June 2017
Beginner
320 pages
7h 37m
English
Let’s do one exercise that uses argv and input together to ask the user something specific. You will need this for the next exercise where you learn to read and write files. In this exercise we’ll use input slightly differently by having it print a simple > prompt. This is similar to games like Zork or Adventure.
ex14.py
1 from sys import argv 2 3 script, user_name = argv 4 prompt = '> ' 5 6 print(f"Hi {user_name}, I'm the {script} script.") 7 print("I'd like to ask you a few questions.") 8 print(f"Do you like me {user_name}?") 9 likes = input(prompt)1011 print(f"Where do you live {user_name}?")12 lives = input(prompt)1314 print("What kind of computer ...
Read now
Unlock full access