a = 9
b = 4
c = 5
x = a % b
y = a // c
print(x, y)
a = 5.5
b = 5
x = a % b
y = a // b
print(x, y)
a = -7
b = -4
x = a % b
y = (a + b) // b
print(x, y)1 1
0.5 1.0
-3 2
Note: if you forget what any of these operators do, review the lecture notes on Operators!
What is the output of the following programs?
What does the ** operator do? What does the // operator do?
25
2
The print function will insert a space between each comma-separated argument.
-0.5 0.5 0 -1
Wha’t the output and resulting data type of the following program?
Does the / operator return an int or float?
1.0
float
What is the output of the following program?
Remember the PEDMAS (bracket/exponent/division/multiplication/addition/subtraction) rules!
17.5
What is the output of the following program?
Make sure you pay attention to the changes in x and y from line to line.
1
What is the output of the following program?
Write a short program which given a budget, calculates how many t-shirts they can purchase. Assume each t-shirt costs $15, including tax.
Given a required number of eggs (num_eggs), where eggs can only be purchased in containers of 30, 12, 6, or as individual eggs, determine the number of containers of each size needed to purchase exactly the required number of eggs with no waste.
For example, if I need 24 eggs, I should purchase 2 containers of 12 rather than 1 container of 30.
Complete the following code:
Start by figuring out how many of the largest containers you can buy without exceeding the number of eggs you need.
Calculate how many eggs are still needed after buying the largest containers, then repeat the process with the next container size.
num_eggs = 100
large_size = 30
normal_size = 12
small_size = 6
# 1. Finding how many large can fit in num_eggs
large_count = num_eggs // large_size
# 2. How many eggs are left after buying the large containers
remaining = num_eggs % large_size
normal_count = remaining // normal_size
remaining_n = remaining % normal_size
small_count = remaining_n // small_size
# What's left are individual eggs to purchase
individual_count = remaining_n % small_size
print("Here's what you need to purchase...")
print("Count large: ", large_count)
print("Count normal: ", normal_count)
print("Count small: ", small_count)
print("Individual eggs: ", individual_count)Here's what you need to purchase...
Count large: 3
Count normal: 0
Count small: 1
Individual eggs: 4
Write a short program to help the school administration calculate the number of sections per course given a certain number of registered students. Most groups should have an even number of students, with at least 18 students per classroom and a maximum of 32 students. The administration tries to minimize the number of groups and balances the number of students per classroom.
Note: There are many possible answers for this problem, but some answers are more optimal than others. You are allowed to use any arithmetic operators and simple if statements.
Find it here