name = input('What is your name? '); print('Hello, ' + name). The user types Ana. What prints?
COMPUTING AND DIGITAL LITERACY
This document was made by AI and there may be mistakes. If a question or answer looks wrong, use the Flag a mistake button to let Brett know so he can fix it.
This is how a program takes what you type or tap and gives something back, like a calculator app turning your numbers into an answer on screen. Every program is a loop of input and output, you give it something, it does the work, and it shows you the result. That is how a search box turns your words into results, how a game turns your button presses into movement on screen, and how a form turns your details into a booking.
Greet by name
Solution
name = input("What is your name? ")
print("Hello, " + name)
User types Sam -> Output: Hello, Sam
Ask for the value with input() and store the answer in name.
Join the greeting text and the stored name with +.
Print the result so the user sees: Hello, Sam.
input() reads an age as the text '14'. How do you turn it into a number, and what is the age next year?
Solution
age_text = input("Age? ") ->"14"
age = int(age_text) -> 14
Next year: age + 1 = 15
Read the age with input(), which always gives text, here "14".
Convert it with int() so it becomes the number 14.
Now arithmetic works: 14 + 1 = 15. Without converting, "14" + 1 would fail or join wrongly.
name = input('What is your name? '); print('Hello, ' + name). The user types Ana. What prints?
first = input('First name? '); last = input('Last name? '); print(first + ' ' + last). The user types Ana then Lee. What prints?
What does the text inside input('Favourite colour? ') do?
age_text = input('Age? '); age = int(age_text); print(age + 1). The user types 21. What prints?
age_text = input('Age? '); print(age_text + '1'). The user types 9. What prints?
num_text = input('Give a number: '); num = int(num_text); print(num * 2). The user types 7. What prints?
How do you turn the text '27' into the number 27?
A program asks for a name and prints a greeting. Which part is input?
What does input() always return?
Why convert input before doing maths on it?
Your score: 0 / 10
1. Hello, Ana
2. Ana Lee
3. It shows a prompt asking the question
4. 22
5. 91
6. 14
7. int("27")
8. The name the user types
9. Text (a string)
10. Because input arrives as text, and maths needs numbers