HTTLACS: Ch 4 Exercises
From WLCS
Directions:
- Open a text editor (Applications->Accessories->gEdit Text Editor)
- Put your name at the top
- Save the file as YOURLASTNAME_ch4.txt
- Complete the exercises below in this file. If you use DrPython, then be sure to copy your code back into this file
- Be sure to number each of your answers!!
References:
Exercises:
- What does the modulus operator % do?
- Evaluate the following modulus expressions in your head (double-check your answers using Python)
- 5 % 2
- 9 % 5
- 15 % 12
- 12 % 15
- 6 % 6
- 0 % 7
- 7 % 0
- What does boolean mean?
- List all the comparison operators and what they look like in Python (there should be 6 total)
- Example: greater than >
- Write the following program:
- Prompt the user for his/her age and store it in a variable named age
- 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"
- Write the following program:
- Prompt the user for two numbers
- Check if the sum of the two numbers is greater than 100. If True, then print out "r0x0rs!", else, print out "low low low"
- Write the following program:
- Prompt the user to enter a number
- 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!"
- Write the following program:
- Prompt the user to enter his/her age
- 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"
- If the age is greater than 11 and the age is less than 15, then print out "You're probably in middle school"
- If the age is greater than 14 and the age is less than 19, then print out "You're probably in high school"
Submit:
- Submit the file to School Web Lockers