0% found this document useful (0 votes)
3 views6 pages

CSC1010H ClassTest1 2024 Revised

The document is a class test paper for the Computer Science course CSC1010H at the University of Cape Town, scheduled for May 8, 2024. It consists of 7 questions covering various programming concepts and Python coding tasks, with a total of 35 marks available. The test allows the use of calculators and includes specific instructions for answering each question.

Uploaded by

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

CSC1010H ClassTest1 2024 Revised

The document is a class test paper for the Computer Science course CSC1010H at the University of Cape Town, scheduled for May 8, 2024. It consists of 7 questions covering various programming concepts and Python coding tasks, with a total of 35 marks available. The test allows the use of calculators and includes specific instructions for answering each question.

Uploaded by

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

University of Cape Town

Department of Computer Science

Computer Science CSC1010H

Class Test 1
Wednesday, 8 May 2024
Marks: 35 · Approximate marks per question are
shown in brackets
Time: 40 minutes · The use of calculators is permitted

Surname Initials
NAME:

STUDENT NO: COURSE CODE: CSC

This paper consists of 7 questions and 6 pages (including this cover page).

Mark Allocation
Question Marks Internal External Question Marks Internal External
1 5 6 6
2 5 7 5
3 6
4 4
5 4
Total Total
Grand Total

Final Mark
Internal Examiner: External Examiner:

Question 1. [5 marks]
For each of the following, say whether the statement is True or False.

a) Selection is a set of steps that may be repeated.

[1]

b) "cBD">"cBd" is going to give the output False

[1]

c) Algorithms are not repeatable.

[1]

Answer the following questions:

d) words= “The rare and simple truth”


Write down the code to get the string “simple ”

[1]

e) For the variable mentioned in the previous question what is the index number of “i”

[1]

Question 2. [5 marks]

What is the value of each of these expressions if evaluated in Python:

a) divmod(60,7) [1]

b) 7*2**3+5//2 [1]

c) str(2441139) + “Protea” [1]

d) test= input(“Enter a number”)

What is the data type of the variable test?


[1]

e) Print out the following string

He said, "I'll be back"

[1]

Question 3. [6 marks]

a) def main():
turtle.shape("turtle")
turtle.mode("logo")
turtle.title("Right")
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.froward(50)
turtle.exitonclick()
main()
Find the problems in the given code

[2]

b) w=4
for i in range(1, w + 1):
p = “ ” * (w - i)
s = “**” * i
print(p + s)

Please provide the expected output produced by the given Python code.

[4]

Question 4. [4 marks]

a) Consider the following Python variable(s) assignment:


a,b = “Patronum”, “Expecto”

For the given variables write the code to get the following output.

**Expecto** Patronum$$$$

[2]

b) Consider the following Python variable assignment:


spidey= “With great power comes great responsibility”

Write down the Python code to manipulate the given variable so that the output looks like the
following-

With Great Power Comes Great Responsibility

[1]

c) Consider the following Python Boolean expression:


4<10 or 25<17 and 11>12 or not 19>22

What is the value of the Boolean expression?


a) False
b) true
c) and
d) false
e) None
f) or
g) True

[1]

Question 5. [4 marks]

Write a Python program that does the following:


- Prompts the user to enter a number
- If the user enters a number the program should print out the summation of all the odd
numbers from 11 to inclusive n.
- Write your code inside the main function and make sure the program works.
- Consider the user will not enter any floating point number
Sample input:
20
Sample output:
75

[4]
Question 6. [6 marks]

a) What is the output of the following program?


num= int(11.45)
word= "sky"
new_word= ""
for i in range(len(word)):
new_word+=word
print(new_word,num)

[3]

b) Name 3 distinct operations that occurred in this program

[3]

Question 7. [5 marks]

Write a Python program that prompts the user to enter a number until the user types “done”. For each
number entered, if it is greater than 20, the program should ignore it and prompt for another number. If
the number is negative, the program should instruct the user to enter a positive number instead. The
program should multiply together all other valid numbers entered by the user, and display the result of
this multiplication. Users may enter floating-point numbers, but the final output of the multiplication
should be displayed as an integer.

[5]

You might also like