0% found this document useful (0 votes)
43 views26 pages

Python Programs for Basic Calculations

The document contains a list of 20 programming exercises in Python, each focusing on different basic programming concepts such as arithmetic operations, data structures, and control flow. Each exercise includes an input prompt, the code to execute, and expected output. The exercises are designed to help learners practice and understand fundamental programming skills.

Uploaded by

fakeisour
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views26 pages

Python Programs for Basic Calculations

The document contains a list of 20 programming exercises in Python, each focusing on different basic programming concepts such as arithmetic operations, data structures, and control flow. Each exercise includes an input prompt, the code to execute, and expected output. The exercises are designed to help learners practice and understand fundamental programming skills.

Uploaded by

fakeisour
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INDEX.

1:-PROGRAM TO ENTER 2 NUMBERS AND PRINT THEIR SUM.


2:-PROGRAM THAT ACCEPT RADIUS OF CIRCLE AND PRINT IT’S AREA.

3:-PROGRAM THAT INPUT STUDENTS MARKS AND PRINT IT AVERAGE.


4:-PROGRAM TO CALCULATE SIMPLE INTEREST .
5:-PROGRAM TO GET QUOTIENT AND REMAINDER OF NUMBER.
6:-PROGRAM TO FIND WHEATHER A GIVEN NO. IS EVEN OR ODD.
7:-PROGRAM TO FIND LARGEST OF THREE NUMBERS.
8:- PROGRAM TO CALCULATE THE BMI ( BODY MASS INDEX) .
9:-PROGRAM TO CONVERT HEIGHT FROM CM TO FEET AND INCHES.
10:-PROGRAM TO FIND ELIGIBILITY CRITERIA OF AN INDIVIDUAL.
11:-PROGRAM THAT FIND WHETHER THE FIRST NO. IS FULLY DIVISIBLE
BY SECOND OR NOT.

12:-PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS


PALINDROME OR NOT.

13:-PROGRAM TO INPUT A STRING AND CHECK WHETHER IT


CONTAINS DIGITS OR NOT.
14:-PROGRAM TO INPUT A STRING AND PRINT THE UPPER AND LOWER
CASES LETTERS IN IT.

15:-PROGRAM TO FIND THE NUMBERS OF TIMES AN ELEMENT OCCUR


IN THE GIVEN LIST.

16:-PROGRAM TO CALCULATE THE MEAN OF THE GIVEN NUMBERS OF


THE LIST.

17:-PROGRAM TO CHECK IF ALL THE ELEMENTS OF THE TUPLES ARE IN


DESCENDING ORDER OR NOT.

18:- PROGRAM TO CHECK IF THE ELEMENTS IN THE FIRST HALF OF A


TUPLE ARE SORTED IN ASCENDING ORDER OR NOT.

19:-WRITE A PYTHON PROGRAM TO CREATE A DICTIONARY FROM A


STRING.

20:-PROGRAM TO INPUT THE SELECTED STUDENTS ROLL NUMBERS


AND CREATE A DICTIONARY FOR THE SAME.
1 .WRITE A PROGRAM TO ACCEPTS TWO INTEGERS AND PRINT THEIR
OUTPUT.

INPUT :-
a=int(input(‘Enter the first integer:’))

b=int(input(‘Enter the second integer:’))

Sum=a+b

print(‘The two integers are:’, a, b)

print(‘The sum of two integers are:’, Sum)

OUTPUT :-
[Link] A PROGRAM THAT ACCEPTS RADIUS OF A CIRCLE AND PRINTS
ITS AREA.

INPUT :-

r=int(input(‘Enter the radius of circle:’))


area=3.14*r**2
print(‘The area of the circle is:’, area)

OUTPUT :-
[Link] A PROGRAM THAT INPUTS A STUDENT’S MARKS IN THREE
SUBJECTS (OUT OF 100)AND PRINTS THE PERCENTAGE MARKS.

INPUT :-
print(‘Enter the marks of three subject out of 100’)

a=float(input(‘Enter the marks of first subject:’))

b=float(input(‘Enter the marks of second subject:’))

c=float(input(‘Enter the marks of third subject:’))

p=(a+b+c)/3

print(‘The percentage marks are:’, p,’%’)

OUTPUT :-
[Link] A PROGRAM TO CALCULATE SIMPLE INTEREST.
INPUT :-
P=float(input(‘Enter the principal amount :’))

R=float(input(‘Enter the rate of interest:’))

T=float(input(‘Enter the time in years:’ ))

SI=(P*R*T)/100

print(‘The simple interest is :’ , SI)

OUTPUT :-
[Link] A PROGRAM TO READ TWO NUMBERS AND PRINTS THEIR
QUOTIENT AND REMINDER.

INPUT :-
a=float(input(‘Enter the dividend:’))

b=float(input(‘Enter the divisor:’))

Q=a//b

R=a%b

print(‘The quotient is:’, Q)

print(‘The remainder is:’, R)

OUTPUT :-
[Link] A PROGRAM TO FIND WHETHER A GIVEN NUMBER IS EVEN OR
ODD.

INPUT :-

a=int(input(‘Enter the number:’))

if a%2==0:

print(‘The number is even’)

else:

print(‘The number is odd’)

OUTPUT :-
[Link] A PROGRAM TO FIND LARGEST AMONG THREE INTEGERS.
INPUT :-

a=int(input(‘Enter the first integer:’))

b=int(input(‘Enter the second integer:’))

c=int(input(‘Enter the third integer:’))

if a>b and a>c:

print(a, ‘is the largest integer’)

