HTTLACS: Ch 4 Exercises

From WLCS

Directions:

  1. Open a text editor (Applications->Accessories->gEdit Text Editor)
  2. Put your name at the top
  3. Save the file as YOURLASTNAME_ch4.txt
  4. Complete the exercises below in this file. If you use DrPython, then be sure to copy your code back into this file
  5. Be sure to number each of your answers!!

References:

Exercises:

  1. What does the modulus operator % do?
  2. Evaluate the following modulus expressions in your head (double-check your answers using Python)
    1. 5 % 2
    2. 9 % 5
    3. 15 % 12
    4. 12 % 15
    5. 6 % 6
    6. 0 % 7
    7. 7 % 0
  3. What does boolean mean?
  4. List all the comparison operators and what they look like in Python (there should be 6 total)
    • Example: greater than >
  5. Write the following program:
    1. Prompt the user for his/her age and store it in a variable named age
    2. Using an if-statement, check if the age is less than 18. If True, then print out "You are a minor", else, print out "You are an adult"
  6. Write the following program:
    1. Prompt the user for two numbers
    2. Check if the sum of the two numbers is greater than 100. If True, then print out "r0x0rs!", else, print out "low low low"
  7. Write the following program:
    1. Prompt the user to enter a number
    2. Using the modulus operator (%), check if the remainder when divided by 2 is equal to 0. If True, then print out "Even number!", else, print out "Odd number!"
  8. Write the following program:
    1. Prompt the user to enter his/her age
    2. If the age is greater than 4 and the age less than or equal to 11, then print out "You're probably in elementary school"
    3. If the age is greater than 11 and the age is less than 15, then print out "You're probably in middle school"
    4. If the age is greater than 14 and the age is less than 19, then print out "You're probably in high school"

Submit: