PYTHONPDF.pdf.pdf
PYTHONPDF.pdf.pdf
while True:
current_date = datetime.now()
print(formatted_date)
(Q.4) WAP to Create, append & remove list in Python
Answer:-
Main program
if choice == '1':
else:
print("Invalid choice. Please choose a valid
option.")
Run the main program if name == "main":
main()
(Q.5) wap to demonstrate working ith tuple ?
answer :-
Answers:-
Choose an operation:
Choose an operation:
Choose an operation:
new value for the key: Bob Updated: name -> Bob
Choose an operation:
Choose an operation:
4. Display dictionary
5. Exit Enter choice (1/2/3/4/5): 4 Current dictionary: {}
Choose an operation:
fahrenheit =
float(input("Enter temperature in Fahrenheit: "))
fahrenheit_to_celsius(fahrenheit)
Roman numeral
for i in range(len(val)):
# Determine how many times the Roman symbol fits
into the number
while num >= val[i]:
roman_numeral += syb[i]
num -= val[i]
return roman_numeral
Main program
print_numbers_less_than_20()
output:- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(Q.11)wap to find factorial of a number using recursion
Answer:-
Main program def main(): # Taking input from the user number =
int(input("Enter a number
find its factorial: "))
# Finding the factorial using the recursive function result
= factorial(number)
# Displaying the result
print(f"The factorial of {number} is {result}.")
is_right_triangle(a, b,
=c) : # Sort the sides to ensure the largest is treated as the hypotenuse sides
sorted([a, b, c])
# Check if the sum of squares of the two smaller sides
equals the square of the largest side
if sides[0]**2 + sides[1]**2 == sides[2]**2:
return True
else:
return False
Main program
def main(): # Accept the lengths of the three sides of the triangle a =
float(input("Enter the length of side a: ")) b = float(input("Enter the length of
side b: ")) c = float(input("Enter the length of side c: "))
output: - Enter the length of side a: 3 Enter the length of side b: 4 Enter the
length of side c: 5 The triangle is a right triangle.
Enter the length of side a: 6 Enter the length of side b: 8 Enter the length of
side c: 10 The triangle is a right triangle.
Enter the length of side a: 2 Enter the length of side b: 3 Enter the length of
side c: 4 The triangle is not a right triangle.
(Q.13) wap to define a module to find fibonacci number and
import the module to another program?
Answer :-
import fibonacci_module
Main program to take user input and find the Fibonacci number
def main(): # Accepting the value of n from the user n = int(input("Enter the
position to find the Fibonacci number: "))
# Calling the fibonacci function from the fibonacci_module
result = fibonacci_module.fibonacci(n)
# Displaying the result
print(f"The {n}th Fibonacci number is: {result}")
(Q.14)*
**
***
****
*****
******
*******
********
*********
**********
Answer:- Function to print a right triangle pattern of asterisks def