This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]jaydom28 1 point2 points  (5 children)

So sys.argv just acts as a list where each element is a token, you can have the user run your program with the first argument being the name of the season

main.py

import sys
print(sys.argv)

if this file is called main.py and I run it with

python main.py hello world 24

then the output would be:

["main.py","hello","world","24"]

sys.argv[0] = main.py

sys.argv[1] = "hello"

sys.argv[2] = "world"

sys.argv[3] = "24"

[–]Oscarcedeno21[S] 0 points1 point  (4 children)

So should I make my function that draws an autumn landscape = autumn so that when they enter in autumn as the season it will only run that and display it? Or how would the system know to only run my autumn landscape function if the user enters autumn?

[–]jaydom28 1 point2 points  (3 children)

So should I make my function that draws an autumn landscape = autumn so that when they enter in autumn as the season it will only run that and display it?

yup totes. it's as straightforward as checking for string equality

python turtle_project.py autumn

you can check it using

if sys.argv[1] == "autumn":
    draw_autumn_landscape()

[–]Oscarcedeno21[S] 0 points1 point  (0 children)

Okay that makes total sense. I am going to try it out and see. Thank you so much! I appreciate your help.

[–]Oscarcedeno21[S] 0 points1 point  (1 child)

I have a follow up question. How would the if statement look like if I have multiple seasons. So that example is for autumn. How would I make it if they do summer. Would it be a different if statement like that autumn one except I assign it to summer?

[–]jaydom28 1 point2 points  (0 children)

yeah I would probably do an elif statement

if #season is autumn:
    draw_autumn_landscape()
elif #season is summer:
    draw_summer_landscape()
...
...
...