ProgrammingConcepts Exam Makeup Solution
ProgrammingConcepts Exam Makeup Solution
100
QUID Section
1|Page
Question 1:
Write a loop that calculates the total of the following series of numbers:
5 6 7 50
+ + + ⋯ +
50 49 48 5
total = 0
j = 50
for i in range(5,51):
total+=(i/j)
j-=1
print("Total=",total)
22 marks
Question 2:
Write a function unit_split that receives a list of numbers and returns two lists:
one includes only tenths (numbers from 0 to 99 ,including both numbers) and the
other one includes only hundreds (numbers from 100 to 999, including both
numbers).
• Test the unit_split function in a main program using the following list:
[5,200,60,342,192,0,15,999]
• Display the output (i.e., print the list of tenths and hundreds) in your main
program.
def unit_split(numbers):
tenths = []
hundreds = []
for i in numbers:
if 0<=i<=99:
tenths.append(i)
else:
hundreds.append(i)
return tenths, hundreds
2|Page
def main():
numbers = [5,200,60,342,192,0,15,999]
tenths,hundreds = unit_split(numbers)
print("Tenths:",tenths)
print("Hundreds:",hundreds)
main()
26 marks
Question 3:
def main():
string = input("Enter a string:")
result = digitMultiplier(string)
print(result)
main()
26 marks
3|Page
Question 4:
The file “cars.txt” contains cars’ records where every car model is followed by it’s
horsepower and price as follows:
model(string)\nhorsepower(integer)\nprice(integer)
inFile.close()
print("Average price of all cars:",sum(prices)/len(prices))
print("Average price of all Toyota cars:",sum(priceToyota)/len(priceToyota))
print("Average price of all cars with horsepower >
100:",sum(price100)/len(price100))
process_list('cars.txt')
26 marks
Don’t forget to upload your zip file on blackboard and submit your exam paper
4|Page