Full course of c++ programming language
Click here > C++ programming language
1. Write a program to display an average of 3 inputted numbers.
a=int(input("Enter a : "))
b=int(input("Enter a : "))
c=int(input("Enter a : "))
avg=(a+b+c)/3
print(avg)
======================================
2. Write a program to calculate simple interest for a given principle amount, rate of
interest and no of years.
p=float(input("Enter a P : "))
r=float(input("Enter a R : "))
n=float(input("Enter a N : "))
si=(p*r*n)/100
print("simple interest is ",si)
======================================
3. Write a program to display area of triangle.
base=float(input("Enter a base : "))
height=float(input("Enter a height : "))
area=base*height/2
print("Area of triangle is ",area)
======================================
4. Write a program to calculate area of circle.
r=float(input("Enter a radious : "))
area=3.14*r*r
print("Area of circle is ",area)
======================================
5. Write a program to calculate area of rectangle.
length=float(input("Enter a length : "))
width=float(input("Enter a width : "))
area=length*width
print("Area of circle is ",area)
======================================
6. Write a program to check whether inputted no is positive or negative.
a=int(input("Enter a : "))
if a>0:
print("Positive")
elif a==0:
print("zero")
else:
print("Negative")
======================================
7. Write a Python program to check whether a number is divisible by 5 and 11 or not.
a=int(input("Enter a : "))
if a%5==0 and a%11==0:
print("Divisible")
else:
print("not divisible")
======================================
8. Write a program to check whether given no is odd or even?
a=int(input("Enter a : "))
if a%2==0:
print("even")
else:
print("odd")
======================================
9. Write a program to display Yth power of X.
x=float(input("Enter a x : "))
y=float(input("Enter a y : "))
result=x**y
print(result)
====================================
10.Write a python function that converts inches to centimetres.
def inch_to_cm(inch):
cm=inch*2.54
return cm
inch=float(input("Enter a inch : "))
centimetres=inch_to_cm(inch)
print(centimetres)
======================================
11.Write a python function to check given inputted year is leap year or not.
def leap():
if a%4==0:
print("leap year")
else:
print("not ")
a=int(input("Enter a : "))
leap()
===================================
14.Write a python function to display minimum number from three given numbers.
def min():
if a<b and a<c:
print("a is min")
elif b<c:
print("b is min")
else:
print("c is min")
a=int(input("enter a : "))
b=int(input("enter b : "))
c=int(input("enter c : "))
min()
======================================
15.Write a python function to display maximum number from three given numbers.
def max():
if a>b and a>c:
print("a is max")
elif b>c:
print("b is max")
else:
print("c is max")
a=int(input("enter a : "))
b=int(input("enter b : "))
c=int(input("enter c : "))
max()
======================================
16.Write a program to display reverse number. E.g. I/P =>1234 O/P => 4321
a=int(input("enter a : "))
rev=0
while a>0 :
r=a%10
rev=rev*10+r
a//=10
print(rev)
======================================
17.Write a program to check whether the entered alphabet is vowel or consonant.
vowel=['a','e','i','o','u','A','E','I','O','U']
n=input("enter a word :")
char=str
for char in n:
if char in vowel:
print(char,':vowel')
else:
print(char,'constants')
======================================
18.Write a program to print first 10 natural numbers and its sum and average.
sum=0
for i in range(0,11):
sum+=i
print(i)
avg=sum/10
print(sum)
print(avg)
======================================
19.Write a Program to count the Number of Digits. E.g. I/P =>1234 O/P => 4
n=int(input("Enter a n : "))
i=0
while n>0:
n//=10
i+=1
print(i)
======================================
20.Write a program to print factorial of n using while loop.
n=int(input("Enter a n : "))
ans=1
i=1
while i<=n:
ans=ans*i
i+=1
print(ans)
======================================
21.Write a python function to calculate the sum of digits of the entered number.
n=int(input("Enter a n : "))
ans=0
while n>0:
r=n%10
ans=ans+r
n//=10
print(ans)
======================================
22.Write a program to check whether the number is palindrome or not.
str=input("Enter a string : ")
str1=str
str2=str[::-1]
if str1==str2:
print("palindrome")
else:
print("not")
def pal(str):
return str==str[::-1]
str=input("Enter a string : ")
if pal(str):
print("palindrome")
else:
print("not")
======================================
23.Write a python function to check whether the entered number is Prime or not.
def prime():
c=1
for i in range(1,n):
if n%i==0:
c+=1
if c==2:
print('prime')
else:
print("not")
n=int(input("enter n : "))
prime()
======================================
24.Write a program to Fibonacci series of n numbers using while loop.
n=int(input("Enter n : "))
a,b=0,1
i=0
while(i!=n):
print(a)
c=a+b
a=b
b=c
i+=1
n=int(input("Enter n : "))
a,b=0,1
for i in range(0,n):
print(a)
c=a+b
a=b
b=c
======================================
25.Write a python function to check whether the entered number is Armstrong or not.
def arm(n):
c=n
arm=0
while(n>0):
r=n%10
arm=arm+(r*r*r)
n//=10
if c==arm:
return 1
else:
return 0
n=int(input("Enter a n : "))
a=arm(n)
if a==1:
print("Armstrong")
else:
print("not")
======================================
26.Write a program to count characters in the entered string.
str=input("Enter a string :")
a=len(str)
print(a)
str=input("Enter a string : ")
i=0
for char in str:
if char=='':
continue
else:
i+=1
print("the length is",i)
======================================
27.Write a program to create choice based menu for calculator operations. (if…elif)
print("1.addition")
print("2.subtraction")
print("3.Divison")
print("4.Multiplecation")
n=int(input("Enter a choice : "))
a=float(input("Enter first number : "))
b=float(input("Enter second number : "))
if n==1:
res=a+b
sy='+'
elif n==2:
res=a-b
sy='-'
elif n==3:
res=a/b
sy='/'
elif n==4:
res=a*b
sy='x'
else:
print("invalid choice !!")
print(a,sy,b,'=',res)
==================================
28.Write a program to input cost price and selling price of a product and check profit or
loss. Also calculate total profit or loss using if else.
HINT: If cost price is greater than selling price then there is a loss otherwise profit.
Formula to calculate profit and loss
Profit = S.P - C.P (Where S.P is Selling Price and C.P is Cost Price)
Loss = C.P - S.P
cp=int(input("Enter cost price : "))
sp=int(input("Enter selling price : "))
if cp>sp:
print("there is a loss")
loss=cp-sp
print("The loss is ",loss)
elif cp<sp:
print("There is a profit")
pro=sp-cp
print("the profit is ",pro)
else:
print("no loss no profit")
======================================
30.Write a program to generate mark sheet of Student and display appropriate result as
follows:Percentage Result
>=70 Distinction
>=60 First Class
>=50 Second Class
>=35 Pass Class
<35 Fail
sub1 = float(input("Enter marks for subject 1: "))
sub2 = float(input("Enter marks for subject 2: "))
sub3 = float(input("Enter marks for subject 3: "))
sub4 = float(input("Enter marks for subject 4: "))
sub5 = float(input("Enter marks for subject 5: "))
total_marks = sub1 + sub2 + sub3 + sub4 + sub5
percentage = (total_marks / 500) * 100
print("------------MARK SHEET------------")
print("Subject 1: ", sub1)
print("Subject 2: ", sub2)
print("Subject 3: ", sub3)
print("Subject 4: ", sub4)
print("Subject 5: ", sub5)
print("Total marks obtained: ", total_marks)
print("Percentage: ", percentage)
if percentage >= 70:
print("Result: Distinction")
elif percentage >= 60:
print("Result: First Class")
elif percentage >= 50:
print("Result: Second Class")
elif percentage >= 35:
print("Result: Pass Class")
else:
print("Result: Fail")
======================================
31.Write a Python program to find maximum between two numbers.
a=int(input("enter a : "))
b=int(input("enter b : "))
if a>b:
print("a is max")
else:
print("b is max")
======================================
32.Write a Python program to find maximum between three numbers.
a=int(input("enter a : "))
b=int(input("enter b : "))
c=int(input("enter c : "))
if a>b and a>c:
print("a is max")
elif b>c:
print("b is max")
else:
print("c is max")
======================================
33.Write a Python program to check whether a character is alphabet or not.
n=input("Enter n:")
if n>='A' and n<='Z':
print("char")
elif n>='a' and n<='z':
print("char")
else:
print("not")
n=input("Enter n:")
if n.isalpha():
print("char")
else:
print("not")
======================================
34.Write a Python program to input any character and check whether it is alphabet, digit
or special character.
n=input("Enter n:")
if n>='A' and n<='Z':
print("char")
elif n>='a' and n<='z':
print("char")
elif n>='0' and n<='9':
print("Digit")
else:
print("special char")
n=input("Enter n:")
if n.isalpha():
print("char")
elif n.isdigit():
print("digit")
else:
print("symbol")
======================================
35.Write a Python program to check whether a character is uppercase or lowercase
alphabet.
n=input("Enter n:")
if n>='A' and n<='Z':
print("upper case")
elif n>='a' and n<='z':
print("lower case")
n=input("Enter n:")
if n.isupper():
print("upper case")
else:
print("lower case")
====================================
36.Write a Python program to input week number and print week day.
n=int(input("Enter n:"))
if n==1:
print("sunday")
elif n==2:
print("monday")
elif n==3:
print("tuesday")
elif n==4:
print("wednesday")
elif n==5:
print("thursday")
elif n==6:
print("friday")
elif n==7:
print("saturday")
else:
print("invalid")
======================================
37.Write a Python program to input month number and print number of days in that
month.
n=int(input("Enter a month number : "))
if n==2:
y=int(input("Enter the year : "))
if (y%4==0):
print("This month has 29 days")
else:
print("This month has 28 days")
else:
if n is (4,6,9,11):
print("This month has 30 days")
else:
print("This month has 31 days")
======================================
38.Write a Python program to count total number of notes in given amount.
amount=int(input("Enter amount : "))
a=0
b=0
c=0
d=0
e=0
f=0
g=0
h=0
i=0
j=0
amo=amount
while amount>0:
if amount>=2000:
amount=amount-2000
a+=1
elif amount>=500:
amount=amount-500
b=b+1
elif amount>=200:
amount=amount-200
c=c+1
elif amount>=100:
amount=amount-100
d=d+1
elif amount>=50:
amount=amount-50
e=e+1
elif amount>=20:
amount=amount-20
f=f+1
elif amount>=10:
amount=amount-10
g=g+1
elif amount>=5:
amount=amount-5
h=h+1
elif amount>=2:
amount=amount-2
i=i+1
elif amount>=1:
amount=amount-1
j=j+1
else:
print("invalid")
print("\n2000 : \t",a)
print("500 : \t",b)
print("200 : \t",c)
print("100 : \t",d)
print("50 : \t",e)
print("20 : \t",f)
print("10 : \t",g)
print("5 : \t",h)
print("2 : \t",i)
print("1 : \t",j)
print("\nTotal : \t",amo)
======================================
39.Write a Python program to input angles of a triangle and check whether triangle is
valid or not.
angle1=int(input("Enter a angle 1 : "))
angle2=int(input("Enter a angle 2 : "))
angle3=int(input("Enter a angle 3 : "))
if angle1+angle2+angle3==180:
print("valid")
else:
print("not")
======================================
40.Write a Python program to input all sides of a triangle and check whether triangle is
valid or not.
a=int(input("Enter a side a : "))
b=int(input("Enter a side b : "))
c=int(input("Enter a side c : "))
if (a+b>=c) and (a+c>=b) and (b+c>=a):
print("valid")
else:
print("not")
======================================
41.Write a Python program to check whether the triangle is equilateral, isosceles or
scalene triangle.
a=int(input("Enter a side a : "))
b=int(input("Enter a side b : "))
c=int(input("Enter a side c : "))
if a==b==c:
print("eqilateral")
elif a==b or a==c or b==c:
print("isoscelses")
else:
print("scalene")
======================================
43.Write a Python program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
physics = float(input("Enter marks in Physics: "))
chemistry = float(input("Enter marks in Chemistry: "))
biology = float(input("Enter marks in Biology: "))
mathematics = float(input("Enter marks in Mathematics: "))
computer = float(input("Enter marks in Computer: "))
percentage = (physics + chemistry + biology + mathematics + computer) / 5
if percentage >= 90:
grade = 'A'
elif percentage >= 80:
grade = 'B'
elif percentage >= 70:
grade = 'C'
elif percentage >= 60:
grade = 'D'
elif percentage >= 40:
grade = 'E'
else:
grade = 'F'
print("Percentage is",percentage)
print("Grade is",grade)
======================================
44.Write a Python program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
basic_salary = float(input("Enter the basic salary: "))
if basic_salary <= 10000:
hra = 0.2 * basic_salary
da = 0.8 * basic_salary
elif basic_salary <= 20000:
hra = 0.25 * basic_salary
da = 0.9 * basic_salary
else:
hra = 0.3 * basic_salary
da = 0.95 * basic_salary
gross_salary = basic_salary + hra + da
print("Gross salary is Rs.",gross_salary)
======================================
45.Write a Python program to input electricity unit charges and calculate total electricity
bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
unit = int(input("Enter the electricity unit charges: "))
if unit <= 50:
bill = unit * 0.50
elif unit <= 150:
bill = 25 + (unit - 50) * 0.75
elif unit <= 250:
bill = 100 + (unit - 150) * 1.20
else:
bill = 220 + (unit - 250) * 1.50
bill = bill + (bill * 0.20)
print(f"Total electricity bill is Rs.",bill)
======================================
46.Write a Python program to get choice from the user for the currency conversion. For
example, we have taken four currencies those are Rupee, Dollar, Pound and Euro.
Following are the Choices:
[1] Rupee Conversion
[2] Dollar Conversion
[3] Pound Conversion
[4] Euro Conversion
print("Which currency conversion would you like to perform?")
print("[1] Rupee Conversion")
print("[2] Dollar Conversion")
print("[3] Pound Conversion")
print("[4] Euro Conversion")
choice = int(input("Enter your choice (1-4): "))
conversion_rates = {
"Rupee": 1.0,
"Dollar": 0.013,
"Pound": 0.009,
"Euro": 0.011
}
if choice == 1:
print("You chose Rupee Conversion")
currency = "Rupee"
elif choice == 2:
print("You chose Dollar Conversion")
currency = "Dollar"
elif choice == 3:
print("You chose Pound Conversion")
currency = "Pound"
elif choice == 4:
print("You chose Euro Conversion")
currency = "Euro"
else:
print("Invalid choice. Please enter a number between 1 and 4.")
exit()
amount = float(input(f"Enter the amount in {currency}: "))
converted_amount = amount * conversion_rates[currency]
print(f"{amount} {currency} is equal to {converted_amount} Rupees.")
====================================
Comments
Post a Comment