我很难跟踪输入的总数。我希望我的程序跟踪输入的总数并在while循环中断时将其打印出来。任何帮助表示赞赏!
r = float(input("enter r:"))
def main(r):
a = 3.14 * (float(r ** 2))
s_v = 0
total = 0
while True:
r = float(input("enter r:"))
if r == sentinal_value:
total += r
print("Total = " , total)
break
else:
print("Area = ", a)
continue
main(r)
答案 0 :(得分:1)
我假设您希望您的程序在每次迭代时都重新计算面积。按照书面规定,它将仅在您第一次运行mymian
函数时计算。您无需将任何参数传递给函数。
def mymian():
sentinal_value = 0
total = 0
while True:
r = float(input("enter r:"))
if r == sentinal_value:
print("Total number of r provided to this program" , total)
break
else:
print("Area = ", 3.14 * (float(r ** 2)))
total += 1
continue