Cs File
Cs File
Cs File
py
# Trigonometric functions
angle = math.radians(45)
print("Sine of 45 degrees:", math.sin(angle))
print("Cosine of 45 degrees:", math.cos(angle))
print("Tangent of 45 degrees:", math.tan(angle))
# Logarithmic functions
print("Logarithm of 2 to the base 10:", math.log10(2))
print("Natural logarithm of 2:", math.log(2))
# Other functions
print("Square root of 25:", math.sqrt(25))
print("Factorial of 5:", math.factorial(5))
def random_module_demo():
print('Random Integer:', random.randint(1, 100))
print('Random Float:', random.random())
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)
print('Shuffled List:', numbers)
print('Random Choice:', random.choice(numbers))
random_module_demo()
# TASK 12: WAPP to input annual income of a person and calculate the payable income tax based
income = int(input('Enter annual income: '))
if income <= 250000:
tax = 0
elif 250000 < income <= 500000:
tax = 0.05 * (income - 250000)
elif 500000 < income <= 1000000:
tax = 0.05 * (500000 - 250000) + 0.1 * (income - 500000)
else:
tax = 0.05 * (500000 - 250000) + 0.1 * (1000000 - 500000) + 0.2 * (income - 1000000)
print('Payable Income Tax:',tax)
# TASK 13: WAPP to input eclectic consumption (present reading – previous reading) of a house
f=int(input("Enter the Number of bills you want to calculate:"))
while f>0:
f=f-1
n=int(input("input present reading:"))
k=int(input("input previous reading:"))
b=(n-k)
a=0
c=0
if b<0:
print("ERROR please check the units entered no of units entered are",b)
elif b<=200:
print ("bill is 0")
elif b>200 and b<=400:
c=b-200
print ("Your bill amount is:",600+ (c*4.5))
elif b>400 and b<=800:
c=b-600
print ("Your bill amount is:",600+900+(c*6.5))
elif b>800 and b<=1200:
c=b-800
print ("Your bill amount is:",600+900+2600+ (c*7))
else:
c=b-1200
print ("Your bill amount is:",600+900+2600+ (c*7.75))
Output: Enter the Number of bills you want to calculate:input present reading:
Python Code: Program_1_14.py
# TASK 14: WAPP to input two natural numbers and display all the EVEN numbers between those.
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
for num in range(num1, num2 + 1):
if num % 2 == 0:
print(num)
# TASK 15: WAPP to input a natural number and display the MULTIPLICATION TABLE of that
n = int(input('Enter a number: '))
for i in range(1, 11):
print(n * i)
# TASK 16: WAPP to input a natural number N and display first N FIBONACCI numbers.
term = int(input('Enter the number of terms: '))
a, b = 0, 1
for _ in range(term):
print(a, end=' ')
a, b = b, a + b
# TASK 18: WAPP to input a natural number and display the SUM OF all its proper FACTORS.
number = int(input('Enter a number: '))
total = 0
for i in range(1, number):
if number % i == 0:
total += i
print('Sum of Factors:', total)
# TASK 19: WAPP to input a natural number and check whether the number is a PERFECT or not.
number = int(input('Enter a number: '))
total=0
for i in range(1, number):
if number % i == 0:
total += i
if number==total:
print("It Is a perfect no")
else:
print("IT IS NOT")
# TASK 20: WAPP to input two natural numbers and check whether those numbers are AMICABLE
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
total1=0
total2=0
for i in range(1, num1):
if num1 % i == 0:
total1 += i
for i in range(1, num2):
if num2 % i == 0:
total2 += i
if total1 == num2 and total2 == num1:
print("nos are amicable")
else:
print("they are not amicable")
# TASK 21: WAPP to input a natural number and check whether the number is a PRIME or not.
num = int(input('Enter a number: '))
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime and num > 1:
print('Prime')
else:
print('Not Prime')
# TASK 22: WAPP to input a natural number N and display the first N PRIME numbers.
N = int(input('Enter the value of N: '))
count = 0
num = 2
while count < N:
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=' ')
count += 1
num += 1
# TASK 23: WAPP to input a number N and display all PRIME numbers less than equals to N.
N = int(input('Enter the value of N: '))
for num in range(2, N + 1):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=' ')
# TASK 24: WAPP to input a natural number N and display the sum of all PRIME numbers less than equals
N = int(input('Enter the value of N: '))
prime_sum = 0
for num in range(2, N + 1):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
prime_sum += num
print('Sum of Prime Numbers:', prime_sum)
# TASK 25: WAPP to input two natural numbers and calculate and display their HCF/GCD
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
while num2:
num1, num2 = num2, num1 % num2
print('HCF/GCD:', num1)
# TASK 26: WAPP to input two natural numbers and check whether they are CO-PRIME or not.
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
hcf = 0
for i in range(1, min(num1, num2) + 1):
if num1 % i == 0 and num2 % i == 0:
hcf = i
if hcf == 1:
print('Co-Prime')
else:
print('Not Co-Prime')
# TASK 27: WAPP to input two natural numbers and calculate and display their LCM
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
hcf = 0
for i in range(1, min(num1, num2) + 1):
if num1 % i == 0 and num2 % i == 0:
hcf = i
lcm = (num1 * num2) // hcf
print('LCM:', lcm)
# TASK 28: WAPP to input a natural number and display the SUM OF all its DIGITS.
number = int(input('Enter a number: '))
digit_sum = sum(map(int, str(number)))
print('Sum of Digits:', digit_sum)
# TASK 29: WAPP to input a natural number and check whether the number is a ARMSTRONG number or not.
number = int(input('Enter a number: '))
order = len(str(number))
armstrong_sum = sum(int(digit) ** order for digit in str(number))
if armstrong_sum == number:
print('Armstrong Number')
else:
print('Not Armstrong Number')
# TASK 30: WAPP to input a natural numbers and display the same but after REVERSING its digits.
number = int(input('Enter a number: '))
reverse_number = int(str(number)[::-1])
print('Original Number:', number)
print('Reversed Number:', reverse_number)
# TASK 31: WAPP to input a natural numbers and check whether the number is PALINDROMIC or not.
number = input('Enter a number: ')
if number == number[::-1]:
print('PALINDROMIC')
else:
print('NOT PALINDROMIC')
# TASK 32: WAPP to input an amount of money and display MINIMUM CURRENCY NOTES (out of 2000/500/200/1
amount = int(input('Enter the amount: '))
notes = [2000, 500, 200, 100, 50, 20, 10, 5, 2, 1]
for note in notes:
count = amount // note
if count > 0:
print(f'{count} x {note} notes')
amount %= note
# TASK 33: WAPP to input a natural numbers and check whether the number is PALINDROMIC or not.
number = input('Enter a number: ')
if number == number[::-1]:
print('PALINDROMIC')
else:
print('NOT PALINDROMIC')
# TASK 34: WAPP to read a sentence and display the number of occurrences of each characters.
sentence = input('Enter a sentence: ')
character_count = {}
for char in sentence:
character_count[char] = character_count.get(char, 0) + 1
for char, count in character_count.items():
print(f'{char}: {count} times')
# TASK 35: WAPP to read a sentence and display the number of occurrences of each words.
sentence = input('Enter a sentence: ')
word_count = {}
words = sentence.split()
for word in words:
word_count[word] = word_count.get(word, 0) + 1
for word, count in word_count.items():
print(f'{word}: {count} times')
# TASK 36: WAPP to input a natural numbers and display the same but after REVERSING its digits.
number = input('Enter a number: ')
reversed_number = int(number[::-1])
print('Reversed Number:', reversed_number)
# TASK 37-A: WAPP to read a sentence and display the same by reversing characters of all words withou
sentence = input('Enter a sentence: ')
reversed_sentence = ' '.join(word[::-1] for word in sentence.split())
print('Reversed Sentence:', reversed_sentence)
# TASK 38-A: WAPP to read 3 numbers and display those in ASCENDING/DESCENDING order.
numbers = [int(input('Enter first number: ')), int(input('Enter second number: ')), int(input('Enter
print('Ascending Order:', sorted(numbers))
print('Descending Order:', sorted(numbers, reverse=True))
# TASK 39: WAPP to input a natural number N and calculate & display the FACTORIAL of N.
n = int(input('Enter a natural number: '))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print('Factorial of', n, 'is:', factorial)
# TASK 40: WAPP to illustrate the difference between append() vs insert() methods and pop() vs remove
my_list = [1, 2, 3, 4, 5]
print('Original List:', my_list)
# Append vs Insert
my_list.append(6)
print('List after append(6):', my_list)
my_list.insert(2, 7)
print('List after insert(2, 7):', my_list)
# Pop vs Remove
my_list.pop(3)
print('List after pop(3):', my_list)
my_list.remove(7)
print('List after remove(7):', my_list)
# Append vs Insert
my_list = [1, 2, 3]
# Using append
my_list.append(4)
# Using insert
my_list.insert(1, 5)
my_numbers = []
while True:
print("1. Add Number")
print("2. Display Numbers")
print("3. Search Number")
print("4. Modify Number")
print("5. Delete Number")
print("6. Exit")
if choice == 1:
number = int(input("Enter a number: "))
my_numbers.append(number)
elif choice == 2:
print("Numbers:", my_numbers)
elif choice == 3:
search_num = int(input("Enter number to search: "))
print("Found" if search_num in my_numbers else "Not Found")
elif choice == 4:
old_num = int(input("Enter number to modify: "))
new_num = int(input("Enter new number: "))
if old_num in my_numbers:
index = my_numbers.index(old_num)
my_numbers[index] = new_num
else:
print("Number not found")
elif choice == 5:
del_num = int(input("Enter number to delete: "))
if del_num in my_numbers:
my_numbers.remove(del_num)
else:
print("Number not found")
elif choice == 6:
break
import statistics
mean = statistics.mean(numbers)
median = statistics.median(numbers)
mode = statistics.mode(numbers)
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
Output: Mean: 30
Output: Median: 30
Output: Mode: 10
Output:
Python Code: Program_1_44.py
stack = []
word = "INDIA"
Output: I
Output: IN
Output: IND
Output: INDI
Output: INDIA
Output:
Python Code: Program_1_47.py
# Extracting initials
initials = [char.upper() + "." for char in name.split()]
print("Initials:", "".join(initials))
# Extracting initials
initials = [char.upper() + "." for char in name.split()]
print("Initials:", "".join(initials))
def is_palindrome(s):
s = s.lower().replace(" ", "")
return s == s[::-1]
string_to_check = "level"
if is_palindrome(string_to_check):
print(f"{string_to_check} is a palindrome.")
else:
print(f"{string_to_check} is not a palindrome.")
if choice == 1:
side = float(input("Enter the side length of the square: "))
area = side ** 2
print("Area of the square:", area)
elif choice == 2:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print("Area of the rectangle:", area)
elif choice == 3:
radius = float(input("Enter the radius of the circle: "))
area = 3.14 * (radius ** 2)
print("Area of the circle:", area)
else:
print("Invalid choice. Please choose 1, 2, or 3.")
Output: 1. Square
Output: 2. Rectangle
Output: 3. Circle
Output: Enter your choice (1/2/3): Invalid choice. Please choose 1, 2, or 3.
Output:
Python Code: Program_1_50.py
if word_to_check in sentence:
print(f"The sentence contains the word '{word_to_check}'.")
else:
print(f"The sentence does not contain the word '{word_to_check}'.")
Output: Enter a word to check: The sentence does not contain the word 'RlHqMj'.
Output:
Python Code: Program_1_52.py
countries = ["India", "USA", "Canada", "Brazil", "China", "Germany", "France", "Australia", "Japan",
Output: Countries with 6 or more characters: ['Canada', 'Brazil', 'Germany', 'France', 'Australia']
Output:
Python Code: Program_1_53.py
names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Henry", "Ivy", "Jack"]
vowel_starting_names = [name for name in names if name[0].lower() in ['a', 'e', 'i', 'o', 'u']]
names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Henry", "Ivy", "Jack"]
consonant_ending_names = [name for name in names if name[-1].lower() not in ['a', 'e', 'i', 'o', 'u']
Output: Names ending with consonants: ['Bob', 'David', 'Frank', 'Henry', 'Ivy', 'Jack']
Output:
Python Code: Program_1_55.py
queue = []
my_tuple = (1, 2, 3)
students = [
("Alice", 90),
("Bob", 85),
("Charlie", 92)
]
Output: Students after push and pop: [('Alice', 90), ('Bob', 85), ('Charlie', 92)]
Output: Removed student: ('David', 88)
Output:
Python Code: Program_1_58.py
# Tuple length
length = len(my_tuple)
# Tuple sum
total = sum(my_tuple)
# Tuple maximum
maximum = max(my_tuple)
# Tuple minimum
minimum = min(my_tuple)
print("Length:", length)
print("Sum:", total)
print("Maximum:", maximum)
print("Minimum:", minimum)
Output: Length: 5
Output: Sum: 150
Output: Maximum: 50
Output: Minimum: 10
Output:
Python Code: Program_1_59.py
my_dict = {
"Alice": 90,
"Bob": 85,
"Charlie": 92
}
print("Keys:", keys)
print("Values:", values)
result_dict = {
"Alice": 95,
"Bob": 30,
"Charlie": 75,
"David": 40
}
marks_dict = {
"Alice": 90,
"Bob": 85,
"Charlie": 92,
"David": 88
}
numbers = [1, 2, 3, 2, 4, 1, 5, 2, 3, 5]
marks = [85, 92, 78, 95, 88, 72, 90, 92, 88, 85, 78, 95, 90, 92, 88]
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
print("Standard Deviation:", std_dev)
Output: Character Occurrences: {'l': 3, 'r': 1, 'w': 1, 'd': 1, ' ': 1, 'h': 1, 'e': 1, 'o': 2}
Output:
Python Code: Program_1_65.py
# GST Calculator
import random
if user_choice == computer_choice:
result = "It's a tie!"
elif (
(user_choice == "Stone" and computer_choice == "Scissors") or
(user_choice == "Paper" and computer_choice == "Stone") or
(user_choice == "Scissors" and computer_choice == "Paper")
):
result = "You win!"
else:
result = "You lose!"
print(result)
questions = [
["What is the capital of France?", "Paris"],
["Which planet is known as the Red Planet?", "Mars"],
["What is the largest mammal?", "Blue Whale"]
]
score = 0
Output: What is the capital of France? Wrong! The correct answer is Paris.
Output: Which planet is known as the Red Planet?
Python Code: Program_1_8.py
# String methods
print("Uppercase:", string.upper())
print("Lowercase:", string.lower())
print("Titlecase:", string.title())
print("Capitalized:", string.capitalize())
print("Length:", len(string))
print("Count 'l':", string.count('l'))
print("Replace 'World' with 'Python':", string.replace("World", "Python"))
print("StartsWith 'Hello':", string.startswith("Hello"))
print("EndsWith 'World!':", string.endswith("World!"))