Boxes of Eggs
Write a program that allows a chicken farmer to track how many broken eggs are in their boxes of eggs. The program should let the user enter how many boxes they want to check. The program should then loop through each box asking the user the size of the box which is validated to be either 6 or 12. The program should then ask how many eggs were not broken in each box which is validated from 0 (all eggs were broken) to the size of the box (the 6 or 12 that was selected). From there, a tally of broken eggs and intact eggs should be increased accordingly. After every box has been checked, the totals should be displayed.
How many boxes of eggs do you want to check? 3 Enter box size (6 or 12): 5 Invalid box size. Please enter 6 or 12. Enter box size (6 or 12): 6 How many eggs were intact in this box? 4 Enter box size (6 or 12): 6 How many eggs were intact in this box? 6 Enter box size (6 or 12): 12 How many eggs were intact in this box? 21 Invalid number of intact eggs. How many eggs were intact in this box? 12 Total eggs checked: 24 Total broken eggs: 2
total_eggs = 0
broken_eggs = 0
RECEIVE boxes FROM KEYBOARD
FOR i FROM 1 TO boxes DO
SEND "Enter box size (6 or 12): " TO DISPLAY
RECEIVE box_size FROM KEYBOARD
WHILE box_size != 6 AND box_size != 12 DO
SEND "Invalid box size. Please enter 6 or 12." TO DISPLAY
SEND "Enter box size (6 or 12): " TO DISPLAY
RECEIVE box_size FROM KEYBOARD
END WHILE
SEND "How many eggs were intact in this box? " TO DISPLAY
RECEIVE intact FROM KEYBOARD
WHILE intact < 0 OR intact > box_size DO
SEND "Invalid number of intact eggs." TO DISPLAY
SEND "How many eggs were intact in this box? " TO DISPLAY
RECEIVE intact FROM KEYBOARD
END WHILE
total_eggs = total_eggs + box_size
broken_eggs = broken_eggs + (box_size - intact)
END FOR
SEND "Total eggs checked: " & total_eggs TO DISPLAY
SEND "Total broken eggs: " & broken_eggs TO DISPLAY
total_eggs = 0
broken_eggs = 0
boxes = int(input("How many boxes of eggs do you want to check? "))
for i in range(boxes):
box_size = int(input("Enter box size (6 or 12): "))
while box_size != 6 and box_size != 12:
print("Invalid box size. Please enter 6 or 12.")
box_size = int(input("Enter box size (6 or 12): "))
intact = int(input("How many eggs were intact in this box? "))
while intact < 0 or intact > box_size:
print("Invalid number of intact eggs.")
intact = int(input("How many eggs were intact in this box? "))
total_eggs = total_eggs + box_size
broken_eggs = broken_eggs + (box_size - intact)
print("Total eggs checked:", total_eggs)
print("Total broken eggs:", broken_eggs)
# Create the running totals
total_eggs = 0
broken_eggs = 0
# Get number of boxes from user
boxes = int(input("How many boxes of eggs do you want to check? "))
# Loop for every box
for i in range(boxes):
# Input Validation for the Box Size
box_size = int(input("Enter box size (6 or 12): "))
while box_size != 6 and box_size != 12:
print("Invalid box size. Please enter 6 or 12.")
box_size = int(input("Enter box size (6 or 12): "))
# Input Validation for the number of eggs
intact = int(input("How many eggs were intact in this box? "))
while intact < 0 or intact > box_size:
print("Invalid number of intact eggs.")
intact = int(input("How many eggs were intact in this box? "))
# Increasing the running totals
total_eggs = total_eggs + box_size
broken_eggs = broken_eggs + (box_size - intact)
# Display the running totals
print("Total eggs checked:", total_eggs)
print("Total broken eggs:", broken_eggs)
Extension
Extend the program to do the following:
- Allow for boxes sizes of 6, 12 and 15.
- Keep a running total of how many of each size box were checked.
- This should be displayed at the end of the program.
- Display the percentage of broken eggs at the end of the program.
- Display a message if that percentage is over 10%.