I have to write a program that asks the user how many pumpkin weights they have, and the reads that many pumpkin weights, printing each weight with two decimeal points and a comment and displays data about them to four decimal places. I need to find the average weight, maximum weight and minimum weight as well. I have to use functions as well. I thought I finished my program but I have continuously been getting an error saying that a str object cannot be interpreted as an integer. It may not even be that. I may have something else in my program wrong that I havent been able to catch. If you could help that would be great thank you!
# Purpose: write a program that asks the user
# how many pumpkin weights they have,
# and then reads that many pumpkin
# weights, printing each weight with
# two decimal points and a comment,
# and displays data about them to four
# decimal places using functions
def intro():
# print out the introduction
print()
print("Program to calculate statistics of a")
print("group of pumpkin weights.")
print("You will be asked to enter the number of")
print("pumpkins, followed by each pumpkin weight.")
print("Written by ARH.")
print()
def pumpkinInputs():
numPumpkins = input("Enter the number of pumpkins: ")
print()
print()
totalWeight = 0
count = 0
for pumps in range(numPumpkins):
count = count + 1
pumpWeight = int(input("Enter the weight for pumpkin "+str(count)+": "))
totalWeight = totalWeight + pumpWeight
if (pumpWeight >= 1500.00):
print(str(pumpWeight) + " is humungous")
elif (pumpWeight > 500.00):
print(str(pumpWeight) + " is huge")
elif (pumpWeight >= 300.00):
print(str(pumpWeight) + " is heavy")
elif (pumpWeight >= 100.00):
print(str(pumpWeight) + " is medium")
elif (pumpWeight >= 50.00):
print(str(pumpWeight) + " is featherweight")
else:
print(str(pumpWeight) + " is light")
return totalWeight, numPumpkins
def calcAverage(totalWeight, numPumpkins):
averageWeight = float(totalWeight) / float(numPumpkins)
return averageWeight
pumpkins = (numPumpkins + 1)
maxi = 0
for num in pumpkins:
weight = num
if (weight > maxi):
maxi = weight
mini = maxi
for num in pumpkins:
weight = num
if (weight < mini):
mini = weight
return maxi, mini
def printResults(numPumpkins, averageWeight):
print("Number of pumpkins:", numPumpkins)
print("The average weight is {0:0.4f}".format(averageWeight))
print("The maximum weight is {0:0.4f}".format(maxi))
print("The minimum weight is {0:0.4f}".format(mini))
print()
def main():
intro()
totalWeight, numPumpkins = pumpkinInputs()
averageWeight = calcAverage(totalWeight, numPumpkins)
printResults(numPumpkins, averageWeight)
main()