【发布时间】:2016-11-28 12:49:03
【问题描述】:
我一直在尝试完成我的作业,但遇到了逻辑错误。我使用的是 Python 3。
print("Car Service Cost")
def main():
loan=int(input("What is your loan cost?:\t"))
maintenance=int(input("What is your maintenance cost?:\t"))
total= loan + maintenance
for rank in range(1,10000000):
print("Total cost of Customer #",rank, "is:\t", total)
checker()
def checker():
choice=input("Do you want to proceed with the next customer?(Y/N):\t")
if choice not in ["y","Y","n","N"]:
print("Invalid Choice!")
else:
main()
main()
我得到了这个输出:
Car Service Cost
What is your loan cost?: 45
What is your maintenance cost?: 50
Total cost of Customer # 1 is: 95
Do you want to proceed with the next customer?(Y/N): y
What is your loan cost?: 70
What is your maintenance cost?: 12
Total cost of Customer # 1 is: 82
Do you want to proceed with the next customer?(Y/N): y
What is your loan cost?: 45
What is your maintenance cost?: 74
Total cost of Customer # 1 is: 119
Do you want to proceed with the next customer?(Y/N): here
我的排名每次都是 1。我做错了什么?
【问题讨论】:
-
maincallschecker进入循环,调用main--> 你根本没有循环,只是在每个 first 迭代中重新启动main循环(你迟早会用完递归深度)。
标签: python python-3.x for-loop range