Need help with "Running Simple Python Scripts" Challenge

Hello. I have a simple question most likely but I’m just starting out in Python so its all foreign to me. Under the curriculum in the prep course, when we are transferred to for “Beginning Python”, there is a question I cannot figure out.

In “Running Simple Python Scripts” I am not able to get the first and last name (John Doe) to populate in the proper location, and therefore am only getting 75% credit. I think I am probably missing a user argument somewhere but Im not sure since I don’t know much about user arguments and the curriculum mentioned them only briefly. The question is: Following the instructions above, in your terminal, pass a first and last name argument to the file which should return the system arguments bordered by 33 underscores on the top and bottom.

My code is: print("" * 33)
print(“First name:”)
print(“Last name:”)
" * 33)
The Output is: workspace $ python3 John Doe

First name:
Last name:

workspace $

Notice that there is no name by “First name” or “Last name”. What am I missing?
Thanks, James

Hey James,

Your code is close! You are just missing the parameters. To do so, you will need to import the sys library at the beginning of your script. When you run the script, the parameters are, John, and Doe. So, sys.argv[1] will get John and sys.argv[2] will get Doe (since Python is 0-indexed).

The following will pass the check:

import sys

print("_" * 33)
print("First name:", sys.argv[1])
print("Last name:", sys.argv[2])
print("_" * 33)

You can read more about this in the Passing User Arguments to Scripts activity just before this challenge. Let me know if you have any other questions!

Happy coding :slight_smile:

Thank you so much Lorraine for your encouragement. I hope this gets easier or something clicks in my brain to make me absorb this material easier. Your response helped so much but I think I need to see it in action.

If it’s not too much trouble, can you please show exactly what you meant in your email by including the correctly written script. I have looked everywhere for something like that to help. I wish they had answer keys so I can see exactly what I am missing by seeing the correct working script. I learn best that way.

If you could do that it would be amazing. I don’t want to tie you up if it takes a while though. Thank you so much for your response. It helped a lot!! I just need to see it in application I guess.


Nevermind about my response a few minutes ago. Sorry about that. I saw the drop down menu with the script right after I sent the message. It was exactly what I needed though!

Thanks!!! Your are the best!

1 Like

No problem, James! Happy to help :slight_smile: