0% found this document useful (0 votes)
2 views3 pages

Programs To Execute in Lab1

The document outlines a series of programming tasks to be executed in a lab setting from May 11, 2024, to September 11, 2024. It includes programs for reading multi-digit numbers, calculating statistical measures, finding areas of geometric shapes, and various other functions such as checking for palindromes and generating Fibonacci series. Additionally, it lists assignments that involve computing areas and performing arithmetic operations using functions.

Uploaded by

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

Programs To Execute in Lab1

The document outlines a series of programming tasks to be executed in a lab setting from May 11, 2024, to September 11, 2024. It includes programs for reading multi-digit numbers, calculating statistical measures, finding areas of geometric shapes, and various other functions such as checking for palindromes and generating Fibonacci series. Additionally, it lists assignments that involve computing areas and performing arithmetic operations using functions.

Uploaded by

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

Programs to execute in Lab 5/11/24 to 9/11/24

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)

3. Develop a menu driven program to find


a) Area of Triangle
b) Area of Rectangle
c) Area of Circle
Use match to demonstrate the above cases
import math
while True:
print("Choose the shape to calculate area:")
print("1. Triangle")
print("2. Rectangle")
print("3. Circle")
print("4. Exit")
choice = int(input("Enter your choice (1, 2, 3 or 4): "))

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.")

4. Develop a python program to print the multiplier of 5 using functions.


def fivemultiplier(x):
return 5*x
a=fivemultiplier(3)
b=fivemultiplier(5)
c=fivemultiplier(9)
print("Program to print Multiple of Five")
print(a)
print(b)
print(c)

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 the value of N: "))


total_sum = calculate_sum(N)
average = calculate_average(N)
print(f"The sum of the first {N} natural numbers is: {total_sum}")
print(f"The average of the first {N} natural numbers is: {average}")

7. Develop a python program using functions to check whether the number is


palindrome or not
def palindrome(num):
temp=num
rev=0
while num > 0:
rem = num%10
rev = rev*10+rem
num = num//10
if temp == rev:
print(f"The Number {rev} is a palindrome")
else:
print(f"Number {rev} is not a palindrome")

n = int(input("Enter a Number"))
palindrome(n)

Assignment to do in lab

8. Develop a python program to compute the area of triangle, area of rectangle,


area of square using functions
9. Develop a python program to find the sum,difference of two numbers using
functions
10. Develop a python program to generate N Fibonacci series using functions

You might also like