user3307366
user3307366

Reputation: 327

Reading user input in Python

Write nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amount2.

this is what I have so far:

amount1=print('Enter amount1:')
amount2=print('Enter amount2:')
if amount1> 10 and amount2< 100:
    if amount1>amount2:
        print('amount1 is greater')
    elif amount2>amount1:
        print('amount2 is greater')
else:
    print('Amounts not in valid range')

when I run the program, this error message comes up:

Traceback (most recent call last):
  File "/Users/Yun/Documents/untitled", line 3, in <module>
    if amount1> 10 and amount2< 100:
TypeError: unorderable types: NoneType() > int()

Upvotes: 0

Views: 5227

Answers (4)

Print() function returns str type value, you need to convert it into int or float type. int(print(' '))

Upvotes: 0

Mesgana Desta
Mesgana Desta

Reputation: 1

  1. You need to use input instead of the print function.
  2. You need to cast the variables amount1 and amount2 as an int data type.
    amount1=int(input('Enter amount1:'))
    amount2=int(input('Enter amount2:'))
    if amount1> 10 and amount2< 100:
        if amount1>amount2:
            print('amount1 is greater')
        elif amount2>amount1:
            print('amount2 is greater')
    else:
        print('Amounts not in valid range')

Upvotes: 0

akaRem
akaRem

Reputation: 7638

Did you mean

amount1=raw_input('Enter amount1:')
amount2=raw_input('Enter amount2:')

if amount1> 10 and amount2< 100:
    if amount1>amount2:
        print('amount1 is greater')
    elif amount2>amount1:
        print('amount2 is greater')
else:
    print('Amounts not in valid range')

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1125078

The print() function returns None, which you store in amount1 and amount2. You probably meant to use input() there instead:

amount1 = input('Enter amount1:')
amount2 = input('Enter amount2:')

Upvotes: 4

Related Questions