if b>a and b>c:

print(b, ‘is the largest integer’)

if c>a and c>b:

print(c, ‘is the largest integer’)

OUTPUT :-
[Link] A PROGRAM THAT ACCEPTS WEIGHT IN KG

AND HEIGHT IN METERS AND CALCULATE THE BMI.

INPUT :-

W= float(input(‘Enter the weight in Kg:’))

H = float(input(‘Enter height in meters:’))

BMI=W/(H**2)

print(‘BMI is:’, BMI)

OUTPUT :-
[Link] A PROGRAM TO ACCEPT THE HEIGHT IN CM AND CONVERT IT
INTO FEET AND INCHES.

INPUT :-

a=float(input(‘Enter your height in centimeters:’))

feet=a*0.032

inch=a*0.393
print(‘Your height in feet is:’, feet)
print(‘Your height in inch is:’, inch)

OUTPUT :-
[Link] A PROGRAM THAT ACCEPTS THE AGE AND PRINT IF ONE IS
ELIGIBLE TO VOTE OR NOT .

INPUT :-
a=int(input(‘Enter your age:’))

if a>=18:

print(‘You are eligible to vote’)

else:

print(‘You are not eligible to vote’)

OUTPUT :-
[Link] A PROGRAM THAT ACCEPTS TWO NUMBERS AND CHECK IF
THE FIRST NUMBER IS FULLY DIVISIBLE BY SECOND NUMBER OR NOT.

INPUT :-

a=float(input(‘Enter the first number:’))

b=float(input(‘Enter the second number:’))


if a%b==0:
print(‘The first number is fully divisible by second number’)
else:
print(‘The first number is not fully divisible by second number’)

OUTPUT :-
[Link] A PROGRAM TO CHECK IF A GIVEN NUMBER IS A
PALINDROME NUMBER OR NOT.

INPUT :-
n=int(input(“Enter number:”))

temp=n

rev=0

while(n>0):

dig=n%10

rev=rev*10+dig

n=n//10

if(temp==rev):

print(“The number is a palindrome!”)

else:

print(“The number isn’t a palindrome!”)

Output :-
[Link] A PROGRAM TO INPUT A STRING AND CHECK IF CONTAINS A
DIGIT OR NOT.

INPUT :-
strg = input(“Enter a string:”)

test = False

dig = “0123456789”

for ch in strg:

if ch in dig:

print(“The string contains a digit.a”)

test = True

break

if test == False:

print(“The string doesn’t contain a digit.”)


OUTPUT :-
[Link] A PROGRAM TO INPUT A STRING AND PRINT NUMBER OF
UPPER- AND LOWER-CASE LETTERS IN IT.

INPUT :-
str1 = input(“Enter a string:”)

ucase, lcase = 0,0

for ch in str1:

if ch >= ‘A’ and ch <= ‘Z’:

ucase += 1

if ch >= ‘a’ and ch <= ‘z’:

lcase += 1

print(“[Link] uppercase letters:”, ucase)

print(“[Link] lowercase letters:”, lcase)

OUTPUT :-
[Link] A PROGRAM TO FIND THE NUMBER OF TIMES AN
ELEMENT OCCURS IN THE LIST.

INPUT :-
val = eval(input(“Enter a list :”))

item = int(input(“Enter element:”))

print(item, “occurs in the list”, [Link](item), “times.”)

OUTPUT :-
[Link] TO CALCULATE THE MEAN OF A GIVEN LIST OF
NUMBERS.

INPUT :-
lst= eval(input(“Enter list:”))

length = len(lst)

mean = sum = 0

for i in range(0, length):

sum += lst[i]
mean = sum /length

print(“Given list is:”, lst)

print(“The mean of the given list is:”, mean)

OUTPUT :-
[Link] A PROGRAM TO CHECK IF ALL THE ELEMENTS OF A TUPLE ARE
IN DESCENDING ORDER OR NOT.

INPUT :-
tup = eval(input(“Enter a tuple:”))

if sorted(tup, reverse = True) == list(tup):

print(“Tuple is sorted in descending order.”)

else:

print(“Tuple is not sorted in descending order.”)

OUTPUT :-
[Link] A PROGRAM TO CHECK IF THE ELEMENTS IN THE FIRST HALF
OF A TUPLE ARE SORTED IN ASCENDING ORDER OR NOT.

INPUT :-
tup = eval(input(“Enter a tuple:”))

ln = len(tup)

mid = ln//2

if ln % 2 == 1:

mid = mid+1

half = tup[:mid]

if sorted(half) == list(tup[:mid]):

print(“First half is sorted”)

else:

print(“First half is not sorted”)

OUTPUT :-
[Link] A PYTHON PROGRAM TO CREATE A DICTIONARY FROM A
STRING.

INPUT :-
string = input(“Enter a string :”)

d1 = [Link] (list(string), 1)
print(“Given string :”, string)

print(“Dictionary created:”, d1)

OUTPUT :-
[Link] SCHOOL HAS DECIDED TO DEPOSIT SCHOLARSHIP
AMOUNT OF 2500/- TO SOME SELECTED STUDENTS. WRITE A

PROGRAM TO INPUT THE SELECTED STUDENTS’ ROLL NUMBERS AND

CREATE A DICTIONARY FOR THE SAME.

INPUT :-
L = []
n = int(input(“How many students?”))
for a in range(n):
r= int(input(“Enter Roll No.”))
[Link](r)
S= [Link] (L, 2500)
print(“Created dictionary”)
print(S) OUTPUT :-

You might also like