0% found this document useful (0 votes)
47 views

10.1. Python Practice - Flow Control

Practice flow control

Uploaded by

madhus.naragani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

10.1. Python Practice - Flow Control

Practice flow control

Uploaded by

madhus.naragani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo1.py
a = 33
b = 200

if b > a:
print("b is greater than a")
Output

Program Please execute the program and check the output


Name demo2.py
a = 33
b = 200

if b > a:
print("b is greater than a")
Output

1|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo3.py
a = 33
b = 33

if b > a:
print("b is greater than a")

elif a == b:
print("a and b are equal")
Output

Program Please execute the program and check the output


Name demo4.py
a = 200
b = 33

if b > a:
print("b is greater than a")

elif a == b:
print("a and b are equal")

else:
print("a is greater than b")

Output

2|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo5.py
a = 200
b = 33

if b > a:
print("b is greater than a")

else:
print("b is not greater than a")
Output

Program Please execute the program and check the output


Name demo6.py
a = 200
b = 33

if a > b: print("a is greater than b")

print("A") if a > b else print("B")


Output

3|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo7.py
a = 200
b = 33

if a > b: print("a is greater than b")

print("A") if a > b else print("B")

Output

Program Please execute the program and check the output


Name demo8.py
flag = True

if flag==True:
print("Welcome")
print("To")
print("Python programming language" )

Output

4|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo9.py
flag = False

if flag==True:
print("Welcome")
print("To")
print("Python programming language" )

Output

Program Please execute the program and check the output


Name demo10.py
i = 20;

if (i < 15):
print ("i is smaller than 15")
print ("i'm in if Block")

else:
print ("i is greater than to 15")
print ("i'm in else Block")

print ("i'm not in if and not in else Block")


Output

5|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo11.py
i = 10
if (i == 10):

if (i < 15):
print ("i is smaller than 15")

if (i < 12):
print ("i is smaller than 12 too")

else:
print ("i is greater than 15")
Output

Program Please execute the program and check the output


Name demo12.py
x = int(input("Enter x value :"))
y = int(input("Enter y value :"))
z = int(input("Enter z value :"))

if x>y and x>z:


print("x is greater than remaining two values")

elif y>z:
print("y is greater than remaining two values")

else:
print("z is greater than remaining two values ")
Output

6|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Calculating the marks and check the output


Name demo13.py
math = int(input("Enter your maths marks:"))
sci = int(input("Enter your science marks:"))
kan = int(input("Enter your Kannada marks:"))

a = (math + sci +kan)/3

i = int(a)

print("The total average 3 subjects are :",i,"%")

if i>90 and i<=100:


print("A+ bro")

elif i>80 and i<=90:


print("A bro")

elif i>60 and i<=80:


print("B+ bro")

elif i>50 and i<=60:


print("B bro")

elif i>=30 and i<=35:


print("C+ bro just pass")

elif i<35:
print("Sorry boss, you failed")
Output

