![](/img/trans.png)
[英]i wrote this code to find the largest and smallest (int)number but it does not work
[英]Find Largest and Smallest number code not working on python
設計一個帶有循環的程序,讓用戶輸入一系列數字。 用戶應輸入 - 99 以表示系列結束。 輸入所有數字后,程序應顯示輸入的最大和最小數字。
當我 go 運行我的程序並輸入一個像“4”這樣的數字時,它返回說最小和最大的數字是 4。但是當我想輸入一系列像“3、4、5”這樣的數字時,它會出錯。 不知道是我打錯了還是我的程序有問題。 讓我知道你們的想法
def main():
displayWelcome()
inputNum = int(); smallest = int(); largest = int()
smallest = None
largest = None
SENTINEL = -99
# program description
while True:
inputNum=int(input('Enter a number (Zero indicates end of input): '))
if inputNum == SENTINEL:
print('End of program')
break
if smallest is None or inputNum < smallest:
smallest = inputNum
if largest is None or inputNum > largest:
largest = inputNum
displayLargestSmallest(largest, smallest)
def displayWelcome():
print ('This program displays the largest and smallest numbers \
entered by the user from a series of numbers')
def displayLargestSmallest(最大,最小):
#module to display numbers input
print('The largest number input is ', largest)
print('The smallest number input is', smallest)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.