Casting Power 0 / 29
Casting Rank Value Watcher

Topic 2.2.5: Data Types & Casting

Integers, Floats, Strings, Booleans & Casting.

1 [2 Marks]
x = int(9.9)
(a) Value of x?
(b) Explanation?
Hint: Casting to int merely cuts off the decimal. It does NOT round.
✅ Mark Scheme

(a) 9

(b) Truncates (removes) the decimal part; does not round up.

Score:
2 [4 Marks]
char1 = 'A' val1 = ASC(char1) val2 = val1 + 2 char2 = CHR(val2) print(char2)
Note: ASC('A') is 65.
Trace values: val1, val2, char2, Output.
✅ Mark Scheme
  • val1: 65
  • val2: 67
  • char2: 'C'
  • Output: 'C'
Score:
3 [3 Marks]
Final Value & Data Type:
  • str(10 + 5)
  • int("12") + 5
  • float(int(4.8))
✅ Mark Scheme
  • "15" (String)
  • 17 (Integer)
  • 4.0 (Float/Real)
Score:
4 [4 Marks]
userInput = input("Enter True or False: ") isValid = bool(userInput)
(a) Why is isValid True even if user types "False"?
(b) Rewrite using IF statement to fix logic.
✅ Mark Scheme

(a) Non-empty strings evaluate to True in Python. It checks presence of text, not meaning.

(b) if userInput == "False": isValid = False

Score:
5 [3 Marks]
Generate random capital letter (A-Z).
  • Random Int 65-90.
  • Cast to Char.
✅ Mark Scheme
num = random(65, 90)
letter = CHR(num)
print(letter)
Score:
6 [3 Marks]
01 ageYears = int(input("Enter age: ")) 02 ageMonths = ageYears * 12 03 print("You are " + ageMonths + " months old.")
(a) Line number of error?
(b) Rewrite line to fix (using casting).
✅ Mark Scheme

(a) Line 03

(b) print("You are " + str(ageMonths) + " months old.")

Score:
7 [3 Marks]
radiusString = input("Enter radius: ") radiusVal = _______(radiusString) area = 3.142 * (radiusVal * radiusVal) print("The area is " + _______(area))
Fill the blanks (radius can be decimal).
✅ Mark Scheme
  • 1. float (or real)
  • 2. str (or String)
Score:
8 [2 Marks]
x = "10" y = "2" print(x + y)
Output?
✅ Mark Scheme

102 (String concatenation)

Score:
9 [2 Marks]
Why is casting Real to Integer a risk to data accuracy?
✅ Mark Scheme

Removes fractional part / Loss of precision (e.g. 9.9 becomes 9).

Score: