0% found this document useful (0 votes)
6 views2 pages

T1 Homework 1

The document contains a series of programming exercises focused on basic operations, string manipulation, and ASCII values. It includes tasks to determine variable values after specific operations, outputs of algorithms, and requires comments to explain code functionality. The total marks for the exercises are 16.

Uploaded by

j9360.sarpong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

T1 Homework 1

The document contains a series of programming exercises focused on basic operations, string manipulation, and ASCII values. It includes tasks to determine variable values after specific operations, outputs of algorithms, and requires comments to explain code functionality. The total marks for the exercises are 16.

Uploaded by

j9360.sarpong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

​ ​

Name:​ ​ Class:​ ​Mark:​

1.​ State the values of a, b, c, d and e after the following operations are carried out: ​ [5]

(a) a = 26 % 5= 1​

(b) b = 142 // 7= 20​


(c) c = (7 + 3) * 4 – 1= 39​

(d) d = 15.6 / 3 + 4.8 / 2= 7.6​


(e) e = "4" + "56"= 456​

2.​ The function ASC('a') evaluates to 97, the ASCII value of the character ‘a’.
​ CHR(97) evaluates to 'a'.
State what is output by this algorithm: ​ [4]

x = ord('b')​

y = x + 1​

z = x – 1​

w = chr(y) + chr(z)​

print(x)​

print(y)​

print(z)​

print(w)

output=(98,99,97,‘ca’)​

3.​ What is output by the following algorithm?​ [3]


notice = "Please do not walk on the grass"
stringLength = len(notice)
left = notice[:11]
right = notice[stringLength-11:]
print(stringLength)
1
​ ​

print(left)
print(right)

34
“please do n”
“the grass”

4. Write a comment for each line with a # after the code to explain its
purpose.​ [4]

firstName = input("Enter your first name: ")


surname = input("Enter your surname: ")
initial = firstName[0] #extract the first character of firstname and store it in the variable initial

initial = initial.upper() #Convert the initial to a capital letter


surnameStart = surname[0]#Extract the character at index 9 of surname and store it at variable surname
Start​

surnameStart = surnameStart.upper() #Convert surnameStart to uppercase ​


surname = surname.lower() #Convert the entire surname to lower
length = len(surname) #calculate the length and store it in the variable length​
surname = surnameStart + surname[1:]#Replace the first character of surname with surnameStart
and concentrate the rest of the surname

[Total 16 marks]

You might also like