Pseudocode assignment, INPUT and OUTPUT in Python

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Pseudocode assignment, INPUT and OUTPUT in Python

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which Python line matches the pseudocode: Score ← 10
A Score = 10
B Score ← 10
2. Which Python line matches the pseudocode: INPUT Name
A Name = input()
B input Name
3. Which Python line matches the pseudocode: OUTPUT Total
A print(Total)
B output(Total)
4. The pseudocode is INPUT Age and Age will be used in a sum. Which Python line is better?
A Age = input()
B Age = int(input())
5. The pseudocode is INPUT Price where Price can be 2.50. Which Python line is better?
A Price = int(input())
B Price = float(input())

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Age = int(input()) APrice = float(input())
2print(Name, Score) BPython for INPUT Age: reads what the user types and turns the text into a whole number
3Python has no ← arrow, so the pseudocode Total ← 0 is written with a plain = sign CAge is still text because int() was not used, so adding 1 to it causes an error. It should be Age = int(input()).
4To read a decimal number such as a price, wrap input() in float() so the text becomes a real number DPython for OUTPUT Name, Score: shows both values on one line
5Age = input() Next = Age + 1 EPseudocode was left unchanged: Python needs Total = 5 and print(Total) instead of the arrow and OUTPUT.
6Total ← 5 OUTPUT Total FTotal = 0

Definitions

Age = int(input())

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Name = _____()
2.
Age = ___(input())
3.
Price = _____(input())
4.
Total = 7 + 3 _____("Total:", Total)
5.
Score _ int(input())

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Name = input()
B Age = int(input)
C print(Name, Age)
Question 2
A Count = int(input())
B Total ← Count * 2
C print(Total)
Question 3
A Name = input()
B Score = int(input())
C Bonus = 5
D print(Name + Score + Bonus)
Question 4
A Length = float(input())
B Width = input()
C Area = Length * Width
D print(Area)
Question 5
A Age == int(input())
B Next = Age + 1
C print(Next)

Answer Key

Pseudocode assignment, INPUT and OUTPUT in Python
Section A: Quick Questions
Q1
A — Score = 10
Q2
A — Name = input()
Q3
A — print(Total)
Q4
B — Age = int(input())
Q5
B — Price = float(input())
Section B: Match the Pairs
Q1
Age = int(input()) → Python for INPUT Age: reads what the user types and turns the text into a whole number
Q2
print(Name, Score) → Python for OUTPUT Name, Score: shows both values on one line
Q3
Python has no ← arrow, so the pseudocode Total ← 0 is written with a plain = sign → Total = 0
Q4
To read a decimal number such as a price, wrap input() in float() so the text becomes a real number → Price = float(input())
Q5
Age = input() Next = Age + 1 → Age is still text because int() was not used, so adding 1 to it causes an error. It should be Age = int(input()).
Q6
Total ← 5 OUTPUT Total → Pseudocode was left unchanged: Python needs Total = 5 and print(Total) instead of the arrow and OUTPUT.
Section C: Definitions
Q1
Age = int(input()) — Python for INPUT Age: = replaces the arrow, input() reads text, and int() turns that text into a whole number. OUTPUT Age becomes print(Age); use float() for decimals.
Section D: Fill in the Blanks
Q1
Name = input()
Q2
Age = int(input())
Q3
Price = float(input())
Q4
Total = 7 + 3 print("Total:", Total)
Q5
Score = int(input())
Section E: Spot the Error
Q1
B — input is a function, so it needs brackets to be called. INPUT Age becomes Age = int(input()), with input() ending in ().
Q2
B — The arrow ← is pseudocode only. Python uses = for assignment, so the line should be Total = Count * 2.
Q3
D — Name is text and Score is a number, so + cannot join them and gives a TypeError. Separate the values with commas: print(Name, Score + Bonus).
Q4
B — input() returns text, so multiplying Length by Width causes an error. A number must be read with float(input()).
Q5
A — A double == compares values, it does not assign. Use a single = to store the input in Age: Age = int(input()).