Program
Program
P2: Write a program to enter marks in 5 subjects , calculate and display total
and average marks.
m1 = int(input("Enter first subject marks: "))
m2 = int(input("Enter second subject marks: "))
m3 = int(input("Enter third subject marks: "))
m4 = int(input("Enter fourth subject marks: "))
m5 = int(input("Enter fifth subject marks: "))
avg = (m1 + m2+ m3+ m4 + m5) / 5;
print("Average Marks =", avg)
OUTPUT
Enter first subject marks: 65
Enter second subject marks: 78
Enter third subject marks: 79
Enter fourth subject marks: 80
Enter fifth subject marks: 85
Average Marks = 77.4
Output
P4: write a program to calculate simple interest if the principle_amount=2000 rate_of_interest=8 time=10.
P=2000
T=10
R=8
SI=(P*T*R)/100
# input age
age = int(input("Enter Age : "))
Output
RUN 1:
Enter Age : 21
You are Eligible for Vote.
RUN 2:
Enter Age : 17
You are Not Eligible for Vote.
l2=[30,50,10]
l3=l1+l2
print("Addition of",l1,"and",l2,"is",l3)
o/p:
Addition of [20, 30, 40] and [30, 50, 10] is [20, 30, 40, 30, 50, 10]
P7: Write a program to calculate mean, median and mode using Numpy.
import numpy as np
import statistics as
st l=[30,20,50,60,20]
l1=np.array(l)
print("Mean of",l1,"is",st.mean(l1))
print("Median of",l1,"is",st.median(l1))
print("Mode of",l1,"is",st.mode(l1))
o/p:
x=(2,9)
y=(5,10)
plt.plot(x,y)
plt.title("Line chart")
plt.show()
x=[2,9,8,5,6]
y=[5,10,3,7,18]
plt.scatter(x,y)
plt.title("Line chart")
plt.show()
P 10: Write a program to display bar chart for the following data with appropriate titles:
Subjects=[“Eng”,”Sci”,”Soc”,”Maths”,”AI”]
Marks=[89,87,78,90,99] i
Sub=["Eng","Sci","Soc","Maths","AI"]
Marks=[89,87,78,90,99] plt.bar(Sub,Marks)
plt.title("Term-1 Performance")
plt.xlabel("Subjects")
plt.ylabel("Marks")
# Printing square
print(square)
Output:
49
P12: To find the sum, difference, multiplication and division of two number 15 and 20.
result = 0
if ch == '+':
result = num1 + num2
elif ch == '-':
result = num1 - num2
elif ch == '*':
result = num1 * num2
elif ch == '/':
result = num1 / num2
else:
print("Input character is not recognized!")
Sample Output:
P 14: Input a number and check if the number is positive, negative or zero and display an appropriate message.
Enter a number: 5
Positive number
*
* *
* * *
* * * *
* * * * *
def half_pyramid(n):
print("")
n = 5
half_pyramid(n)
Output:
* *
* * *
* * * *
* * * * *
print("\r")