Strings, lists and records · GCSE · OCR J277 2.2.2, AQA 8525 3.2.8, Edexcel 1CP2 6.3.3 · about 15 min
ord and chr, ASCII, comparing strings, and a Caesar cipher.
[1 mark]What does this program print?
print(ord("A"), ord("a"))[1 mark]What does this program print?
print(chr(66) + chr(111) + chr(116))
[1 mark]ord("A") is 65. What is ord("E")?
[1 mark]Why is "Zebra" < "apple" True?
[1 mark]What does this program print?
letter = "Y"
code = (ord(letter) - ord("A") + 3) % 26
print(chr(code + ord("A")))[1 mark]Which AQA pseudo-code function gives the code for a character?
CHAR_TO_CODEASCordSTRING_TO_INT[1 mark]What does this program print?
print("42".isdigit(), "4two".isdigit())Ask Message? and print the message with every letter moved one place along the alphabet. The task answers HAL (the computer in a famous film), and the answer is the name of a famous computer company. The message will be capital letters only. Work it out with ord and chr.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
message = input("Message? ")
secret = ""Plan your program here, then type it in and press Run.
chr, without typing any letters.HELLO ROBOT works.tone(ord(letter) * 5, 0.2). Which name sounds best?