-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python1 problem set Question3 #69
Comments
The idea, is for a user who is running your program to give arguments on the command line. An to not have to open the script and change the values in your code. You then, as a user of your script, can type the script name followed by your custom arguments, like "Bo Zhang" Blue and Dreaming. ON THE COMMAND LINE run your script like this: Your code should be more generalized using name, color, thing, dog as your variable names. you can now run your code many times providing different values each time. INSIDE A PY SCRIPT:
|
Thanks Sofia, at least I got the command work:) Still a little bit question: why if I only give less than four items in the command like: Blue Dreaming Dog, there will be an error message |
Your code is explicitly asking for 4 items from the command line
if you only give 3 arguments the code will complain. It tells you that you have an index error, you will learn more about indexes in up coming sections. And again, you are only printing 4 items
so only 4 items will be printed. if you only wanted to print the first argument (
if you want to change the order of the output you change the order of the variables:
|
Hello,
I had a question with python 1 problem set Question 3. I think I didn't get the 'sys' part in the example note. I basically copy the code in the example to solve question 3. My code is below:
#!/usr/bin/env python3
import sys
Bo Zhang = sys.argv[1]
Blue = sys.argv[2]
Dreaming = sys.argv[3]
Dog = sys.argv[4]
print(Bo Zhang,Blue,Deaming,Dog)
should these code be saved in a .py file or should it be the code I type in the command line?
I saved these code in a .py script and dont't know what command to use to get the question 3 done.
Thank you,
Bo
The text was updated successfully, but these errors were encountered: