0% found this document useful (0 votes)
8 views5 pages

Lab Assignment-07

The document is a lab assignment containing various Python programming tasks. It includes programs demonstrating data types, arithmetic operations, list methods, string manipulation, conditional statements, finding the largest number, calculating factorial, simple interest, checking for perfect numbers, and calculating student grades. Each task is accompanied by code snippets and user input prompts.

Uploaded by

Harshit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Lab Assignment-07

The document is a lab assignment containing various Python programming tasks. It includes programs demonstrating data types, arithmetic operations, list methods, string manipulation, conditional statements, finding the largest number, calculating factorial, simple interest, checking for perfect numbers, and calculating student grades. Each task is accompanied by code snippets and user input prompts.

Uploaded by

Harshit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB ASSINGMENT-07

NAME: HARSHIT
ROLL NO: B-90(U23CS077)
1) Write a program to demonstrate different data types in python.

a=5

b=5.2
c='c'
d="cars"
e=True
list=[1,2
]
set={1,2}
distnary={1:1,2:
2} touple=(1,2)
print("data type of a
is",type(a)) print("data type
of b is",type(b))
print("data type of c
is",type(c))
print("data type of d is",type(d))
print("data type of e is",type(e))
print("data type of list
is",type(list)) print("data type of
set is",type(set))
print("data type of distnary
is",type(distnary)) print("data type of
touple is",type(touple))

2) Write a program to perform different arithmetic operations on numbers in python.

print("2+3=",2+3)
print("26-3=",26-3)
print("26/3=",26/3)
print("reminder(26/3)",26%3)
print("queotient(26/3)",26//
3)
3) Create a list and perform the following methods 1) insert() 2) remove() 3) append()

list=[1,2,3,4,5,6,7,8,9,10]
print("list=",lis
t) #insert
a=int(input("enter position at which you want to insert
num ")) b=int(input("enter what you want to insert "))
list.insert(a-1,b)
print("list=",lis
t) #remove
a=int(input(("enter the element which you want to remove
"))) list.remove(a)
print("list=",lis
t) #append
b=int(input("enter what u want to add at end
")) list.append(b)
print("list=",list)

4) len() 5) pop() 6) clear()

list=[1,2,3,4,5,6,7,8,9,10]
print("list=",lis
t) #len
print("length of list=
",len(list)) #pop
a=int(input(("enter the position
of element which you want to
remove ")))
list.pop(a-1)
print("list=",lis
t) #clear
list.clear()
print("list=",lis
t)
5) Write a program to create, concatenate and print a string
string="web programming"
print("string=",string)
a=input("enter string which you wnat to add at the
end ") string=string+a
print("string=",string)

6) Write a python program to add two numbers.

a=int(input("enter a num"))
b=int(input("enter another num"))
print("sum of two
num",a,"and",b,"=",a+b)

7) Write a python program to print a number is positive/negative using if-else.

a=int(input("enter a num"))
if a>0:
print("num is
+ve") elif a<0:
print("num is -
ve") else :
print("num is
neither +ve nor -
ve i.e, zero")
8) Write a python program to find largest of three numbers
a=int(input("enter a num 1: "))
b=int(input("enter a num 2:
")) c=int(input("enter a num
3: ")) if (a>b and a>c):
print(a," is the largest
num") elif (b>a and b>c):
print(b," is the
num") else :
print(c," is the
largest num")

9) Python program for factorial of a number

a=int(input("enter a num : "))


p=1
for i in
range(1,a+1,1):
p=p*i
print("factorial of
",a," is ",p)

10)Python program for simple interest

p=int(input("enter a principle : "))


t=int(input("enter a time : "))
r=int(input("enter a rate : "))
print("simple intrest =
",p*t*r/100)
11) Python program to check Perfect Number (Example: 6, divisors of 6 are 3,2,1 and sum of divisors is the
number itself)

a=int(input("enter a num"))
s=0
for i in
range(1,a,1):
if(a%i==0):
s+=i
if(a==s):
print(a," is a perfect
num") else :
print(a," is not a
perfect num")

12) Python program to calculate grade of a student. Take in the marks of 5 subjects and display the grade.
CODE:-
sum=0
for i in range(1,6,1):
a=int(input("enter marks of subject"))
sum+=a
print("grade(avg) of the student is
",sum/5)
OUTPUT:-

You might also like