You should understand the following terms:
- syntax
- semantics
- algorithm
- program
- computer
- variable
- assignment
- data types: int, float, string (or str), sequence (string or list so far)
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()
- raw_input()
- for loops
- print()
- def main():
- integer division
- string concatenation (using + operator)
- string repetition (using * operator)
Sample practice problems
- Show the output from the following code fragments:
for i in range(5):
print(i*i)
for x in range(2,10,3):
print("Hello"*x)
print("------")
print("done!")
for ch in "hello!":
print(ch*3)
- Write a program to convert a certain number of gallons (entered
by a user) to liters. There are 3.79 liters in a gallon.
$ python gallons.py
Gallons: 2
That's 7.58 liters.
- Write a for loop that prints your name 10 times.
- Write a for loop that prints the odd numbers from 11 to 51.
- What is the value and type for each of the following expressions? Try them in python to check your answers.
Note: not all expressions shown are allowed in python.
- 2 + 5 (for example: value=7 type=int)
- "2" + "5"
- 2**5
- 2.0 + 5
- 5/2
- 5/2.0
- 8 / 10
- 8 % 10
- 8 / 10.0
- range(1,5)
- range(10,1,-1)
- range(3)
- 5 - 2 * 3
- "pony" * 3
- "Jeffrey" - "rey"
include("../style/footer.php"); ?>