2017-07-30 31 views
-1
largest = None 
smallest = None 
while True: 
    num = input("Enter a number: ") 
    if num == "done": 
     break 
    try: 
     inp = int(num) 
    except: 
     print("Invalid Input") 
     continue 
    if largest is None or num > largest: 
     largest = inp 

    if smallest is None or num < smallest: 
     smallest = inp 

print("Maximum is", largest) 
print("Smallest is", smallest) 
+0

的可能的複製[類型錯誤: '<=' 不是 'STR' 和 'INT' 的實例之間支承](https://stackoverflow.com/questions/41950021/typeerror-not-在str和int的實例之間支持) – miradulo

+0

P在這裏加入你的代碼。這對我們來說不是一件好事 – AK47

回答

0

當你從輸入法得到一個數是例如鍵入「STR」 :

>>> num = input("enter num:") 
enter num:5 
>>> type(num) 
<class 'str'> 

你修正,與寫

num = int(num) 
+0

幫助....但是inp = int(num) –

+0

是什麼問題,您可以將inp轉換爲整數,但仍然使用'>'運算符使用num – aviad

+0

沒有與inp的問題你只需要在比較時使用int(num) – aviad

相關問題