Quiz 1 Study Guide
You are responsible for all material covered through the end of Week 2, with the
exception of the accumulator pattern. You are not responsible for Unix or
Your quiz will be on paper, so be sure to practice the concepts below on paper including writing simple programs
Quiz Study Guides are provided as a courtesy. You may work with other students on the questions, and ask questions about the guide during evening ninja help sessions, on piazza, or with meetings with faculty and staff. We do not provide full solutions to the quiz guides.
You should understand the following terms:
Python as a programming language
Python concepts and functions
You should be able to use the following Python concepts and functions:
basic arithmetic expressions using +, -, *, /, //, **
reading in strings using
float()and type conversion
Sample practice problems
1) Write a program to convert a certain number of gallons (entered by the user) to liters. There are 3.79 liters in a gallon.
$ python gallons.py Gallons: 2 That's 7.58 liters.
2) What is the value and type for each of the following
expressions? Try them in
python3 to check your answers.
2 + 3
2.0 + 3
5 - 2 * 3
"Swat" + "CS"
For example, the answer to the first one (
2 + 3) would
5 and type
3) Write a madlib program that asks the user for a noun and verb and
then prints them out in a pre-determined sentence. E.g., for inputs
$ python madlib.py Noun: Marco Verb: studies The nation was riveted to see the beloved Marco on TV. He studies better than any person in history.
4) Write a program that takes a user’s hotel room rate and outputs the cost of a 6% sales tax and 10.5% city tourism fee. The program should then output the total bill.
$ python bill.py Room rate: 100 Total nights: 3 ------------------- Tax: $ 18.0 Tourism Fee: $ 31.5 Total: $ 349.50
5) Show the output from the following code fragments:
for i in range(4): print(i) print("-----")
for x in range(6): print("x ="+str(x)) print("done!")
word = "hello!" num_chars = len(word) for i in range(num_chars): print("---" + word[i] + "---")
6) Write a program that asks the user for their name, and then prints their name 20 times.