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

Python Class 2 (12-9-24)

Uploaded by

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

Python Class 2 (12-9-24)

Uploaded by

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

n=int(input('enter the n:'))

i=1
while (i<=n) :
print(i)
i+=1

enter the n:2


1
2

n=int(input('enter the n:'))


i=1
while (i<=n) :
if(i==3):
break
print(i)
i+=1

enter the n:5


1
2

n=int(input('enter the n:'))


i=0
while (i<n) :
i+=1
if(i==3):
continue
print(i)

enter the n:5


1
2
4
5

n=int(input('enter the n:'))


i=1
while (i<=n) :
print(i)
i+=1
else:
print("else block")

enter the n:4


1
2
3
4
else block

# while(True): #infinite loop


# print("hello")

while(1): #infinite loop


print("hello")
hello

i=1
while(i<=5):
pass

print("end")

---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-20-6245bd9be5d8> in <cell line: 2>()
1 i=1
----> 2 while(i<=5):
3 pass
4
5 print("end")

KeyboardInterrupt:

print(range(5))

range(0, 5)

for i in range(5): #for(i=0;i<5;i++)


print(i)

0
1
2
3
4

for i in range(1,5): #for(i=1;i<5;i++)


print(i)

1
2
3
4

for i in range(1,6): #for(i=1;i<5;i++)


print(i)

1
2
3
4
5

n=int(input('enter the n:'))


for i in range(1,n+1):
print(i)
enter the n:5
1
2
3
4
5

n=int(input('enter the n:'))


for i in range(1,n+1,1): #for(i=1;i<5;i++)
print(i)

enter the n:5


1
2
3
4
5

n=int(input('enter the n:'))


for i in range(n,0,-1): #for(i=n;i>0;i--)
print(i)

enter the n:5


5
4
3
2
1
0

n=int(input('enter the n:'))


for i in range(n,0,-2): #for(i=n;i>0;i--)
print(i)

enter the n:10


10
8
6
4
2

n=int(input('enter the n:'))


j=2
for i in range(n):
print(j)
j=j*2
# i=i*10

enter the n:10


2
4
8
16
32
64
128
256
512
1024

for x in "python":
print(x)

p
y
t
h
o
n

msg=input("enter the string:")


v=0
c=0
for x in msg:
if x in "aeiouAEIOU":
v=v+1
elif x in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ":
c=c+1

print("number of vowel is:",v)


print("number of consonent is:",c)

enter the string:hello python123@


number of vowel is: 3
number of consonent is: 8

msg=input("enter the string:")


v=0
c=0
for x in msg:
if x in "aeiouAEIOU":
print("vowel is:",x)
elif x in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ":
print("cosonant is:",x)

# print("number of vowel is:",v)


# print("number of consonent is:",c)

enter the string:hello


cosonent is: h
vowel is: e
cosonent is: l
cosonent is: l
vowel is: o

msg=input("enter the string:")


v=""
c=""
for x in msg:
if x in "aeiouAEIOU":
v=v+x
elif x in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ":
c=c+x
print("vowel is:",v)
print("consonent is:",c)

enter the string:hello


vowel is: eo
consonent is: hll

if "y" in "python":
print("present")
else:
print("not present")

not present

if "k" not in "python":


print("not present")
else:
print("present")

not present

n=int(input('enter the n:'))


for i in reversed(range(n)): #for(i=n;i>=0;i--)
print(i)

enter the n:5


4
3
2
1
0

for x in reversed("python"):
print(x,end="")

nohtyp

msg=input("enter the string:")


for x in reversed(msg):
print(x,end="")

enter the string:hello


olleh

for i in range(5): #for(i=0;i<5;i++)


print(i)
else:
print("End of loop")

0
1
2
3
4
End of loop
msg=input("enter the string:")
rev=""
for x in reversed(msg):
rev=rev+x
if(rev==msg):
print("Palindrome")
else:
print("Not Palindrome")

enter the string:python


Not Palindrome

msg=input("enter the string:")


print(msg[::-1])
if(msg==msg[::-1]):
print("Palindrome")
else:
print("Not Palindrome")

enter the string:python


nohtyp
Not Palindrome

# i=1
# do{
# print(i)
# i=i+1
# }while(i<=5);
i=1
while(True):
print(i)
i=i+1
if(i>5):
break

1
2
3
4
5

def sum(x,y):
print("Sum is:",x+y)

def mul(x,y):
return(x*y)

def div(x,y):
p=x//y
return(p)

def power(x,y):
return (x**y)

x=int(input('enter the 1st number:'))


y=int(input('enter the 2nd number:'))
sum(x,y)
m=mul(x,y)
print("Multiplication is:",m)
d=div(x,y)
print("division is:",d)
print("power is:",power(x,y))

enter the 1st number:10


enter the 2nd number:2
Sum is: 12
Multiplication is: 20
division is: 5
power is: 100

You might also like