-3

What is wrong with the following code? I get an error.

largest = 0
smallest = 0

while True:
    num = raw_input("Enter a number: ")

    try:
        num = int(num)
        if num == 'done':
            break 
    except:
        print('Invalid input')
        continue

    if num < smallest:
        smallest = num

    if num > largest:
        largest = num

print('Maximum is ', largest)
print('Minimum is ', smallest)
Alexander
  • 9,737
  • 4
  • 53
  • 59
mmrbulbul
  • 390
  • 2
  • 12

2 Answers2

2

In the future, please include your error messages in the question. This is your error:

Traceback (most recent call last):
  File "./prog.py", line 5, in <module>
NameError: name 'raw_input' is not defined

That's because in Python 3 raw_input() was renamed to input().

Community
  • 1
  • 1
Xiong Chiamiov
  • 13,076
  • 9
  • 63
  • 101
1

You are trying to run a Python 2 application with a Python 3 interpreter.

Alexander
  • 9,737
  • 4
  • 53
  • 59