Nested and While
Nested and While
# #Nested if:
# #An if condition present inside another if condition is called
# # nested if.
#
# '''
# syntax:
# if condition:
# ___________________
# |if condition: |
# | ___________ |
# | | TSB | |
# | |___________| |
# |else: |
# | ___________ |
# | | FSB | |
# | |___________| |
# |___________________|
# else:
# ___________
# | FSB |
# |___________|
# '''
# # Working:
# #Firs it will check the condition assosiated with outer if, if the
# #condition is True than it enter into TSB and it will check the
# # condition of nested if, if it is True than it will execute the
# # TSB of nested if. else it will check it is having elif or else...
# # if cond of outer if is False than it executes FSB of outer if.
#
#
# #19. WAP to check given number is even or odd, before that check it is pos
# n= 34
# if n > 0:
# if n%2==0:
# print('Positive even number')
# else:
# print('Positive Odd number')
# else:
# print('Negative number')
#
# #20. WAP to check first char of a string is vowel or not, if it is vowel check
whether length is odd
# # or even, else check string is ending with vowel or not.
#
# s= 'Adom'
# if s[0].lower() in 'aeiou':
# if len(s)%2==0:
# print("String is starts with vowel and it's length is even")
# else:
# print('Startswith Vowels but length is odd')
# else:
# if s[-1].lower() in 'aeiou':
# print('It is ending with vowel')
# else:
# print('It is starting and ending with consonant')
# #21. WAP to check given list is having specified number or not, if it is present
check the
# # occurrences are greater than 2, if it not don't print anything.
# # If it is not present print 'Specified num is not present'
# lst= [23, 45, 34, 45, 67, 78, 89, 45]
# num= 45
# if num in lst:
# c = lst.count(num)
# if c > 2:
# print(f'Specified number is present {c} times')
# else:
# print('Specified num is not present')
#
# #22. WAP to check second Largest number among 3 numbers.
# a, b, c = 23, 45, 12
# if a>b and a>c:
# if b>c:
# print(f'{b} is second largest')
# else:
# print(f'{c} is second largest')
# elif b>c:
# if a>c:
# print(f'{a} is second largest')
# else:
# print(f'{c} is second largest')
# else:
# if a>b:
# print(f'{a} is second largest')
# else:
# print(f'{b} is second largest')
# '''
# Enter country name which you want to visit: India
# Enter city name: Mangaluru
# ಕರ್ನಾಟಕಕ್ಕೆ ಸ್ವಾಗತ
# '''
# # Looping statements
#
# #Looping statements are used to repeat a set of statements for any
# # number of times.
#
# #Here we have two types in loopings
# #1. While loop
# #2. for loop
#
# #1. While:-
# # While loop is a looping statement which is used for repeating
# # some set of statements for a specified number of time.
# #while loop will always be assosiated with a condition, the statement
# #block will be executed unitil the given condition becomes False.
#
# # While loop will always be having looping variable which will be
# #use in condition and the looping variable value must be updated
# #(either incrementation or decrementation) or else the while loop will
# # enter infinity loopings.
#
# '''
# syntax:
# initialization = value #looping variable
# while condition:
# TSB
# updation
# '''
#
# Working
# step-1: Looping variable should always be declared before the while.
# step-2:
# First the while condition will check, if the condition True than the
# TSB assosiated with the while loop will be executed after executes
# TSB once the control again will go back to the while condition with
# updated value of the looping variable again condition will check,
# if the condition is True than the TSB will be executed again and
# this process will keeps on happening until the while condition
# will become False.
#
# Note: If ever the looping is not updated in each & every
# ittiration than the while condition will be check for the
# same value for infinte number of times. Thus it will enter
# infinite time loop.
#
# #Ex:
#
# i = 0 #initialization #looping variable/ref variable
# while i < 5:
# print("Hello Python")
# i = i + 1 # i += 1 #Updation
# '''
# tracing:
# i=0, 0<5 --> T, print, i=0+1, i=1
# i=1, 1<5 --> T, print, i=1+1, i=2
# i=2, 2<5 --> T, print, i=2+1, i=3
# i=3, 3<5 --> T, print, i=3+1, i=4
# i=4, 4<5 --> T, print, i=4+1, i=5
# i=5, 5<5 --> F, Termination.
# '''