Python Reading
- Read the chapter entitled Selection.
- The bool type has values True and False
- Boolean operators: = =, !=, >, >=, <, <=
- Logical operators: and, or, not
- Conditional statements: if, if else, if elif else
- Conditional statements can be nested
- Writing and calling Boolean functions
- Consider a simplified game of UNO that has forty different cards. Each card has a color ("red", "yellow", "green" or "blue") and a value (0, 1, 2, 3, 4, 5, 6, 7, 8 or 9). Complete the boolean function below so that it returns True if the second card can be played on the first card and False otherwise.
def legal_play(first_value, first_color, second_value, second_color):
For example, legal_play(3, "blue", 3, "green") and legal_play(5, "yellow", 7, "yellow") should both return True, but legal_play(9, "red", 6, "green") should return False. - Take key-events.py and modify it so that the turtle only moves if it will still be visible. Use one boolean function in your solution.
Additional problem:
Learning Outcomes
Note: the federal tax is progressive. For example, if a person has a taxable income of $15,000, the first $9,700 is taxed at a rate of 10% and the remaining $5,300 is taxed at a rate of 12%.
Rate For Unmarried Individuals, Taxable Income Over
10% -- $0
12% -- $9,700
22% -- $39,475
24% -- $84,200
32% -- $160,725
35% -- $204,100
37% -- $510,300
Grading - 10 points
Learning Outcomes
- Gain experience writing a Python function.
- Gain experience writing Python selection statements.
- Download tax lab2.py and rename it according to the instructions above.
- Modify the program by adding the missing function. The missing function will use Python selection statements to calculate the amount of tax that a single (unmarried) taxpayer owes using the table below. If the missing function is implemented correctly, this output will appear.
Note: the federal tax is progressive. For example, if a person has a taxable income of $15,000, the first $9,700 is taxed at a rate of 10% and the remaining $5,300 is taxed at a rate of 12%.
Rate For Unmarried Individuals, Taxable Income Over
10% -- $0
12% -- $9,700
22% -- $39,475
24% -- $84,200
32% -- $160,725
35% -- $204,100
37% -- $510,300
Grading - 10 points
- 7 points - Your program calculates the income tax for each of the seven test cases correctly (1 point each).
- 3 points - A function with the correct name (1 point), correct parameters (1 point) and correct return value (1 point) is used in the solution.