How to use if statement on python


An if statement is a conditional statement in python. its used thus:
if (condition):
      print(statement)
else:
     print(statement)

For example on python 3 and above:
print('please insert a number')
a=int(input(''))
print('please insert another number')
b=int(input(''))

if (a>b):
    print(a,' is larger')
else:
    print(b,' is larger')

For example on python 2.7:
#!/usr/bin/python
print 'please insert a number'
a=input('')
print 'please insert another number'
b=input('')

if (a>b):
    print(a,' is larger')
else:
    print(b,' is larger')

Please leave your comment if you have any problem.


1 comments:

Post a Comment