Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Help
#1
How come if I Put this "max = a if ( a > b ) else b" by itself it works? But if I try putting together with other code like this "a = 1
b = 2
print( '\nVariable Is :' , "One" if ( a == 1 ) else "Not One"
( 'Variable a Is :', 'Even' if ( a % 2 == 0 ) else 'Odd' )
( '\nVariable 2 Is :', 'One' if  ( b == 1 ) else'Not One' )
( 'Variable 2 Is :', 'Even' if ( b % 2 == 0 ) else 'Odd' )
max = a if ( a > b ) else b
print( 'nGreater Value Is:', max )
it doesn't work?
Reply
#2
You are using improper syntax,
conditional if else should be like
print('\nVariable Is :  ', end='')
if a == 1:
    print('One')
else:
    print('Not One')
Reply
#3
Aditional, this should be changed:
max = a if ( a > b ) else b
into:
result_max = max(a, b)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020