Friday, 7 May 2021

If Statement and For Loops

 even or odd

enter a number:391
391 num is odd


use of not

use of not

False

if the dish exists in the menu:

enter a dish that you wantchocolate
my small brian cannot help you
 
Printing patters like this:
* ** *** **** *****
def print_pattern(n):
# we need to run two for loops. Outer loop prints patterns line by line
# where as inner loop print the content of that specific lines
for i in range(n):
s = ''
for j in range (i+1):
s = s + '*'
print(s)
print_pattern(5) 
 
Adding the list values using for loops:
exp= [123,456,789,120]
total=0
for item in exp:
total=total + item
print(total)


No comments:

Post a Comment