# CS21: Quiz 1 Topics

### You should understand the following terms:

• syntax
• semantics
• algorithm
• program
• computer
• variable
• assignment
• data types: `int`, `float`, `str`, `list`

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

• assignment using `=`
• basic arithmetic expressions using +, -, *, /, **, %
• basic string expressions using +, *
• `type()`
• `range()`
• `int()`, `str()`, `float()`
• `input()`
• basic `for` loops
• `print()`
• `def main():`
• string concatenation (using + operator)

### Sample practice problems:

1. Show the output from the following code fragments:
`for i in range(4):   print(i)   print("-----")`
`for x in range(6):   print("x =",x)print("done!")`
`for ch in "hello!":   print("---" + ch + "---")`
2. Write a program to convert a certain number of gallons (entered by the user) to liters. There are 3.79 liters in a gallon.
```\$ python3 gallons.py
Gallons: 2
That's 7.58 liters.
```
3. Write a program that asks the user for their name, and then prints their name 20 times.

4. 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**3
• 2.0 + 3
• 5/10
• 8 % 6
• 8 % 7
• 8 % 8
• list(range(5))
• 5 - 2 * 3
• "Swat" + "CS"

For example, the answer to the first one (`2 + 3`) would be: value=5, type=integer.