even or odd
num=int(input("enter a number:"))
if num%2==0:
print(num, "num is even")
else:
print(num, "num is odd")
output:
enter a number:391 391 num is odd
use of not
use of not
not 3<4
output:
False
if the dish exists in the menu:
indian=["somosa","dal", "naan"]
chinese=["egg roll","pot sticker", "fried rice"]
italian=["pizza","pasta", "risotto"]
dish= input("enter a dish that you want")
if dish in indian:
print("dish is indian")
elif dish in chinese:
print("dish is chinese")
elif dish in italian:
print("dish is italian")
else:
print("my small brian cannot help you")
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