برنامه ای بنویسد که اعداد را تا زمانی که 1- وارد کنید دریافت و میانگین آنها و بزرگترین و کوچکترین آنها را نشان دهد
posnum = 0
conter = 0
sum = 0
max = 0
min = 0
terval = -1
print("\nInput a positive integer to calculate some processes or -1 to terminate:")
print("----------------------------------------")
while posnum != terval:
print("Input a positive integer or", terval, "to terminate: ", end="")
posnum = int(input())
if posnum > 0:
conter += 1
sum += posnum
if posnum > max:
max = posnum
if posnum < min:
min = posnum
else:
print("error: input must be positive! if negative, the value will only be -1! try again...")
print("\nYour input is for termination. Here are the results below:")
print("Number of positive integers is:", conter)
if conter > 0:
print("The maximum value is:", max)
print("The minimum value is:", min)
print("The average is", sum / conter)
- ۰۲/۰۶/۲۷