0% found this document useful (0 votes)
39 views14 pages

Python Programs for Basic Calculations

The document contains a series of Python programs that demonstrate various programming concepts such as input/output, arithmetic operations, conditional statements, loops, and functions. Each program addresses a specific task, such as calculating the sum of two numbers, checking for even/odd numbers, and finding the area of geometric shapes. The examples serve as practical exercises for learning Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views14 pages

Python Programs for Basic Calculations

The document contains a series of Python programs that demonstrate various programming concepts such as input/output, arithmetic operations, conditional statements, loops, and functions. Each program addresses a specific task, such as calculating the sum of two numbers, checking for even/odd numbers, and finding the area of geometric shapes. The examples serve as practical exercises for learning Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

#WAPP to display the welcome message

print("Welcome to Python programming ")

2. #wap to calculate any two number accepted by you during run time

a=int(input("enter the first number:"))

b=int(input("enter the second number:"))

sum=a+b

print("sum of",a,"and ",b,"is ",sum)

3. age=int(input(" ENTER YOUR AUTHENTICATED AGE "))

if age<13:

print(" YOUR NOT ELIGIBLE TO USE INSTAGRAM SO FOF")

else:

print("CONGRATS YOU HAVE CREATED AN ACCOUNT ")

4. num1 = int(input('Enter your first number: '))

num2 = int(input('Enter your second number: '))

def compute_lcm(x, y):

# choose the greater number

if x > y:

greater = x

else:

greater = y

while(True):

if((greater % x == 0) and (greater % y == 0)):

lcm = greater

break

greater += 1
return lcm

print("The L.C.M. is", compute_lcm(num1, num2))

5#Wapp to calculate the Body Mass Index(BMI)

weight_in_kg=float(input("ENTER WEIGHT IN KG"))

height_in_meter=float(input("ENETR HEIGHT IN METERS"))

bmi=weight_in_kg/(height_in_meter*height_in_meter)

print("BMI is:",bmi)

6. a=float(input("ENTER THE LENGHT OF THE RECTRIANGLE: "))

b=float(input("ENTER THE BREADTH OF THE RECTANGLE: "))

area=a*b

print("area=",area)

7. #WAPP to calculate the Area of a triangle = (s*(s-a)*(s-b)*(s-c))-1/2

# Three sides of the triangle is a, b and c:

a=float(input('Enter first side: '))

b=float(input('Enter second side: '))

c=float(input('Enter third side: '))

s=(a+b+c)/2 #calculate the semi-perimeter

area=(s*(s-a)*(s-b)*(s-c))**0.5 #calculate the area

print('The area of the triangle is ',area)

8. #Python Program to Find the Area & perimeter of a Rectangle

a=int(input("Enter length of rectangle: "))

b=int(input("Enter breadth of rectangle: "))

Area=a*b

Peri=2*(a+b)

print("Area of the Reactangle is : ",Area)

print("Perimeter of the reactangle is :",Peri)


9. #Python Program to Find the Area & perimeter of a Square

a=int(input("Enter length of Square: "))

Area=a*a

Peri=4*a

print("Area of the Square is : ",Area)

print("Perimeter of the Square is :",Peri)

10. #Python Program to Convert Celsius to Fahrenheit

celsius=int(input("Enter the temperature in celcius:"))

f=(celsius*1.8)+32

print("Temperature in farenheit is:",f)

11. # import module

import calendar

yy = 2023

# display the calendar

print([Link](yy))

12. #Write a Python program to Calculate Compound Interest.

#CI = Principal Amount * ( 1 + ROI )** Number of years)

import math

princ_amount = float(input(" Please Enter the Principal Amount : "))

rate_of_int = float(input(" Please Enter the Rate Of Interest : "))

time_period = float(input(" Please Enter Time period in Years : "))

ci_future = princ_amount * ([Link]((1 + rate_of_int / 100), time_period))

compound_int = ci_future - princ_amount

print("Future Compound Interest for Principal Amount {0} = {1}".format(princ_amount, ci_future))

print("Compound Interest for Principal Amount {0} = {1}".format(princ_amount, compound_int))

13. #WAP to accept youe name and age and will display the message with appropriate value

name=input('Enter a name:')
age=int(input('Enter your age: '))

print('Welcome '+name)

print('you are ',age,'year old')

14.#WAPP to accept a car speed in Kilometer and convert into miles

kilometre=float(input ("Please enter the speed of car in Kilometre: "))

conv_ratio=0.621371

miles=kilometre*conv_ratio

print("The speed value of car in Miles: ",miles)

15. #WAP to calculate the KE PE and E total energy

m=int(input("Enter the Mass: "))

v=int(input("Enter the velocity: "))

g=float(input("Enter the gravity: "))

h=int(input("Enter the height: "))

