Exercise 4.1 (Pythons ord() function)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. Capitol A is represented by the decimal (denary) number 65. Armed with this knowledge what number represents each of the following:
B
C
D
W
Y
B
C
D
W
Y
3. Lowercase a is represented by the decimal (denary) number 97. Armed with this knowledge what number represents each of the following:
a
b
c
w
y
a
b
c
w
y
4. Write a computer programme that asks the user to enter a character at the keyboard. Have the computer report back the character entered and the number code that represents it.
5. Using an appropriate for ... iteration construct and the ord() function to output the character and number representing each of the characters for the following string:
my_string = ‘RST rst’
The output should look like:
The letter R is represented by 82
The letter S is represented by 83
Etc.
my_string = ‘RST rst’
The output should look like:
The letter R is represented by 82
The letter S is represented by 83
Etc.
6. What is the output of the following program?
Exercise 4.1 Example 1
7. What is the output of the following program? Please note: The following program uses the f string method for displaying the string. If you have been viewing the videos in sequence on this website then I have not yet covered the f string. You may need to google it to understand how it works. The f string was introduced in Python version 3.6 onwards.
Exercise 4.1 Example 2
END Next Exercise >>