Lab Record Assignments
Lab Record Assignments
***
x=int(input('Enter 1st number '))
y=int(input('Enter 2nd number '))
op=input('Enter operation ')
if op=='+':
res=x+y
print(res)
elif op=='-':
res=x-y
print(res)
elif op=='*':
res=x*y
print(res)
elif op=='/':
res=x/y
print(res)
elif op=='//':
res=x//y
print(res)
elif op=='%':
res=x%y
print(res)
else:
print('operation invalid')
***
x=int(input('Enter length of rectangle '))
y=int(input('Enter breadth of rectangle '))
area=x*y
print(area)
***
***
x=int(input('enter a number '))
if x%2==0:
print('the number is even')
else:
print('the number is odd')
x=int(input('enter a number '))
s=0
while x!=0:
s+=x%10
x=x//10
print(s)
***
***
name=input('Please enter your name ')
age=input('Please enter your age ')
sci=int(input('Please enter the marks received in Science '))
mat=int(input('Please enter the marks received in Mathematics '))
eng=int(input('Please enter the marks received in English '))
total=(sci+mat+eng)
avg=(sci+mat+eng)/3
percentage=int(((sci+mat+eng)/300)*100)
print('\nStudent Name:',name)
print('Age:',age)
print('You have obtained',sci,'marks in Science,',mat,'marks in
Mathematics and',eng,'marks in English.')
print("The total marks you've obtained are",total,"out of 300")
print('Your average marks are',avg)
print('Your overall percentage is',percentage)
if percentage>=90:
print('Your overall grade is A+.')
elif percentage>=80:
print('Your overall grade is A.')
elif percentage>=70:
print('Your overall grade is B.')
elif percentage>=60:
print('Your overall grade is C.')
elif percentage>=50:
print('Your overall grade is D.')
else:
print('Your overall grade is E.')
***
***
x=int(input('enter a number '))
f=1
for i in range(1,x+1):
f=f*i
print('factorial is',f)
***
***
n=int(input('enter a natural number '))
s=0
for i in range(1,n+1):
s+=(i**2)
print('sum of squares of the first',n,'natural numbers is',s)
***
***
#1+x1/1!+x2/2!...xn/n!#
x=int(input('enter the variable in place of x '))
n=int(input('enter nth power '))
s=0
f=1
for a in range(1,n+1):
f=f*a
term=(x**a)/f
s+=term
print('the sum of',n,'terms of this sequence is',s+1)
***
***
n=int(input('enter a positive number '))
if n>1:
for a in range(2,n):
if n%a==0:
print('this is not a prime number')
break
else:
print('this is a prime number')
else:
print('this is not a prime number')
for a in range(3,10,2):
for b in range(1,a,2):
print(b,end='')
print()
***
***
#quadratic eqn#
import math
print('the form of the quadratic equation is: ax^2+bx+c')
a=int(input('enter a '))
b=int(input('enter b '))
c=int(input('enter c '))
dis=(b**2)-(4*a*c)
if a==0:
print('this is not a quadratic equation')
elif dis==0:
print('the roots are real and equal')
r1=(-b+math.sqrt(dis))/(2*a)
r2=(-b-math.sqrt(dis))/(2*a)
print('the roots are',r1,'and',r2)
elif dis<0:
print('the roots are complex')
elif dis>0:
print('the roots are real and unequal')
r1=(-b+math.sqrt(dis))/(2*a)
r2=(-b-math.sqrt(dis))/(2*a)
print('the roots are',r1,'and',r2)
***
***
n=int(input('enter the number of terms in the fibonacci sequence you
want '))
f=0
s=1
print(f)
print(s)
for i in range(1,n+1):
t=f+s
print(t)
f=s
s=t
***