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

Python Lab Work 4,8,9,10

Uploaded by

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

Python Lab Work 4,8,9,10

Uploaded by

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

Python Lab work

Anjika Rastogi
2024/848

Question 4

print(f"{'Height (in Feet)':<30} {'Height (in Inches)':<30}")


feet = 5.0
while feet <= 6.0:
inches = feet * 12
print(f"{feet:<30.1f} {inches:<.1f}")
feet += 0.1

Question 8

n = int(input("Enter the value of n: "))


def factorial(n):
if n == 0 or n == 1:
return 1
else:
factorial = 1
for i in range(2, n + 1):
factorial *= i
return factorial
def sum(n):
sum = 0
for i in range(1, n + 1):
each_value = 1 / factorial(i)
sum += each_value
print(f"1/{i}! = {each_value:}")

return sum
print("The series is:")
result = sum(n)
print("Sum of the series: ",result )
Question9

X=input("Enter your name: ")


print('Length of X =' , len(X))
print('Frequency of character a =' , X.count('a'))
if X.isupper():
print('The characters are in uppercase')

if X.islower():
print('The characters are in lowercase')
else:
print('The characters are combination of upper and lower case')

Question 10
even_l=[]
odd_l=[]
for i in range(1,21):
if i%2==0:
even_l.append(i)
else:
odd_l.append(i)
print(odd_l)
print(even_l)
print(odd_l+even_l)
print(odd_l*2)
print(3 in even_l)
print(even_l is odd_l)
del even_l[2]
even_l.clear()
print(odd_l.count(2))
l=[]
l=odd_l.copy()
odd_l.extend(l)
odd_l.pop(3)
odd_l.insert(1,5)
odd_l.remove(7)
odd_l.reverse()

You might also like