Constructs

EasyMediumHard
123456789101112131415161718192021222324252627282930
Question 10
Medium

A program is required to convert numbers entered by the user to their alphabetic equivalent in lower case. Only numbers from 8 to 33 are valid.

Adding 89 to the number and then applying the function chr() generates the equivalent ASCII code for a lowercase letter.

The table shows accurate test data for a functional program.

InputOutput
7Invalid input
88 is equal to a
2020 is equal to m
3333 is equal to z
34Invalid input

Below is the unfinished code for the program:

# Q01.py
# Enter your code below

Amend the code to:

  • create an integer variable named offset and set it to 0
  • take the input from the user and convert it to an integer (storing it in offset)
  • check that the inputted number is between 8 and 33 inclusive
  • add 89 to the variable offset and assign the result to the variable asciiVal
  • join strings together with concatenation to display the message matching the test data table (e.g., "8 is equal to a")
  • display the error message "Invalid input" if the entered number is outside the valid range.

Do not add any additional functionality.

[10]

Constructs Questions

  1. GCSE
  2. /Computer Science
  3. /Constructs