我似乎无法获得多次显示的用户输入。例如,如果输入的是Python 2.7.5,在函数中使用循环并调用函数
Jeff 6
输出应该
Jeff
Jeff
Jeff
Jeff
Jeff
Jeff
我新的功能在Python,但这里是我的代码至今:
def getName():
name = raw_input("please enter name")
return name
def getRepval():
irepnum = float(raw_input("please enter number to show name entered"))
return irepnum
def inamed(name, irepnum):
count = 1 #the loop to show the name entered by the user
while irepnum != count:
print name
count += 1 #do I need to use return??
def main(): #having the main func like this gives me an infinite loop
irepnum = 0
iname = getName() #I think my problem is somewhere here.
irepnum = getRepval()
inamed(irepnum,name)
main()
你的预期产出是什么,你得到的是什么产出?你说你得到这个名字有问题,但不要说出问题所在。我怀疑问题是当你调用inamed时irepnum <1,所以该函数中的循环永远不会结束。对于像这样的循环使用少于条件的做法是很好的做法,以防止可能出现的超出范围的错误,例如使用'while count
我的错,当我有一个无限循环时运行代码 – JuanB457
我可以阅读。你将不得不更具描述性。 –