Skip to main content

Section 16.10 Review - Input

Practice using input() to get values from the user and understand that input() returns a string.

Subsection 16.10.1 Quick Reference

input() gets information typed by the user. The value returned by input() is always a str. Use int() or float() if you want to convert the input to a number.
name = input("Enter your name: ")
age = int(input("Enter your age: "))

Subsection 16.10.2 Part A: Recognize

Checkpoint 16.10.1.

Answer the following questions based on this code snippet.
name = input("Enter your name: ")
print(name)
  1. What does input() do?
  2. What message is shown to the user?
  3. What variable stores the user’s response?
  4. What data type is the value returned by input()?

Subsection 16.10.3 Part B: Predict What Happens

Checkpoint 16.10.2.

If the user types Raya, what is printed given the following code snippet?
name = input("Enter your name: ")
print("Hello, " + name)

Checkpoint 16.10.3.

If the user types 18, what is stored in age given the following code snippet?
age = input("Enter your age: ")
print(age)

Checkpoint 16.10.4.

If the user types 5, what is printed given the following code snippet?
num = input("Enter a number: ")
print(num + num)

Subsection 16.10.4 Part C: Explain

Checkpoint 16.10.5.

What is the difference between these two lines?
value = input("Enter a number: ")
value = int(input("Enter a number: "))

Subsection 16.10.5 Part D: Fix

Checkpoint 16.10.6.

Rewrite the code so it works correctly.

Checkpoint 16.10.7.

Rewrite the code so it works correctly.

Checkpoint 16.10.8.

Rewrite the code so it works correctly.

Subsection 16.10.6 Part E: Create

Checkpoint 16.10.9.

Write code that asks the user for their name and prints a greeting. Then asks for their favorite number and prints it back. Finally, it asks the user for two whole numbers, and prints their sum.

Subsection 16.10.7 Think About ...

Checkpoint 16.10.10.

Why is it sometimes necessary to use int() or float() with input()?
You have attempted of activities on this page.