Homework

Try out these exercises at home. These are just examples. Try to find some more examples in the internet or just play around!

  1. Which Python version are you using?
  2. Not everything can be used as a variable name. Which ones of these cannot be used as variable names? If you are not sure, try it out.
    • x, button4, 34, 3e4, turkey, $i, square-root, readme, readme.txt, shorterEdge, shorter_edge, NUMBER_OF_POINTS, _, π, True, _cache, __name__, while.
  3. Some of the names above are valid, but not very good variable names. Which ones do you think are those?
  4. Which one of shorterEdge, shorter_edge is a more correct name for a variable? Why? Try searching for PEP 8 variable names. What's a PEP 8?
  5. Try to write a program that calculates the surface and volume of a cube with edge = 2852 cm.
  6. Now change the program so that the user can enter the edge value.
  7. Write a program that calculates the Body Mass Index (BMI) from a user's weight and height. The BMI is a measure of some's weight taking into account their height. e.g. If a tall person and a short person both weigh the same amount, the short person is usually more overweight. The BMI is calculated by dividing a person's weight (in kg) by the square of their height (in m).
  8. Write the following code into single cell and run it more times. What is it doing?
    from random import randrange 
    number = randrange(3) 
    print(number)