0% found this document useful (0 votes)
5 views

Modified_CS_Practical

The document contains Python programs for Class 12, including a menu-driven arithmetic operations program, a Fibonacci series generator, and a program for calculating factorials and the sum of a list. Users can perform basic arithmetic operations, generate Fibonacci sequences, and compute factorials and sums through a simple menu interface. The programs utilize functions and handle user input for various calculations.

Uploaded by

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

Modified_CS_Practical

The document contains Python programs for Class 12, including a menu-driven arithmetic operations program, a Fibonacci series generator, and a program for calculating factorials and the sum of a list. Users can perform basic arithmetic operations, generate Fibonacci sequences, and compute factorials and sums through a simple menu interface. The programs utilize functions and handle user input for various calculations.

Uploaded by

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

Modified Python Practical Programs - Class 12

Menu-Driven Arithmetic Operations

def arithmetic_operations():
while True:
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")

choice = input("Enter choice: ")

if choice in ['1', '2', '3', '4']:


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':
print("Result:", num1 + num2)
elif choice == '2':
print("Result:", num1 - num2)
elif choice == '3':
print("Result:", num1 * num2)
elif choice == '4':
print("Result:", num1 / num2 if num2 != 0 else "Division by zero not
allowed")
elif choice == '5':
break
else:
print("Invalid choice, try again.")

arithmetic_operations()

Fibonacci Series

def fibonacci(n):
sequence = [0, 1]
for _ in range(n - 2):
sequence.append(sequence[-1] + sequence[-2])
return sequence[:n]

n = int(input("Enter number of terms: "))


print("Fibonacci Series:", fibonacci(n))

Factorial and Sum of List

import math
Modified Python Practical Programs - Class 12

def menu():
print("1. Calculate Factorial")
print("2. Sum of List")
print("3. Exit")

def factorial(n):
return math.factorial(n)

def sum_list(lst):
return sum(lst)

while True:
menu()
choice = input("Enter choice: ")

if choice == '1':
num = int(input("Enter number: "))
print("Factorial:", factorial(num))
elif choice == '2':
numbers = list(map(int, input("Enter numbers separated by space: ").split()))
print("Sum:", sum_list(numbers))
elif choice == '3':
break
else:
print("Invalid choice, try again.")

You might also like