1.
write a python program to obtain the principal amount rate of interest and time from
the user and complete simple interest and compound interest
# Program to calculate Simple Interest and Compound Interest
#SIMPLE AND COMPOUND INTEREST
print("\t SIMPLE AND COMPOUND INTEREST")
print("\t********************************")
print("INPUT DATA")
# Get user inputs
print("------------\n")
P=int(input("enter the principal amount :"))
R=int(input("enter the rate of interest :"))
T=int(input("enter the time in years :"))
#simpleInterest
SI=(P*R*T)/100
#Compundintrest
CI=A-P
print("output DATA")
print("-----------")
print("simple interest :",SI)
print("compound interest is :",CI)
Result :
enter the principal amount :8
enter the rate of interest :8
enter the time in years :6
output :
-----------
simple interest : 3.84
compound interest is : 4.694994583552004
2. Write a python program to find and print the area of rectangle, triangle and circle
3. Write a python program to solve quadratic equation and display either one of the
three roots of the equation (using if…elif)
import cmath # For handling complex roots
# Input coefficients a, b, and c
a = float(input("Enter coefficient a (non-zero): "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
# Ensure it's a valid quadratic equation
if a == 0:
print("This is not a quadratic equation.")
else:
# Calculate the discriminant
discriminant = b**2 - 4*a*c
# Check the nature of the roots
if discriminant > 0:
# Real and distinct roots
root1 = (-b + [Link](discriminant)) / (2 * a)
print(f"The equation has real and distinct roots. One root is: {[Link]}")
elif discriminant == 0:
# Real and equal roots
root = -b / (2 * a)
print(f"The equation has real and equal roots. The root is: {root}")
else:
# Complex roots
root1 = (-b + [Link](discriminant)) / (2 * a)
print(f"The equation has complex roots. One root is: {root1}")
Output:
Enter coefficient a (non-zero): 1
Enter coefficient b: 2
Enter coefficient c: 1
The equation has real and equal roots. The root is: -1.0
4. Write a python program to accept a list of integers and print number of 3 digit
numbers and reverse all integers
# Accept a list of integers from the user
numbers = list(map(int, input("Enter a list of integers separated by spaces: ").split()))
# Count the number of three-digit numbers
three_digit_count = sum(100 <= abs(num) <= 999 for num in numbers)
# Reverse all integers in the list
reversed_numbers = [int(str(abs(num))[::-1]) * (-1 if num < 0 else 1) for num in
numbers]
# Print the results
print(f"Number of three-digit numbers: {three_digit_count}")
print(f"Reversed integers: {reversed_numbers}")
Output:
Enter a list of integers separated by spaces: 123 356 605
Number of three-digit numbers: 3
Reversed integers: [321, 653, 506]
5. Find the sum of series
i) X – X2/ 3! + X3/ 5! – +- Xn/n!
ii) 12 +(12+32) +(12+32+52) + ….(1+….n2)
i)
x = int(input("Enter a term = "))
n = int(input("Enter the Number = "))
fact = 1
sum = 0
for i in range(1,n):
fact = fact * i
if i % 3 == 0 :
sum = sum - (x**i)/fact
else :
sum = sum + (x**i)/fact
print("Sum of series = ",sum)
Output:
Enter a term = 5
Enter the Number = 3
Sum of series = 17.5
6. Armstrong number or not using while loop
# Input from the user
number = int(input("Enter a number: "))
# Initialize variables
original_number = number
sum_of_powers = 0
# Find the number of digits
num_digits = len(str(number))
# Check Armstrong number using while loop
while number > 0:
digit = number % 10 # Extract the last digit
sum_of_powers += digit ** num_digits # Add the power of the digit
number //= 10 # Remove the last digit
# Check if the sum of powers equals the original number
if sum_of_powers == original_number:
print(f"{original_number} is an Armstrong number.")
else:
print(f"{original_number} is not an Armstrong number.")
Output :
Enter a number: 153
153 is an Armstrong number.
7. Write a python programming to accept a line of text from user and print the
following
i) Number of lowercase vowels
ii) Number of special characters
iii) Number of digits
iv) Number of uppercase alphabets
# Accept a line of text from the user
user_input = input("Enter a line of text: ")
# Initialize empty lists for each category
lowercase = []
uppercase = []
digits = []
special_characters = []
# Categorize each character in the input
for char in user_input:
if [Link]():
[Link](char)
elif [Link]():
[Link](char)
elif [Link]():
[Link](char)
else:
special_characters.append(char)
# Print the categorized characters
print("Lowercase letters:", ''.join(lowercase))
print("Uppercase letters:", ''.join(uppercase))
print("Digits:", ''.join(digits))
print("Special characters:", ''.join(special_characters))
Output:
Enter a line of text: 4g # H a
Lowercase letters: ga
Uppercase letters: H
Digits: 4
Special characters: #
8. Write a python program to accept a string and find the following
i) Those words starts with upper case vowel
ii) 4 letter words
iii) Occurrences of given letter in each word
def analyze_string(input_string, given_letter):
# Split the string into words
words = input_string.split()
# i) Words starting with an uppercase vowel
uppercase_vowel_words = [word for word in words if word[0] in 'AEIOU']
# ii) Four-letter words
four_letter_words = [word for word in words if len(word) == 4]
# iii) Occurrences of the given letter in each word
letter_occurrences = {word: [Link]().count(given_letter.lower()) for word in words}
# Display results
print("Words starting with an uppercase vowel:", uppercase_vowel_words)
print("Four-letter words:", four_letter_words)
print(f"Occurrences of '{given_letter}' in each word:", letter_occurrences)
# Input from the user
input_string = input("Enter a string: ")
given_letter = input("Enter a letter to count occurrences: ")
# Call the function
analyze_string(input_string, given_letter)
Output:
Enter a string: A pattient Accept a pain
Enter a letter to count occurrences: t
Words starting with an uppercase vowel: ['A', 'Accept']
Four-letter words: ['pain']
Occurrences of 't' in each word: {'A': 0, 'pattient': 3, 'Accept': 1, 'a': 0, 'pain': 0}