Emerging trends in programming languages

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

Emerging trends in programming languages

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Why do programming languages keep changing over time?
A New features and languages aim to make software easier, safer or faster to build
B Old languages stop working once a new language is released
2. Which Python line uses a type hint?
A def double(n: int) -> int:
B def double(n) -> print:
3. What is the main purpose of a type hint in Python?
A It makes the program run twice as fast
B It shows what type of data a variable or function should use, which helps readers and tools spot mistakes
4. Which language was designed with a strong focus on memory safety?
A Rust
B HTML
5. Which is an example of readable syntax?
A if(a>=18)&&{;;
B if age >= 18:

Match the Pairs

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

Left columnRight column
1def add(a: int, b: int) -> int: AA Python function with type hints that show the inputs and the result should be whole numbers
2for name in names: Blet age: i32 = 16;
3Newer languages built for safety can stop some bugs by checking that values are used correctly Cscore: int = 10
4Type hints are an added feature that tell readers and tools what kind of data a variable should hold DThe type hint says int but the value is text. It should be a number such as 10, or the hint should be str.
5def greet(name: str) -> int: return "Hi " + name EReadable syntax that loops through a list in a way that is close to plain English
6total: int = "ten" FThe type hint says the function returns an int, but it actually returns a string. The hint should be -> str.

Definitions

language trends

Fill in the Blanks

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

1.
def add(a: int, b: int) -> ___: return a + b
2.
def greet(name: ___): print("Hi " + name)
3.
if mark __ 50: print("Pass")
4.
price: _____ = 9.95
5.
names = ["Ava", "Liam"] for n in names: _____(n)

Spot the Error

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

Question 1
A def greet(name: str) -> str:
B msg = 'Hi ' + name
C msg = msg + '!'
D return mesg
Question 2
A age: int = 16
B name: str = 'Sam'
C print(name)
D print(age + '1')
Question 3
A scores: list[int] = [80, 92]
B scores.add(75)
C total = sum(scores)
Question 4
A def is_adult(age: int) -> bool:
B if age >= 18:
C return true
D return False
Question 5
A total: int = 0
B for i in range(3):
C total + = i
D print(total)

Answer Key

Emerging trends in programming languages
Section A: Quick Questions
Q1
A — New features and languages aim to make software easier, safer or faster to build
Q2
A — def double(n: int) -> int:
Q3
B — It shows what type of data a variable or function should use, which helps readers and tools spot mistakes
Q4
A — Rust
Q5
B — if age >= 18:
Section B: Match the Pairs
Q1
def add(a: int, b: int) -> int: → A Python function with type hints that show the inputs and the result should be whole numbers
Q2
for name in names: → Readable syntax that loops through a list in a way that is close to plain English
Q3
Newer languages built for safety can stop some bugs by checking that values are used correctly → let age: i32 = 16;
Q4
Type hints are an added feature that tell readers and tools what kind of data a variable should hold → score: int = 10
Q5
def greet(name: str) -> int: return "Hi " + name → The type hint says the function returns an int, but it actually returns a string. The hint should be -> str.
Q6
total: int = "ten" → The type hint says int but the value is text. It should be a number such as 10, or the hint should be str.
Section C: Definitions
Q1
language trends — Programming languages keep changing. New features and languages aim to make software easier, safer or faster to build, such as readable syntax, type hints and safer languages.
Section D: Fill in the Blanks
Q1
def add(a: int, b: int) -> int: return a + b
Q2
def greet(name: str): print("Hi " + name)
Q3
if mark >= 50: print("Pass")
Q4
price: float = 9.95
Q5
names = ["Ava", "Liam"] for n in names: print(n)
Section E: Spot the Error
Q1
D — The variable is called msg, but the last line returns mesg, which was never created. It should be 'return msg'. Readable code with clear names makes slips like this easy to spot.
Q2
D — age is an int, so adding the string '1' causes a TypeError. Type hints help tools catch this kind of mistake. It should be print(age + 1).
Q3
B — Python lists have no add() method. Use append() to put a new item on the end of a list: scores.append(75).
Q4
C — Python's Boolean values are capitalised: True and False. Lowercase 'true' is an undefined name. It should be 'return True'.
Q5
C — The += operator must be typed with no space between + and =. Python's short, readable syntax uses 'total += i' to add to a variable.