# 1.Program to obtain three numbers and print their sum.
a= int(input("enter the no="))
b=int(input("enter the no="))
c=int(input("enter the no="))
d=a+b+c
print(d)
#2.Program to obtain length and breadth of a rectangle and calculate its area.
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
area = length * breadth
print("The area of the rectangle is=" area)
#3.Program to get selling price and GST rate and print invoice with CGST and SGST
selling_price = float(input("Enter the selling price (SP): "))
gst_rate = float(input("Enter the GST rate (in percentage): "))
cgst = (gst_rate / 2) * selling_price / 100
sgst = cgst
total_price = selling_price + cgst + sgst
print("\nInvoice:")
print("selling price is= ",selling_price)
print("cgst is equal to",cgst)
print("sgst is equal to",sgst)
print("Total Price (including CGST and SGST):",total_price)
#4. Program to calculate profit percentage from the sales of goods
cost_price = float(input("Enter the cost price (CP) of the goods: "))
selling_price = float(input("Enter the selling price (SP) of the goods: "))
profit = selling_price - cost_price
profit_percentage = (profit / cost_price) * 100
print("The profit percentage is ",profit_percentage)
#5. Program to display output of following coding.
A,B,C,D = 9.2,2.0,4,21
print(A/4)
print(A//4)
print(B**C)
print(D//B)
print(A%C)
#6. Program to display given code.
i=2 #integer
fl=4 #integer
db=5.0 #floating point number
fd=36.0 #floating point number
A=(ch+i)/db #expression 1
B=fd/db*ch/2 #expression 2
print(A)
print(B)
#7.Program to display given code.
a=5
b = -3
c = 25
d = -10
a+b+c>a+c-b*d
str(a + b + c > a + c - b * d)=='true'
len(str(a + b + c > a + c - b * d))==len(str(bool(1)))
# 8.Program to display given code.
a = 3 + 5/8
b = int(3 + 5/8)
c = 3 + float(5/8)
d = 3 + float(5)/8
e = 3 + 5.0/8
f = int(3 + 5/8.0)
print(a,b,c,d,e,f)
#9. Program to calculate average investment cost per share.
total_investment = float(input("Enter the total investment amount: $"))
total_shares = float(input("Enter the total number of shares: "))
average_cost = total_investment / total_shares
print("The average investment cost per share is",average_cost)
# 10.Program to display given code.
PV = 100000
r = 5/100 #5% means 5/100
n = 12
FV = PV * (1+r)**n
print("Present Value : ",PV)
print("Rate of Interest :",(r*100), "%per month")
print("Numbers of periods :", n)
print("Future Value :", FV)
#11. Program to check if the first number is divisible by the second number
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
if num1 % num2 == 0:
print("{num1} is divisible by {num2}.")
else:
print("{num1} is not divisible by {num2}.")
#12.Program to check whether the number is odd or even
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is an EVEN number.")
else:
print(f"{num} is an ODD number.")
#13. Program to find the largest of three integers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
if num1 >= num2 and num1 >= num3:
print("The largest number is”, num1)
elif num2 >= num1 and num2 >= num3:
print("The largest number is “,num2)
else:
print("The largest number is”, num3})
# 14.Program to calculate two sums from three numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
sum1 = num1 + num2
sum2 = num2 + num3
print("The sum of the first and second numbers is",sum1)
print("The sum of the second and third numbers is",sum2)
# 15.Program to calculate the amount payable after sales discount and sales tax
sales_amount = float(input("Enter the sales amount: "))
if sales_amount <= 20000:
discount = 0.10 * sales_amount
else:
discount = 0.175 * sales_amount
discounted_price = sales_amount - discount
sales_tax_rate = float(input("Enter the sales tax rate (5-12%): "))
if 5 <= sales_tax_rate <= 12:
sales_tax = (sales_tax_rate / 100) * discounted_price
total_amount = discounted_price + sales_tax
print("The amount payable after discount and sales tax is",total_amount)
else:
print("Invalid sales tax rate. Please enter a value between 5% and 12%.")
#16. Program to print an invoice for the sale of "Amul Butter 100 gms"
item_name = "Amul Butter 100 gms"
quantity = 4
price_per_item = 45
tax_rate = 0.05
subtotal = quantity * price_per_item
tax = subtotal * tax_rate
total = subtotal + tax
print("Invoice")
print("-" * 30)
print("Item:",item_name)
print("Quantity:",quantity)
print("Price per item: Rs.",price_per_item)
print("Subtotal: Rs.",subtotal)
print("Tax (5%): Rs.", tax)
print("Total: Rs.",total)
#17. Program to calculate Simple Interest or Compound Interest
def calculate_simple_interest(P, R, T):
SI = (P * R * T) / 100
return SI
def calculate_compound_interest(P, R, T, n):
A = P * (1 + R / (n * 100)) ** (n * T)
return A
print("Menu:")
print("1. Calculate Simple Interest")
print("2. Calculate Compound Interest")
choice = int(input("Enter your choice (1 or 2): "))
if choice == 1:
P = float(input("Enter the Principal amount (P): "))
R = float(input("Enter the Annual Interest Rate (R%) : "))
T = float(input("Enter the Time (T in years): "))
SI = calculate_simple_interest(P, R, T)
print(f"Simple Interest: Rs. {SI:.2f}")
elif choice == 2:
P = float(input("Enter the Principal amount (P): "))
R = float(input("Enter the Annual Interest Rate (R%) : "))
T = float(input("Enter the Time (T in years): "))
n = int(input("Enter the Number of Times Interest is Compounded per Year (n): "))
A = calculate_compound_interest(P, R, T, n)
CI = A - P
print(f"Compound Interest: Rs. {CI:.2f}")
print(f"Total Amount (A): Rs. {A:.2f}")
else:
print("Invalid choice! Please select either 1 or 2.")
# 18.Program that reads two numbers and an arithmetic operator and displays the computed results.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operator = input("Enter an arithmetic operator (+, -, *, /): ")
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
if num2 != 0:
result = num1 / num2
else:
result = "Error: Division by zero"
else:
result = "Invalid operator"
print("Result:”,result)
# 19.Program to read three numbers and print them in ascending order
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
numbers = [num1, num2, num3]
numbers.sort()
print("Numbers in ascending order:", numbers)
#20. Program to calculate total selling price after levying GST
item_code = input("Enter the item code: ")
selling_price = float(input("Enter the original selling price (SP): "))
cgst_rate = float(input("Enter the Central GST rate (CGST in %): "))
sgst_rate = float(input("Enter the State GST rate (SGST in %): "))
cgst = (selling_price * cgst_rate) / 100
sgst = (selling_price * sgst_rate) / 100
total_gst = cgst + sgst
total_selling_price = selling_price + total_gst
print("\nInvoice:")
print("Item Code:",item_code)
print("Original Selling Price (SP): Rs.",selling_price)
print("Central GST (CGST): Rs.",cgst)
print("State GST (SGST): Rs.",sgst)
print("Total GST: Rs.",total_gst)
print("Total Selling Price (Including GST): Rs.",total_selling_price)
# 21.Program to print table of a number, say 5
num = 5
for a in range(1, 11):
print(num, '*', a, '=', num * a)
#22. Program to print sum of natural numbers between 1 to 7 . Print the sum progressively, i.e.,after adding each
natural numbers , print sum so far.
total_sum = 0
for number in range(1, 8):
total_sum += number
print("After adding", number, "the sum so far is:", total_sum)
#23.Program to calculate the sum of natural numbers from 1 to 7
total_sum = 0
for number in range(1, 8):
total_sum += number
print("The sum of natural numbers from 1 to 7 is:", total_sum)
#24.Program to calculate the average sales made per transaction
total_transactions = 0
total_items_sold = 0
for day in range(1, 8):
print("Day", day)
transactions = int(input("Enter the number of transactions made: "))
items_sold = int(input("Enter the number of items sold: "))
total_transactions += transactions
total_items_sold += items_sold
if total_transactions > 0:
average_sales = total_items_sold / total_transactions
print("The average sales made per transaction is:", round(average_sales, 2))
else:
print("No transactions were made during the week.")
#25. Program to illustrate the difference between break and continue
print("Illustration of 'break':")
for i in range(1, 6):
if i == 4:
print("Encountered 4, breaking the loop.")
break
print("Value:", i)
print("\nIllustration of 'continue':")
for i in range(1, 6):
if i == 4:
print("Encountered 4, skipping this iteration.")
continue
print("Value:", i)
#26.Program to input numbers repeatedly and print their sum
total_sum = 0
while True:
number = int(input("Enter a number (negative number to abort): "))
if number < 0:
print("Negative number entered. Aborting the program.")
break
total_sum += number
choice = input("Do you want to enter more numbers? (yes/no): ").strip().lower()
if choice == "no":
break
print("The total sum of entered numbers is:", total_sum)
#27. Program to check if the given string is a palindrome
input_string = input("Enter a string: ")
cleaned_string = input_string.replace(" ", "").lower()
if cleaned_string == cleaned_string[::-1]:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
#28. Program to find the longest substring of consonants
def is_consonant(c):
if c.isalpha() and c.lower() not in "aeiou":
return True
return False
input_string = input("Enter a string: ")
longest_substr = ""
current_substr = ""
for char in input_string:
if is_consonant(char):
current_substr += char
else:
if len(current_substr) > len(longest_substr):
longest_substr = current_substr
current_substr = ""
if len(current_substr) > len(longest_substr):
longest_substr = current_substr
print("The longest substring of consonants is:", longest_substr)
# 29.Program to capitalize every other letter in a string
def capitalize_alternate(input_string):
result = ""
for i in range(len(input_string)):
if i % 2 == 0:
result += input_string[i].lower()
else:
result += input_string[i].upper()
return result
if __name__ == "__main__":
input_string = input("Enter a string: ")
result_string = capitalize_alternate(input_string)
print("Resulting String:", result_string) '''
#30. Program to validate email domain
def validate_email(email):
if email.endswith('@edupillar.com'):
return True
else:
return False
if __name__ == "__main__":
email = input("Enter your email ID: ")
if validate_email(email):
print("The email ID belongs to the domain @edupillar.com.")
else:
print("Invalid email. The email must belong ”)