Python Till Lab3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

In [2]: name=input("Enter student's name: ")

usn=input("Enter student's USN: ")


marks1=float(input("Enter marks in Subject 1: "))
marks2=float(input("Enter marks in Subject 2: "))
marks3=float(input("Enter marks in Subject 3: "))
total_marks=marks1+marks2+marks3
percentage=(total_marks/300)*100
print("Student's details:")
print("Name:",name)
print("Marks in Subject 1:",marks1)
print("Marks in Subject 2:",marks2)
print("Marks in Subject 3:",marks3)
print("Total marks:",total_marks)
print("Percentage:",percentage,"%")

Enter student's name: VARSHA M K


Enter student's USN: 1AM22IS119
Enter marks in Subject 1: 89
Enter marks in Subject 2: 93
Enter marks in Subject 3: 98
Student's details:
Name: VARSHA M K
Marks in Subject 1: 89.0
Marks in Subject 2: 93.0
Marks in Subject 3: 98.0
Total marks: 280.0
Percentage: 93.33333333333333 %

In [1]: name=input("Enter a name: ")


year_of_birth=int(input("Year of birth: "))
age=2023-year_of_birth
print("Age:",age)
if age >= 60:
print(name,"is a senior citizen.")
else:
print(name,"is not a senior citizen.")

Enter a name: VARSHA M K


Year of birth: 2005
Age: 18
VARSHA M K is not a senior citizen.

In [1]: num=int(input("Enter a number "))


n1,n2=0,1
sum=0
if num<=0:
print("Please enter a number greater than zero")
else:
for i in range(0,num):
print(sum)
n1=n2
n2=sum
sum=n1+n2

Enter a number 5
0
1
1
2
3

In [6]: def factorial(n):


if n==0 or n==1:
return 1
else:
b=n*factorial(n-1)
return b
def binomial_coefficient(n,r):
if r>n:
return 0
else:
c=factorial(n)//factorial(r)*factorial(n-r)
return c
N=int(input("Enter the value of N: "))
R=int(input("Enter the value of R: "))
result=binomial_coefficient(N,R)
print("Binomial Coeffient of N and R is", result)

Enter the value of N: 34


Enter the value of R: 43
Binomial Coeffient of N and R is 0

In [1]: import math


N = int(input("Enter the number of elements: "))
numbers = []
for i in range(N):
num = float(input("Enter number " + str(i + 1) + ": "))
numbers.append(num)
print("List:", numbers)
mean = sum(numbers) / N
variance = sum((x - mean) ** 2 for x in numbers) / N
std_deviation = math.sqrt(variance)
print("Mean:", mean)
print("Variance:", variance)
print("Standard Deviation:", std_deviation)

Enter the number of elements: 3


Enter number 1: 45
Enter number 2: 5
Enter number 3: 69
List: [45.0, 5.0, 69.0]
Mean: 39.666666666666664
Variance: 696.888888888889
Standard Deviation: 26.398653164297777

In [ ]:

You might also like