5.
Control Statements - 2
Problem #1
num = int(input("Enter a number"))
if num > 0:
print("Positive number")
else:
print("Not a positive number")
Enter a number-10
Not a positive number
Problem #2
rating = float(input("Enter a movie rating"))
if rating >= 3.5:
print('Movie is Hit')
else:
print("Movie is Flop")
Enter a movie rating2.5
Movie is Flop
Problem #3
A bartender is trying to determine whether he should serve drinks to someone. He only servers drinks to people 18 and older and when
he is not on break. Given the person's age, and whether the break time is in session.
age = int(input('Enter the customer age'))
on_break = int(input("Enter on break or not"))
if age >= 18 and on_break == 0:
print('Serve to the customer')
else:
print('Not serve to the customer')
Enter the customer age19
Enter on break or not1
Not serve to the customer
Problem #4
lang = input("Enter your favourite programming language")
if lang == 'Python':
print('Nice Choice')
else:
print("I don't know that language")
Enter your favourite programming languagepython
I don't know that language
Problem #5
lang = input("Enter your favourite programming language")
if lang == 'Python' or lang == 'Java':
print("Nice Choice")
else:
print("I don't know that language")
Enter your favourite programming languageJavascript
I don't know that language
Problem #6
lang = input("Enter your favourite programming language")
if lang == 'Python' or lang == 'Java':
print('Nice Choice')
else:
if lang == 'C++':
print('Too old school...')
else:
print("I don't know that language")
Enter your favourite programming languageJava
Nice Choice
Problem #7
lang = input("Enter your favourite programming language")
if lang == 'Python' or lang == 'Java':
print('Nice Choice')
else:
if lang == 'Golang':
print("You're a cool person I see...")
else:
if lang == 'JavaScript':
print("Okay so you are our web developer!")
else:
if lang == 'C++':
print('Too old school...')
else:
print("I don't know that language")
Enter your favourite programming languageGolang
You're a cool person I see...
lang = input("Enter your favourite programming language")
if lang == 'Python' or lang == 'Java':
print('Nice Choice')
elif lang == 'Golang':
print("You're a cool person I see...")
elif lang == 'JavaScript':
print("Okay so you are our web developer!")
elif lang == 'C++':
print('Too old school...')
else:
print("I don't know that language")
Enter your favourite programming languageC++
Too old school...
Quiz
a = 1
b = 0
c = 1
if (a and b):
print("Scaler is awesome")
elif (a and c):
print("ML is fun")
if (a and b and c):
print("Python is amazing")
if (a or b or c):
print("I love DS")
ML is fun
I love DS
FizzBuzz
n = int(input("Enter a number"))
if n %3 == 0:
print("Fizz")
if n %5 == 0:
print('Buzz')
if n%3==0 and n%5 == 0:
print('FizzBuzz')
Enter a number15
Fizz
Buzz
FizzBuzz
n = int(input("Enter a number"))
if n%3==0 and n%5 == 0:
print("FizzBuzz")
elif n %5 == 0:
print('Buzz')
elif n%3==0 :
print('Fizz')
Enter a number15
FizzBuzz
if 5 > 10:
print("fan")
elif 8 != 9:
print("glass")
else:
print("cream")
glass
Home Work Problems
Find out the grade of a student when the marks of 4 subjects are given percentage >= 85. grade = A percentage < 85 and percentage
>=70. grade = B percentage < 70 and percentage >=55. grade = C percentage < 55 and percentage>=40. grade = D percentage < 40.
grade = E
1. Program to find biggest number from three given numbers
Doubts
if False:
print('AI')
elif True:
print('ML')
else:
if True:
print("DS")
else:
print('DL')
lang = input("Enter your favourite programming language")
if lang == ('Python' or 'Java'):
print("Nice Choice")
else:
print("I don't know that language")
Enter your favourite programming languagePython
Nice Choice
Fav_Lang = input()
if Fav_Lang == "Python" or Fav_Lang == "Java":
print("Nice Choice")
if Fav_Lang == "C++":
print("Too old school.....")
else:
print("I don't know the lang")
Java
Nice Choice
I don't know the lang
lang = input("Enter your favourite programming language ")
if (lang == "Python" or "Java"):
print("Nice choice")
else :
print("I don't know that language ")
Enter your favourite programming language java
I don't know that language
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js