7|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo14.py
print("Welcome to DANIEL Airport")
weight = float(input("How many pounds does your suitcase
weigh? "))

if weight > 50:


print("There is a $25 charge for luggage and already
deducted from your credit card, don’t get surprise.")

print("Thank you and Enjoy the Journey Boss.")

Output

Program Please execute the program and check the output


Name demo15.py
balance = -5

if balance < 0:
print("Balance is in negative mode please add funds now
or you will be charged a penalty.")

Output

8|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo16.py
num = 22
if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")

Output

Program Please execute the program and check the output


Name demo17.py
x=10

print(isinstance(x, int))
print(isinstance(x, str))

Output

Program Please execute the program and check the output


Name demo18.py
name="Daniel"

print(isinstance(name, str))
print(isinstance(name, int))

Output

9|Page 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo19.py
x=10

if isinstance(x, int):
print("integer data type")

else:
print("Its other type")

Output

Program Please execute the program and check the output


Name demo20.py
x=10

if isinstance(x, str):
print("string data type")

else:
print("It is an integer type")

Output

10 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo21.py
name="daniel "

if isinstance(name, str):
print("string data type")

else:
print("It is other type")

Output

Program Please execute the program and check the output


Name demo22.py
name="Daniel"

if isinstance(xyz, int):
print("integer data type")

else:
print("It is string data type")

Output

11 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo23.py

answer = input("Is Python teaching by Daniel, Yes or Not >> ")

if answer == "Yes":
print("Welcome to Python sessions by Daniel, please don
't sleep")

else :
print("I guess you are not student of Daniel.")

print("Thanks!")

Output

12 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo24.py
print("welcome to AiNextGen company...")

allowed_users = ['daniel', 'chiru', 'balayya']


username = input("What is your login name? : ")

if username in allowed_users:
print("Access granted, Enjoy Guru :")

else:
print("Sorry Boss, access denied: Contact Admin team.
Namaskaar")

Output

13 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo25.py
number = 4
guess = int(input('Guess number between 1 to 10 : '))

if guess == number:
print("Congratulations Dude, you guessed it but no prizes
:) ")

elif guess < number:


print('No, it is a little higher than guessed number')

else:
print('No, it is a little lower than guessed number')

Output

14 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo26.py

x = int(input("What is the time?"))

if x < 10:
print("Good morning")

elif x<12:
print("Soon time for lunch")

elif x<18:
print("Good day")

elif x<22:
print("Good evening")

elif x>=22 and x<=24:


print("Good night")

else:
print("Dude, please Buy clock and learn timings, Good
day")

Output

15 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo27.py

marks=int(input("Enter marks: "))

if marks >= 90:


print("A grade")

elif marks >=80:


print("B grade")

elif marks >=70:


print("C grade")

elif marks >= 65:


print("D grade")

elif marks >= 55:


print("E grade")

elif marks >= 35:


print("Congrats for great achievement, hope you are from
Back bench")

else:
print("Congratulation Dude, you have successfully failed")

Output

16 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo28.py
marks=int(input("Enter marks: "))

if marks >= 90:


if marks > 96:
print("A++")

elif marks > 93 and marks <= 96:


print("A+")

elif marks >= 90:


print("A grade")

elif marks >=80:


print("B grade")

elif marks >=70:


print("C grade")

elif marks >= 65:


print("D grade")

elif marks >= 55:


print("E grade")

elif marks >= 35:


print("Congrats for great achievement, hope you are from
Back bench")

else:
print("Congratulation Dude, you have successfully failed")

Output

17 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo29.py
while True:
n = input('Please enter 4 to quit application: ')
if n == '4':
break

print("Thank you")

Output

18 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo30.py
number = 4
running = True

while running:
guess = int(input('Please guess number between 1 to 10 :
'))

if guess == number:
print('Congratulations Dude, you guessed it but no
prizes :)')
running = False

elif guess < number:


print('No, it is a little higher than that.')

else:
print('No, it is a little lower than that.')

else:
print('The while loop is over.')

Output

19 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo31.py
for x in range(1, 10):
if (x%2==0):
print(x)

Output

Program Please execute the program and check the output


Name demo31.py
for x in range(1, 20):
if (x%2==0) and (x%4==0):
print(x)

Output

Program Please execute the program and check the output


Name demo32.py
data = [12, 45.678, 1+2j, True, 'daniel', [1, 2, 3]]

for item in data:


print("Type of ",item, " is ", type(item))

Output

20 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program
Accepts a sequence of lines and print those lines by using list,
when entered blank line then program terminates

Name demo33.py
lines = []
print(lines)

while True:
l = input()

if l:
lines.append(l)
else:
break

print(lines)

Output

21 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo34.py
s = input("Enter string, mixed with numbers: ")
l=0
for c in s:
if c.isalpha():
l = l+1

print("Characters count from entered text:", l)

Output

Program Please execute the program and check the output


Name demo35.py
s = input("Enter string, mixed with numbers: ")
l=0
for c in s:
if c.isdigit():
l = l+1

print("Numbers count from entered text:", l)

Output

22 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo36.py

l = input("Enter any alphabet letter: ")

if l in ('a', 'e', 'i', 'o', 'u'):


print(l," is a vowel.")

else:
print(l, " is a consonant.")

Output

Program Please execute the program and check the output


Name demo37.py

l = input("Enter any alphabet letter: ")

if len(l)==1:

if l in ('a', 'e', 'i', 'o', 'u'):


print(l," is a vowel.")

else:
print(l, " is a consonant.")

else:
print("Invalid input")

Output

23 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo38.py

print("List of months: January, February, March, April, May,


June, July, August, September, October, November, December")

month_name = input("Enter name of Month: ")

if month_name == "February":
print("No. of days: 28/29 days")

elif month_name in ["April", "June", "September", "November"]:


print("No. of days: 30 days")

elif month_name in ["January", "March", "May", "July",


"August", "October", "December"]:
print("No. of days: 31 day")

else:
print("Any month name like", month_name, "?")

Output

24 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo39.py

n = int(input("Enter a number for table: "))

for i in range(1,11):
print(n, 'x', i,'=',n*i)

Output

Program Please execute the program and check the output


Name demo40.py
x = ['Daniel', 'abhishek']
for i in x:
print(i)

Output

25 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo41.py
x = ['Daniel', 'abhishek']
for i in x:
print(i.upper())

Output

Program Please execute the program and check the output


Name demo42.py
x = ['DANIEL', 'ABHISHEK']
for i in x:
print(i)

Output

Program Please execute the program and check the output


Name demo43.py
x = ['DANIEL', 'ABHISHEK']
for i in x:
print(i.lower())

Output

26 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo44.py
x = [1, 2, 3]
for i in x:
print(i.upper())

Output

Program Please execute the program and check the output


Name demo45.py
i=1
while i<=20:
if i%2 == 0:
break
print(i)
i += 2

Output

27 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo46.py
i=1
while i<=20:
if i%3 == 0:
break
print(i)
i += 2

Output

Program Please execute the program and check the output


Name demo47.py
i=1
while False:
if i%3 == 0:
break
print(i)
i += 2

Output

28 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo48.py
True = False
while True:
print(True)
break

Output

Program Please execute the program and check the output


Name demo49.py
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

Output

29 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo50.py
i=0
while i < 3:
print(i)
i += 1
else:
print(0)

Output

Program Please execute the program and check the output


Name demo51.py
x = "python"
for i in x:
print(i)

Output

30 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo52.py
x = "python"
for i in x:
print(i, end= "")

Output

Program Please execute the program and check the output


Name demo53.py
x = "python"
for i in x:
print(i, end= " ")

Output

31 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo54.py
x = "python"
for i in x:
print(i+"Z")

Output

Program Please execute the program and check the output


Name demo55.py
x = "python"
if i in x:
print(i)

Output

32 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo56.py
x = "python"
while i in x:
print(i)

Output

Program Please execute the program and check the output


Name demo57.py
x = "python"
i="a"
while i in x:
print(i)

Output

Program Please execute the program and check the output


Name demo58.py
x = 'abcd'
for i in range(10):
print(i)

Output

33 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo59.py
x = 'abcd'
for i in range(x):
print(i)

Output

Program Please execute the program and check the output


Name demo60.py
x = 'abcd'
for i in range(len(x)):
print(i)

Output

Program Please execute the program and check the output


Name demo61.py
x = 'abcd'
for i in range(x):
print(i)

Output

34 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo62.py
x = 'abcd'
for i in range(len(x)):
print(i.upper())

Output

Program Please execute the program and check the output


Name demo63.py
x = 'abcd'
for i in range(len(x)):
print(x[i])

Output

Program Please execute the program and check the output


Name demo64.py
x = 'abcd'
for i in range(len(x)):
print(i[x])

Output

35 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo65.py
x = 123
for i in x:
print(i)

Output

Program Please execute the program and check the output


Name demo66.py
for i in range(0):
print(i)

Output

Program Please execute the program and check the output


Name demo67.py
for i in range(2):
print(i)

Output

36 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo68.py
for i in range(2.0):
print(i)

Output

Program Please execute the program and check the output


Name demo69.py
for i in range(int(2.0)):
print(i)

Output

Program Please execute the program and check the output


Name demo70.py
for i in "abcd":
print(i)

Output

37 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo71.py
for i in " ":
print(i)

Output

Program Please execute the program and check the output


Name demo72.py
x=2
for i in range(x):
x += 1
print (x)

Output

Program Please execute the program and check the output


Name demo73.py
x=2
for i in range(x):
x -= 2
print (x)

Output

38 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo74.py
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("no value")

Output

Program Please execute the program and check the output


Name demo75.py
for i in range(5):
if i == 5:
break
else:
print(i)
else:
print("no value")

Output

39 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL


Data Science – Python – Practice - Flow Control

Program Please execute the program and check the output


Name demo76.py
text = "my name is python"
for i in text:
print (i, end=",")

Output

40 | P a g e 10.1. PYTHON PRACTICE - FLOW CONTROL

You might also like