Input Practice
Let’s try some simple practice problems. These problems are not graded - they are just for you to practice before doing the real exercises in the lab itself. You can find the answers below each question by clicking the button below each question.
3.1 Reading Code
Write the output that is displayed to the user after running the following Python code:
x = input("Enter a number: ")
y = x + "00"
z = int(y)
a = int(z + (z / 100))
print(f"The result is {a}")
Assume the user inputs the string "4"
when prompted.
3.2 Reading Code
Write the output that is displayed to the user after running the following Python code:
x = int(input("Enter a number: "))
x = x // 100 * 100 + x % 10
print(f"The answer twice is {x * 2}")
Assume the user inputs the string "121"
when prompted.
3.3 Writing Code
Write a Python program that prompts the user to input a verb and a noun that will be stored in separate variables. Then, use those two words to create a simple compliment for the user and print it to the terminal. The compliment should be in the form of:
You "<verb>" my "<noun>"? That's awesome!
For example, if the user inputs "love"
and "food"
, then the string printed by the program should be:
You "love" my "food"? That's awesome!
Hint: Notice that the output includes quotation marks around the two words provided by the user, and an apostrophe (single quote) as well. You’ll need to account for this in your code!
You can expand on this program to prompt the user for additional inputs, and use f-strings to create a Mad Libs style game!