February 2024
Beginner
352 pages
8h 16m
English
Let’s do an 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.
Listing 14.1: 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)
10
11 print(f"Where do you live {user_name}?")
12 lives = input(prompt)
13
14 print("What kind of computer do you have?")
15 computer = input(prompt)
16
17 print ...Read now
Unlock full access