COSC 101
Practice Exam #1
1. For each of the following expressions, evaluate the expression and write the result-ing value,
or identify the error in the code that would prevent it from running.
(a) 3**2/2+1
(b) 5 = x
(c) 7%3 == 2
(d) (3**234235 > 5) or (4 != (3+1))
(e) "average score is " + (90.0 + 80.0)/2
(f) max(3*4, 2*min(5, 9/2))
COSC 101
Practice Exam #1
2. For each of the following code segments, write what is printed.
(a) income = 90000
above = income > 200000
if above:
print ("1%" )
else:
print ("99%")
(b) What is the output of the following program?
for i in range (2):
for j in range (3):
print (i,)
print()
for j in range (3):
print (i+1,)
print()
COSC 101
Practice Exam #1
3. Write a short program that asks the user for a word. If the user enters a four-letter
word the program should return: "That word is inappropriate. You should have entered
<alternative word of your choosing>." If the user does not enter a four-letter word, the program
should print: "The word you entered is spelled:" and then print the letters of the word each on
a new line.
COSC 101
Practice Exam #1
4. Write a short program that asks a user for two items: a string s and a number –a positive
integer width. The program should print a string that contains exactly width characters. The
string should consist of as many copies of the string s, with no spaces, that fit in width
characters. If the copies do not fill the entire width, the largest partial copy of s should be
concatenated to the end. For example, if a user types dog and 9, the program should print:
dogdogdog
whereas if the user types dog and 5, it should print:
dogdo
and with dog and 4, it should print:
dogd
You can assume that s has fewer than width characters in it.
COSC 101
Practice Exam #1
5. Write an interactive program to calulate the average temperature in Hamilton for the last week.
Your program will need to ask the user to enter the temperature for every day for the past
week. Then you will output the average temperature. In addition to the average, your program
should output the lowest and highest temperatures during the week. Your program must use a
loop.
Your output must exactly match the following:
What
What
What
What
What
What
What
was
was
was
was
was
was
was
the
the
the
the
the
the
the
temperature
temperature
temperature
temperature
temperature
temperature
temperature
7 days ago?
6 days ago?
5 days ago?
4 days ago?
3 days ago?
2 days ago?
yesterday?
15
20
33
36
40
25
27
The average temperature over the last week was 26.57.
The highest temperature was 40.
The lowest temperature was 15.
© Copyright 2026 Paperzz