ke=0.5*m*v**2

pe=m*g*h

e=ke+pe

print("Calculated Kenitic Energy: ",ke)

print("Calculated Potential Energy: ",pe)

print("Calculated total Energy: ",e)

16. list roll = [1,2,3,4,5]

list mark = [70,80,90,99,100]

marks=[1:4]

list roll=[:]

list roll[:2]

list mark[:2]

a=list roll+list mark

17 #Write a Program to find and display total no of uppercase and lowercase


#letters in a string.

s=input('Enter a string: ')

lowerCount=upperCount=0

for i in range(len(s)):

if s[i]>='a' and s[i]<='z':

lowerCount=lowerCount+1

if s[i]>='A' and s[i]<='Z':

upperCount=upperCount+1

print('Total uppercase letters in string=',upperCount)

print('Total lowercase letters in string=',lowerCount)

18 #WAPP to Display the Multiplication Table

number = int(input ("Enter the number of which the user wants to print the multiplication table: "))

print ("The Multiplication Table of: ", number)

for count in range(1, 11):

print (number, 'x', count, '=', number * count)

19 #Accept any three number and find out the largest among them.

a=int(input("ENTER THE FIRST NUMBERS"))

b=int(input("ENTER THE SECOND NUMBERS"))

c=int(input("ENTER THE THIRD NUMBERS"))

if(a>b):

if(a>c):

print(a,"IS LARGER THAN",b,c)

else:

print(c,"IS LARGER THAN",a,c)

else:

if(b>c):

print(b,"IS LARGER THAN",a,B)

else:

print(c,"IS LARGER THAN",a,b)


20 #WAP to accept a number and check whether it is +ve , -Ve or Zero Nested if condition

num=int(input('Entered any number'))

if num>=0:

if num==0:

print('Zero is entered')

else:

print('+Ve Number is entered')

else:

print('-Ve numbered entered')

21 # Python program to convert given number of days to years, months and days,

number_of_days = int(input("Enter number of days: "))

years = number_of_days // 365

months = (number_of_days - years *365) // 30

days = (number_of_days - years * 365 - months*30)

print("Years = ", years)

print("Months = ", months)

print("Days = ", days)

22 #Python Program to Check if a Number is a Palindrome

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

num=n

rev=0

while(n>0):

rem=n%10

rev=rev*10+rem

n=n//10

if(num==rev):

print("The number is a palindrome!")

else:

print("The number isn't a palindrome!")


23#WAP to calculate the quadertic equation

import cmath

a=1

b=5

c=6

d = (b**2) - (4*a*c)

sol1 = (-[Link](d))/(2*a)

sol2 = (-b+[Link](d))/(2*a)

print('The solution are {0} and {1}'.format(sol1,sol2))

24. #Python Program to Check If Two Numbers are Amicable Numbers or Not n1=220 n2=284

x=int(input('Enter number 1: '))

y=int(input('Enter number 2: '))

sum1=0

sum2=0

for i in range(1,x):

if x%i==0:

sum1+=i

for j in range(1,y):

if y%j==0:

sum2+=j

if(sum1==y and sum2==x):

print('Amicable!')

else:

print('Not Amicable!')

25#WAP to check whether the given number is armstrong or not without using power function

n=int(input("Enter a number : "))

num=n

b=len(str(n))

sum=0
while n!=0:

rem=n%10

sum=sum+(rem**b)

n=n//10

if num==sum:

print("The number ",num," is an armstrong number")

else:

print("The number ",num," is not an armstrong number")

26#WAP to demonstrate the jumping statement in python

print("The number display 1 to 10 using looping")

for i in range(1,11):

print(i,end=" ")

