PYTHON PROGRAMS For CONTROL STATMENT

 Experiment – 1

Program On Control Statements

4.

fruits = ["apple","mango","chiku"] for x in fruits:

print("a is positive no") else:

print("a is negative no")

output:☺☺

a is positive

------_---------------------*--------------------*-----------------

2.

a = 0

if a > 0:

print("a is positive no") else:

print("a is negative no")

output:

a is negative no

------------*---------------------*--------------------*----------

3.

num = float(input("enter one no")) if num==0:

print("user has enter zero") elif num>0:

print("num is positive no") else:

print("num is negative no")

output:

    • user has enter zero ( num = 0 )

    • num is positive no ( num > 0 )

    • num is negative no ( num < 0 )

if x == "mango": break

print(x)

output:

apple

_________*___________*_________*_____________

5.

fruits = ["apple","banana","cherry"] for x in fruits:

if x == "banana": continue

print(x)

output:

apple cherry 6.

for x in range(6): if x == 3:

break else:

print("Finally Finished!!")

output: finally finished!!

Finally Finished!! Finally Finished!!

____*__________________*___________*__________



7. 9.

adj = ["red","big","tasty"]

fruits = ["apple","banana","cherry"] for x in adj:

for y in fruits: print(x,y)

output: red apple red banana red cherry big apple big banana big cherry tasty apple

tasty banana tasty cherry 8.

i = 1 while i<6:

print(i) if i == 3:

break i+=1

output:

1

2

3

i = 0 while i<6:

print(i) i+=1

if i == 3: continue

output:

1

2

4

5

6

10.

num1 = float(input("Enter 1st number")) num2 = float(input("Enter 2nd number")) num3 = float(input("Enter 3rd number")) if num1 >= num2 and num1 >= num3:

out = num1

elif num2 >= num1 and num2 >= num3: out = num2

else:

out = num3

print("The largest number among",out)

output:

    • The largest number among 3 ( if num1 = 1, num2 = 2, num3 = 

    • The largest number among 4 ( if num1 = 1, num2 = 4, num3 = 3)

    • The largest number among 5 ( if num1 = , num2 = 4, num3 = 

Comments

Popular posts from this blog

Govt rolls out PM internship portal, 190+ firms offer 90k opportunities

Top News Today: Mumbai Polls, Oil Imports, AI Growth & Naval Power

Several highly anticipated entertainment releases are set for 2025