Python Practicals 5CS3
Python Practicals 5CS3
/REMARKS
1. Write a Program to Find the Area of a Circle 25.09.24
OUTPUT−
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
Practical:3 Write a Program to show operation on List
Output:
OUTPUT:
('abcd', 786, 2.23, 'john', 70.2)
abcd
(786, 2.23)
(2.23, 'john', 70.2)
(123, 'john', 123, 'john')
('abcd', 786, 2.23, 'john', 70.2, 123, 'john')
Practical:5 Write a Program to find maximum of three numbers
OUTPUT:
num1 = 10
num2 = 25
num3 = 7
import math
OUTPUT:
Enter the first number: 56
Enter the second number: 98
The GCD of 56 and 98 is: 14
Practical 7: To write a Python program to find the exponentiation of a number.
# Calculating exponentiation
result = base ** exponent
def weekday(n):
match n:
case 0: return "Monday"
case 1: return "Tuesday"
case 2: return "Wednesday"
case 3: return "Thursday"
case 4: return "Friday"
case 5: return "Saturday"
case 6: return "Sunday"
case _: return "Invalid day number"
print (weekday(3))
print (weekday(6))
print (weekday(7))
OUTPUT:
Thursday
Sunday
Invalid day number
Practical 9:To write a Python program to all prime numbers
OUTPUT:
Enter the upper limit to find prime numbers: 20
Prime numbers up to 20 are:
2 3 5 7 11 13 17 19
Practical 10: Write a Python program to find factorial of number using user defined function
# Function to calculate factorial of a number
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
OUTPUT:
Enter a number to find its factorial: 5
The factorial of 5 is: 120