Programs To Execute in Lab1
Programs To Execute in Lab1
1. Read a multi-digit number (as chars) from the console. Develop a program to
print the frequency of each digit with suitable message.
s = input("Enter a multidigit Number:")
dict = { }
for i in s:
if i in dict:
dict[i]=dict[i]+1
else:
dict[i]=1
print(dict)
2. Read N numbers from the console and create a list. Develop a program to print
mean, variance, and standard deviation with suitable messages.
import math
list = [ ]
n = int(input("Enter the Size of N (Limit):"))
print("Enter the elements of the List:")
for i in range(n):
list.append(int(input()))
sum = 0
for i in range(n):
sum = sum + list[i]
print("Sum is",sum)
mean = sum/n
sum1=0
for i in range(n):
sum1 = sum1+math.pow((list[i]-mean),2)
variance = sum1/n
sd = math.sqrt(variance)
print("Mean is", mean)
print("Variance is:", variance)
print("Standard deviation is:",sd)
match choice:
case 1:
# Area of Triangle
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print(f"Area of the triangle: {area}")
case 2:
# Area of Rectangle
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print(f"Area of the rectangle: {area}")
case 3:
# Area of Circle
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius ** 2
print(f"Area of the circle: {area}")
case 4:
print("Program Terminated Successfully:")
exit(0)
case _:
print("Invalid choice! Please enter 1, 2, 3 or 4.")
5. Develop a python program that reads first name and last name as arguments to
functions and display it on screen
def myfunc(fname,lname):
print("Hello Prof",fname,lname)
myfunc('Sudeep','J')
myfunc('Rajeshwari','D')
myfunc('Manasa','K.B')
6. Develop a python program using functions to find the sum and average of first
N natural Numbers
def calculate_sum(N):
return N * (N + 1) // 2
def calculate_average(N):
total_sum = calculate_sum(N)
return total_sum / N
n = int(input("Enter a Number"))
palindrome(n)
Assignment to do in lab