Python Practise Part 01
Python Codesss
*********LIST***************************
bikes = ['trek', 'redline', 'giant']
fst_bike=bikes[0]
lst_bike=bikes[-1]
Loops K Leye
for bike in bikes:
print(bike)
bikes = []
bikes.append('treak')
bikes.append('Pek')
bikes.append('Mek')
print(bikes)
squares = []
for x in range(1,11):
squares.append(x**2)
print(squares)
squares = [x**2 for x in range(1,11)]
print(squares)
finishers = ['trek', 'redline', 'giant','cat']
fst_two =finishers[1:2]
print(fst_two)
*******************Tuple***************
dim = (100,200)
print(dim)
*****************DICTIONARY*****************
alien = {'color':'green', 'points':5}
print('the alien ' + alien['color'])
for num in range(1,1001):
print(num)
fin = ['kai','bai','mai','sai','pai']
f3 = fin[-3:]
print(f3)
squares = ['kai','bai','mai','sai','pai']
upper=[]
for x in squares:
upper.append(x.lower())
print(upper)
upper=[x.upper() for x in squares]
Date = 07/09/2024
7.wap to read a string from user and print each character in both forward and
reverse direction.
str = input("Enter ")
c=0
while c<len(str):
print(str[c], end=', ')
c+=1
print()
r = len(str)-1
while r>=0:
print(str[r], end=", ")
r-=1
8. write a program to print all the vowels present inside a given string.
str = input("Enter Any alphbet ")
c=0
while c<len(str):
if str[c] in "aeiouAEIOU":
print(str[c], end=', ')
c+=1
9. wap to display all positions of substrings in a given main string.
s = input()
sub_s = input()
p = -1
n = len(s)
while len(s) > p:
p = s.find(sub_s,p+1,n)
if p == -1:
break
print(p)
wap to display all positions of substrings in a given main string
str2=input()
l=str2.split()
str3=""
c=len(l)-1
while 0<=c:
str3+=l[c]+" "
c-=1
print(str3)
own TRied
str=input()
l=str.split()
str2=""
c=len(l)-1
while c>=0:
str2+=l[c] + " "
c-=1
print(str2)
11. wap to print all the consonants from the given string.
x = input("Enter as Ur Wish ")
c=0
while c<len(x):
if x[c] not in "AEIOUaeiou1234567890":
print(x[c], end=" ")
c+=1
12. wap to print sum of digits from the given string.
x = input("Enter str with sum ")
c=0
a=0
while c <= len(x)-1:
if x[c] in "123456790":
a=a+int(x[c])
c+=1
print(a)
str1 = input()
c = 0
sum = 0
while c <= len(str1)-1:
if str1[c] in "0123456789":
sum = sum + int(str1[c])
c += 1
print(sum)
13. wap to iterate over a string and print each character twice
13. wap to iterate over a string and print each character twice
x = input()
c=0
while c<len(x):
z = x[c], x[c]
print(z)
c+=1
Traverse
num = [2,4,6,3,6,8,9,4,2,4]
name = ["tor","iron","bat","spder"]
i=0
while i < len(name):
print(name[i])
i+=1
OR
c=0
while c< len(num):
print(num[c])
c+=1
Tuple
num = (2,4,6,3,6,8,9,4,2,4)
x=4
i=0 #initialization
while i<len(num):
if (num[i] == x):
print("Hence Found at ",i)
else:
print("Finding...")
i+=1
i=1
while i<=5:
print(i)
if (i==3):
break
i+=1
i=0
while i<=10:
if (i %2!= 0):
i+=1
continue #skip
print(i)
i+=1
8. write a program to print all the vowels present inside a given string.
str = input("string ")
i=0
while i<len(str):
if str[i] in "aeiouAEIOU":
print(str[i], end=" ")
i+=1
14. wap to reverse internal content of each word.
print("enter the sentences")
str = input()
str1=str.split()
str2=""
c=0
while c<len(str1):
str2=str2+str1[c][::-1]+" "
c+=1
print(str2)
print("enter value of n")
n=int(input())
sum=0
c=0
while c<=n:
sum+=c
c+=1
print(sum)
wap to achieve given output.
i/p : "one two three four five six seven"
o/p : "one owt three ruof five xis seven"
str=input()
c=0
str1=str.split()
str2=""
while c<(len(str1)):
if c%2==0:
str2=str2+str1[c]+" "
else:
str2=str2+str1[c][::-1]+" "
c+=1
print(str2)
#Samaj me nahi aya
19. wap to enter name,%,and marks of the n number of students in
dictionary and print information on the screen.
num = int(input())
c = 0
print("-----name-----,-----percentage-----,-----marks-----")
while c <= num:
name = input()
per = float(input())
marks = float(input())
print(f"-----{name}-----,-----{per}-----,-----{marks}-----")
c += 1
Comments
Post a Comment