Python循环和列表问题

时间:2017-03-26 08:57:50

标签: python list loops

任何人都可以帮助我使用我的代码,我似乎无法看到问题。我是新编程的,所以它可能很容易看到。

我以4件生日礼物为例。

x = input("How many birthday gifts do you need to buy? ")
list = []

for gifts in range(int(x)):
    name= input("Enter Name: ")
    list.append(name)

print(list)

def budget (a,b,c,d):
    return budget(a,b,c,d*10)

a = len(list[0])
b = len(list[1])
c = len(list[2])
d = len(list[3])

budget(a,b,c,d*10)

print("The Budget for",list[0],"s gift is: ",a)
print("The Budget for",list[1],"s gift is: ",b)
print("The Budget for",list[2],"s gift is: ",c)
print("The Budget for",list[3],"s gift is: ",d)

我的错误代码

How many birthday gifts do you need to buy? 4
Enter Name: lee
Enter Name: lee
lEnter Name: ee
Enter Name: lee
Traceback (most recent call last):
['lee', 'lee', 'lee', 'lee']
  File "C:/Users/Ethan/PycharmProjects/untitled1/Birthday Gift List.py", line 18, in <module>
    budget(a,b,c,d*10)
  File "C:/Users/Ethan/PycharmProjects/untitled1/Birthday Gift List.py", line 11, in budget
    return budget(a,b,c,d*10)
  File "C:/Users/Ethan/PycharmProjects/untitled1/Birthday Gift List.py", line 11, in budget
    return budget(a,b,c,d*10)
  File "C:/Users/Ethan/PycharmProjects/untitled1/Birthday Gift List.py", line 11, in budget
    return budget(a,b,c,d*10)
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded

0 个答案:

没有答案