Conditional Statements
Conditional Statements
In [2]: if b > a:
print(' b is greater value')
b is greater value
In [13]: if a>b:
print('a is smaller value')
print('execution is done')
In [14]: #w.a.p to check age eligibility for voting of a candidate. take age
#as a dynamic input
In [17]: a,b
If -else
If the condition is true , code block associated to true will get executed ,else, code block associated to else will get executed syntax: if : block of code else: block of code
In [19]: if a>b:
print('a is greater value:',a)
print('Execution is done')
else:
print('b is greater value',b)
print('execution is done')
b is greater value 30
execution is done
if -elif -else
if : block 1 elif : block2 elif : block3 . . . else: defalut block
In [21]:
if a > b:
print('a is greater value: ',a)
print('Execution is done')
elif b>a:
print('b is greater value',b)
print('Execution is done')
elif a == b:
print('a and b are equal',a,b)
print('Execution is done')
else:
print('No condition is true')
print('Execution is done')
Enter a value: 20
Enter b value34
b is greater value 34
Execution is done
In [28]: # w.a.p to find the largest number among three given numbers , take dynamic inputs
Enter a value: 10
Enter b value: 10
Enter c value: 23
c is largest number: 23
In [51]: #w.a.p to check eligibility of candidate for voting. if candidate is not eligible for
# voting find the difference between candidates age and voting eligibility age ,
#print a message that wait for # number of year to get eligibility for voting
In [53]: #w.a.p to check if a given string starts with a character 's', if true print 'welcome' else
#print 'thank you'
In [57]: #w.a.p to check if a string is a title or not , if true print ' given string is a title',
#else convert your string into title and print converted string
In [59]: s.istitle()
Out[59]: True
In [61]: #w.a.p to check whether given numbers is positive or not ? if not add 10 and print the
#number
Enter a number: 10
Given number is positive
In [ ]: