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

Pythonexperiment No.3

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Pythonexperiment No.3

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

1) Python If Statement:
Input:
number = 10
# check if a number is greater than 0
if number > 0:
print('number is positive')
Output:
number is positive

2) Python If-else Statement:


Input:
age = int(input("enter your age: "))
if age>18:
print("Yes")
else:
print("No")
Output:
Enter your age: 30
Yes

3) Python FOR Statement:


Input:

for i in range(5):
print(i)
Output:

0
1
2
3
4

Input:

fruits=["apple", "banana", "cherry"]


for x in fruits:
print(x)
Output:
apple
banana
cherry
Input:
#Measure some strings:
words = ['cat', 'window', 'defenestrate']
for w in words:
print(w, len(w))

Output:
cat 3
window 6
defenestrate 12

4) Python Break and Continue Statement:

Input:

for i in range(10):
if i ==4:
break
print(i)

Output:

0
1
2
3

Input:

fruits=["apple", "banana", "cherry"]


for x in fruits:
print(x)
if x=="banana":
break
Output:
apple
banana

Input:

for num in range(2,10):


if num % 2 == 0:
print("found an even number", num)
continue
print("found an odd number", num)

Output:

found an even number 2


found an odd number 3
found an even number 4
found an odd number 5
found an even number 6
found an odd number 7
found an even number 8
found an odd number 9

You might also like