Quiz 1 | CMSC 105 Elementary Programming - Fall 2024

Quiz 1

Points Possible: 100

Date: Thursday, September 19th

Background

This quiz is based on the topics covered in weeks 1 through 3. There are 3 sections — short answer questions, tracing, and a programming problem. Students are allowed to use the Thonny IDE for Section III only. Please see the grading rubric for the programming problem. Scratch paper and a simple calculator are allowed.

Submission

Section I (20 points)

1 Show the output of the following:

import math
print(math.ceil(-9.6))

2 Show the output of the following:

print(abs(-7.2))

3 Show the output of the following:

print(round(5.7))

4 Show the output of the following:

import math
print(math.pow(2, 3))

5 Show the output of the following:

import math
print(math.sqrt(25))

6 What will be the output of the following:

string_val = "Python programming"
result = string_val.find('t')
print(result)

7 What will be the output of the following:

string_val = "Python programming"
result = string_val.upper()
print(result)

8 What will be the output of the following:

string_val = "Python programming"
result = string_val * 5
print(result)

9 What will be the output of the following:

string_val = "Python programming"
result = string_val[:-1]
print(result)

10 What will be the output of the following:

string_val = "Python programming"
result = string_val[1:3]
print(result)

Section II (30 points)

Trace the execution of the following program by filling in a tracing table. You can draw the tracing table on a piece of paper and include an image file (tracing.png) on Blackboard.

You may use the following guide for reference:

Note: Assume that the user enters 3 for the first number and 7 for the second number.

# Simple Calculator

# Get input from the user
num1 = eval(input("Enter the first number: "))
num2 = eval(input("Enter the second number: "))

# Perform arithmetic operations
sum = num1 + num2
diff = num1 - num2
product = num1 * num2

# Display the results
print("The sum is", sum)
print("The difference is", diff)
print("The product is", product)

Section III (50 points)

Programming question:

You may use the following guide for reference:


Create a program that takes as input three numbers: num1, num2, num3 and displays the average of the three numbers as an integer by rounding off the average.

Sample run:

Enter number 1: 34
Enter number 2: 30
Enter number 3: 25
The average of 34, 30, and 25 is 30

Grading Rubric for Section III:

Grading Points Possible
Appropriate header and comments 5
Input 10
Flowchart 15
Computation 10
Print output 10