这道题最大的需要就是能够进行两个数值的对比,同时还能让更多的数值依次进入到对比中。
这道题的解题版本
这个版本只是能统计出谁是最大数。但是无法统计最大数出现了多少次。
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 = numbercount += 1print("The largest number is", data_number)
print("The occurrence count of the largest number is", count)
这个是在第n次做后的得出的结果。这个代码不是这次做出来的。是之前的。
number_of_input = eval(input("Enter a number (0: for end of input): "))
largest_num = number_of_input
little_num = 0
count_times = 0if 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_inputcount_times += 1elif number_of_input == largest_num:count_times += 1print(f"The largest number is {largest_num}")print(f"The occurrence count of the largest number is {count_times}")