43.0k views
2 votes
Value-returning function calculateEggSize a) Define a value-returning function that will return (not print!) the size-category (as a string) of an egg depending on the weight of the egg. The weight is the parameter (of type float) of this function. Egg sizes are categorized as: - pee-wee (less than 42 grams), - small (above 42, and up to 48 grams), - medium (above 48, and up to 55 grams), - large (above 55 , and up to 63 grams), - extra-large (above 63, and up to 69 grams), and - jumbo (more than 69 grams). b) Call and test the function in a loop as described by the following pseudocode: Get the weight ( −1 for end). Repeat until weight is −1 Call your function and print the egg category Get another weight ( −1 for end)

User MartinHH
by
8.4k points

1 Answer

1 vote

Final answer:

To solve this problem, you can define a value-returning function called 'calculateEggSize' that takes the weight of an egg as a parameter. Within this function, you can use conditional statements to determine the size-category of the egg based on its weight.

Step-by-step explanation:

To solve this problem, you can define a value-returning function called 'calculateEggSize' that takes the weight of an egg as a parameter. Within this function, you can use conditional statements to determine the size-category of the egg based on its weight. Here is an example implementation:

def calculateEggSize(weight):
if weight < 42:
return 'pee-wee'
elif weight > 42 and weight <= 48:
return 'small'
elif weight > 48 and weight <= 55:
return 'medium'
elif weight > 55 and weight <= 63:
return 'large'
elif weight > 63 and weight <= 69:
return 'extra-large'
else:
return 'jumbo'

# You can test the function with a loop
while True:
weight = float(input('Enter weight of the egg (-1 to exit): '))
if weight == -1:
break
egg_size = calculateEggSize(weight)
print('Egg size category:', egg_size)
print()

Learn more about calculateEggSize

User Yamaneko
by
9.0k points

No related questions found