CS21: 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 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:

You should be able to use the following Python concepts and functions:

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.
  1. What is the value and type for each of the following expressions? Try them in python3 to check your answers.

For example, the answer to the first one (2 + 3) would be value 5 and type int (or integer).

  1. 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
  1. 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
  1. Show the output from the following code fragments:
    for i in range(4):
    for x in range(6):
        print("x ="+str(x))
    word = "hello!"
    num_chars = len(word)
    for i in range(num_chars):
        print("---" + word[i] + "---")
  1. Write a program that asks the user for their name, and then prints their name 20 times.