[英]Python shows no error code, but has no output
I am brand new to coding so I hope this is a small mistake.我是编码新手,所以我希望这是一个小错误。 Below is the code for an assignment on a paper carrier's salary.以下是纸质承运人工资分配的代码。 I get no error codes but no output, even the print functions do not show.我没有收到错误代码,但没有 output,甚至打印功能也没有显示。 Please help请帮忙
# This program will calculate the weekly pay of a paper carrier.
# Developer: Hannah Ploeger Date: 08/30/2022
def main():
# initialize variables
paperCost = 4
commission = 0.05
# prompt user for number of papers
numPaper = eval(input("How many papers are delivered on your route?"))
# prompt user for days of delivery
numDays = eval(input("How many days was the paper delivered this week"))
# prompt user for tips recieved
numTips = input("How much did you recieve in tips this week?")
# calculate salary
weekPay = ((numPaper * numDays) * paperCost) * commission
totalPay = weekPay + numTips
# display output
print("This week you delivered", numPaper, "papers")
print("Your salary this week is $", weekPay)
print("Your total tips were $", numTips)
print("Your total pay is $", totalPay)
add this:添加这个:
if __name__ == "__main__":
main()
just call the main function只需调用主 function
def main():
# initialize variables
paperCost = 4
commission = 0.05
# prompt user for number of papers
numPaper = eval(input("How many papers are delivered on your route?"))
# prompt user for days of delivery
numDays = eval(input("How many days was the paper delivered this week"))
# prompt user for tips recieved
numTips = input("How much did you recieve in tips this week?")
# calculate salary
weekPay = ((numPaper * numDays) * paperCost) * commission
totalPay = weekPay + numTips
# display output
print("This week you delivered", numPaper, "papers")
print("Your salary this week is $", weekPay)
print("Your total tips were $", numTips)
print("Your total pay is $", totalPay)
main() # calling main function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.