这道题最大的需要就是能够进行两个数值的对比,同时还能让更多的数值依次进入到对比中。
这道题的解题版本
这个版本只是能统计出谁是最大数。但是无法统计最大数出现了多少次。
number = ""
count = 0
data_number = 0
while number != 0:
number = eval(input("Enter a number(0: for end of input): "))
if number > data_number:
data_number = number
count += 1
print("The largest number is", data_number)
print("The occurrence count of the largest number is", count)
number_of_input = eval(input("Enter a number (0: for end of input): "))
largest_num = number_of_input
little_num = 0
count_times = 0
if number_of_input == 0:
print("This program don't zero")
else:
while number_of_input != 0:
number_of_input = eval(input("Enter a number (0: for end of input): "))
if number_of_input > largest_num:
largest_num = number_of_input
count_times += 1
elif number_of_input == largest_num:
count_times += 1
print(f"The largest number is {largest_num}")
print(f"The occurrence count of the largest number is {count_times}")