Unit 2 Critical Discussions
Unit 2 Critical Discussions
Then, write the line of code that would use integer division.
Answer: Say you want to fill 10 egg cartons all the way up and you don't need to count the
leftover eggs, you can use integer division in this situation.
The code:
eggs = float(input("how many eggs do you have? :"))
cartons = (eggs//12)
2. Describe a situation in which you would want to use modulus division in a program.
Then, write the line of code that would use modulus division.
Answer: Say you made a game where you have two sets of points that need to total an even
number, you can use modulus division to find if there is a remainder to see if the player lost or
won.
The code:
d1p = float(input("how many points did you get day one? :"))
d2p = float(input("how many points did you get day two? :"))
if pointtotal == 0 :
print("YOU WIN")
else :
print("you lose")
3. A customer has hired you to code a cooking mystery game. Here is part of the narrative:
“When the player enters the kitchen, they can choose to preheat the oven or chop
vegetables. If they choose to preheat the oven, they will get a message that the oven is
broken. If they choose to chop the vegetables, they will get a message that the knife is
missing.” Write the code for this situation.
Answer: direction = float(input("you an cut the veggies first or preheat the oven which one do
you want to do first type 1 for veggies and 2 for oven: "))
if direction == 1 :
elif direction == 2 :
print("you fell over and hit your head because you didnt type 1 or 2")
4. Write three lines of code using a sequence (no iteration or selection) that would be
appropriate for a story or game.
Answer: You grab your back and then walk outside and take a jog. You notice that the
surrounding area is loud so you put your earbuds in. Then you realize its cold outside so you
pull your coat out of your bag and put it on.
5. Will the output for each of these print statements be the same? Explain your answer.
num1 = 10
num2 = 50
num3 = 10
num4 = 0
Answer: No they will not be the same, the second problem will be solved left to right because of
order of operations while the first problem will be solved in in the parentheses first meaning their
output will be different.