'>' 'str'和'int'python3的实例之间不支持

时间:2017-07-30 19:41:09

标签: python-3.x

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)

1 个答案:

答案 0 :(得分:0)

当你从输入法中找回一个数字时,它是&#34; str&#34; 例如:

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

你通过写作来解决这个问题

num = int(num)