我正在尝试创建一个程序来查找输入的 n 个数字的平均值,但我无法让递归工作。该程序有点工作,但是当我想要它时它不会退出 while 语句。
print("This program 'is' designed to find the average of n numbers you input\n") #print statement that introduces the average finder
counter = 0 #this counter will count how many numbers the user has inserted into the program and will be used as denominator
sum_of_numbers = 0 #this number is set as 0 as currently the sum is 0, as more numbers are inputed, they will be added together
first_question = input('''Would you like to enter a number? Type "yes" if you do, and "no" if you don't. \n\n''') #takes input of yes or no to see whether user wants to find average of numbers
while first_question == "yes" :
ent_num = int(input("Enter your number here:"))
sum_of_numbers = sum_of_numbers + ent_num
counter = counter + 1
second_question = input('''Would you like to enter another number after this? Type "yes" if you do, and "no" if you don't. \n''')
while second_question == "yes" :
ent_num = int(input("Enter your next number here: "))
sum_of_numbers = sum_of_numbers + ent_num
counter = counter + 1
else :
print("Your average is " + str(sum_of_numbers/counter))
有人可以帮我弄清楚吗?
我不能使用诸如 try 或 eval 或 len 之类的功能,它们都是非常基本的东西,例如我班上的第三天