print("\n\nThe number display some portion of the loop\

and then breaking the loop")

for j in range(1,11):

if(j==5):

print("\nthe loop is terminate abnormally")

break

print(j,end=" ")

print("\n\nThe number display skip some portion of the \n\

loop and then continue further the loop")

print("The loop is skip at 5 and then continue further")

for k in range(1,11):

if(k==5):

continue

print(k,end=" ")

27 #WAP to accept any number and check for even odd

num=int(input("ENTER THE NUMBER: "))

if num%2==0:

print(num,"IS EVEN NUMBER.")


else:

print(num,"IS ODD NUMBER.")

28# WAPP TO ACCPET A NUMBER AND FIND IF ITS POSITIVE AND NEGETIVE OR ZERO

a=int(input("ENTER THE NUMBER: "))

if(a>0)

print("Positive")

else

print("Negative")

29#Write a program to display total number consonants present in a string

str=input('Enter a string:')

c=0

for i in str:

if i>='a' and i<='z':

if i not in('a','e','i','o','u'):

c=c+1

print('No of consonants=',c)

timeformat = '{:02d}:{:02d}'.format(mins, secs)

print(timeformat, end='\r')

[Link](2)

time_sec -= 1

print("stop")

countdown(10)

30#WAP to accept your age and check whether you are belongs to which catogary.

age=int(input("ENTER YOUR AGE "))

if age<7:

print(" YOU ARE IN A KIDS GROUP")

elif age<16:
print(" YOU ARE IN A INTERMIDATE GROUP")

elif age>23:

print(" YOU ARE IN A COLLAGE GROUP")

elif age<60:

print(" YOU ARE IN A EMPLOY GROUP")

else:

age>60

print(" YOU ARE IN A SENIOR GROUP")

31#WAP to accept 5 subject marks and calculate the total average and grade

m1=int(input("Enter the Mark Subject 1 :"))

m2=int(input("Enter the Mark Subject 2 :"))

m3=int(input("Enter the Mark Subject 3 :"))

m4=int(input("Enter the Mark Subject 4 :"))

m5=int(input("Enter the Mark Subject 5 :"))

total=m1+m2+m3+m4+m5

per=total/5

print("Total :",total)

print("Percentage :",per)

if(per>=60):

print("First Division..")

elif(per>=50 and per<=59):

print("Second Division..")

elif(per>=40 and per<=49):

print("Third Division..")

else:

print("Fail..")

32# Python Program to Calculate Electricity Bill

units = int(input(" Please enter Number of Units you Consumed : "))

if(units < 50):

amount=units*2.50
surcharge=25

elif(units<=100):

amount=130+((units-50)*3.25)

surcharge = 25

elif(units <= 200):

amount=130+162.50+((units-100)*5.25)

surcharge=25

else:

amount=130+162.50+526+((units-200)*8.25)

surcharge=25

total=amount+surcharge

print("\nElectricity Bill= %.2f" %total)

for i in range(1,21):

if(i%2==0):

print(i)

else:

print(i)

33#WAP to find out the Factorial of a number is product of all integers from 1 up to the number
( inclusive ).

#Factorial of 5 is 1*2*3*4*5 = 120

a=int(input("Enter a number : "))

fact=1

for i in range(1,a+1):

fact=fact*i

print("Factorial is : ", fact)

34#WAP to find Factors are numbers which divide the number [Link] of 12 are 1, 2, 3, 4, 6,
12#Factors ( of a number ) are numbers which when divide the number they leave 0 as reminder

n=int(input("Enter a number : "))

for i in range (1,n+1):


if(n%i==0):

print(i,end=', ')

35#WAPP to Print the Fibonacci sequence 0 1 1 2 3 5 8 13 ......n

nterms=int(input("How many terms the user wants to print? "))

n1=0

n2=1

c=0

print("The fibonacci sequence of the numbers is:")

print(n1)

print(n2)

while c<nterms-2:

sum=n1+n2

print(sum)

n1=n2

n2=sum

c+=1

r=int(input("Enter upper limit: "))

for a in range(2,r+1):

k=0

for i in range(2,a//2+1):

if(a%i==0):

k=k+1

if(k<=0):

print(a)

36#Python Program to Find the GCD of Two Numbers

import fractions

a=int(input("Enter the first number:"))

b=int(input("Enter the second number:"))


print("The GCD of the two numbers is",[Link](a,b))

37#Python Program to Calculate Grade of a Student

sub1=int(input("Enter marks of the first subject: "))

sub2=int(input("Enter marks of the second subject: "))

sub3=int(input("Enter marks of the third subject: "))

sub4=int(input("Enter marks of the fourth subject: "))

sub5=int(input("Enter marks of the fifth subject: "))

avg=(sub1+sub2+sub3+sub4+sub4)//5

if(avg>=90):

print("Grade: A")

elif(avg>=80 & avg<90):

print("Grade: B")

elif(avg>=70 & avg<80):

print("Grade: C")

elif(avg>=60 & avg<70):

print("Grade: D")

else:

print("Grade: F")

38#WAPP to accept 2 number findout the largest among them

a=int(input("Enter the first number: "))

b=int(input("Enter the Second number: "))

if a>b:

print(a,"is larger among them")

else:

print(b,"is larger among them")

39#WAPP to accept any three number and findout the largest among them

a=int(input("Enter the first number"))

b=int(input("Enter the Second number"))


c=int(input("Enter the Third number"))

if a>b:

if a>c:

print(a," is the largest number")

else:

print(c," is the largest number")

else:

if b>c:

print(b,"is largest number");

else:

print(c," is the largest number")

40#Python Program to Find the LCM of Two Numbers

a=int(input("Enter the first number:"))

b=int(input("Enter the second number:"))

if(a>b):

min1=a

else:

min1=b

while(1):

if(min1%a==0 and min1%b==0):

print("LCM is:",min1)

break

min1=min1+1

You might also like