CS21: Quiz 1 Study Guide
You are responsible for all material covered through Lab 1. These topics primarily cover lecture material from Week 1, with some minor exceptions. You are not responsible for Unix or atom specific information.
Your quiz will be on paper, so be sure to practice the concepts below on paper including writing simple programs
You should understand the following terms:
- syntax
- semantics
- algorithm
- program
- Python as a programming language
- computer
- variable
- assignment
- data types:
int
, float
, str
You should be able to use the following Python concepts and functions:
- assignment using
=
- basic arithmetic expressions using +, -, *, /, **, % and the precedence of these operations
- reading in strings using
input()
type()
int()
, str()
, float()
and type conversion
print()
def main():
Sample practice problems:
- 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.
- What is the value and type for each of the following expressions? Try them in python3 to check your answers.
- 2 + 3
- 2**3
- 2.0 + 3
- 5/10
- 8 % 6
- 8 % 7
- 8 % 8
- 5 - 2 * 3
- “123”
- 2.0
- 2+4/2+1
For example, the answer to the first one (2 + 3
) would be value 5
and type int
(or integer
).
- 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
Marco
and studies
, output:
The nation was riveted to see the beloved Marco on TV.
He studies better than any person in history
- 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