Reputation: 327
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
Reputation: 1
Print() function returns str type value, you need to convert it into int or float type. int(print(' '))
Upvotes: 0
Reputation: 1
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
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
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