Today’s Progress
- ex11: Asking Questions
# end=' ' puts a space after the " ? " AND doesn't go to a newline.
print("How old are you?", end=' ')
# pass age to repr() to get python type
age = input()
print(">> age=", repr(age))
- ex12: Prompting People. In powershell, type “python -m pydoc input”. Look what pydoc command does. input() string has no trailing newline
#ask a question and get an answer in one line age = input("How old are you? ")
- ex13: Parameters, Unpacking, Variables. The argv is the argument variable, it holds the arguments you pass to your Python script. Call your script by naming the script and passing the arguments.
#this line unpack...Take whatever is in argv, unpack it, and assign it to all of these variables on the left in order.
script, first, second, third = argv
- ex14: Prompting and Passing. input(prompt)
print(f"Do you like me {user_name}") likes = input(prompt)
- ex15: Reading Files
# print out contents of a file txt = open(filename) print(f"Here's your file{filename}: ") print(txt.read())
Thoughts: Ok, so this was a lot of unpack from asking user questions, assigning that to variables, unpacking and passing arguments, and reading files.
Link to work: exercises 11-15