0% found this document useful (0 votes)
51 views20 pages

Program No

The document contains 7 Python programs to perform various calculations and tasks. Program 1 calculates employee salary. Program 2 calculates momentum of an object. Program 3 finds max, min, sum and average of input numbers. Program 4 builds a basic calculator. Program 5 reverses digits of a number. Program 6 converts a binary number to decimal. Program 7 generates random numbers.

Uploaded by

soham pawar
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)
51 views20 pages

Program No

The document contains 7 Python programs to perform various calculations and tasks. Program 1 calculates employee salary. Program 2 calculates momentum of an object. Program 3 finds max, min, sum and average of input numbers. Program 4 builds a basic calculator. Program 5 reverses digits of a number. Program 6 converts a binary number to decimal. Program 7 generates random numbers.

Uploaded by

soham pawar
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

PROGRAM NO : 01

1)To calculate salary of an employee given his basic pay


(take as input from user). Calculate gross salary of
employee. Let HRA be 10 % of basic pay and TA be 5% of

basic pay. Let employee pay professional tax as


2% of total salary. Calculate net salary payable after
deductions.

basic_pay = input("Enter your basic pay: ")


basic_pay = float(basic_pay)
if basic_pay<0:

print("Basic pay can't be negative.")


hra = basic_pay*0.1

ta = basic_pay*0.05
total_salary = basic_pay + hra + ta
professional_tax = total_salary*0.02

salary_payable = total_salary - professional_tax


print("Salary Payable is",salary_payable)
OUTPUT :
PROGRAM NO 02
2). To accept an object mass in kilograms and velocity in
meters per second and display its

momentum. Momentum is calculated as e=mc2 where m is


the mass of the object and c is its velocity.

mass = float(input("Enter mass in kgs: "))

velocity = float(input("Enter velocity in m/s: "))

momentum = mass*(velocity**2)
print('Momentum of object is', momentum)
OUTPUT :
PROGRAM NO : 04
4).To simulate simple calculator that performs basic tasks
such as,
addition,
subtraction,
multiplication and division.

def add(x, y):


return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
def main():
while(1):
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
choice = input("Enter choice(1/2/3/4):")
try:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
except:
print("Enter numbers as integers")
continue
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':


print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
if __name__ == '__main__':
main()

OUTPUT :
PROGRAM 05
5).To accept a number from user and print digits of
number in a reverse order using built-in function.

Number = int(input("Please Enter any Number: "))


Reverse = 0
while(Number > 0):
Reminder = Number %10
Reverse = (Reverse *10) + Reminder
Number = Number //10

print("\n Reverse of entered number is = %d"


%Reverse)
OUTPUT :
PROGRAM NO : 06

6).To input binary number from user and convert it into


decimal number

def binaryToDecimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
print(decimal)
if __name__ == '__main__':
binaryToDecimal(100)
binaryToDecimal(101)
binaryToDecimal(1001)

OUTPUT :
PROGRAM NO : 07
To generate pseudo random numbers.

import random
try:
start = int(input("Enter start point: "))
end = int(input("Enter end point: "))
num = random.randint(start,end)
print(num)
except:
print("Enter start and end point as integer")
OUTPUT :
PROGRAM NO : 03
3).To accept N numbers from user. Compute and display
maximum in list, minimum in list,
sum and average of numbers using built-in function.

try:
n = int(input("Enter no of elements: "))
nos_list = [] # nos_list list is created
for i in range(n):
num = int(input("Enter no: "))
nos_list.append(num)
maxNo = max(nos_list)
minNo = min(nos_list)
sumNos = sum(nos_list)
average = sumNos/len(nos_list)
print('Max no is ',maxNo)
print('Min no is ',minNo)
print('Count: ',len(nos_list))
print('Sum of nos is ',sumNos)
print('Average of nos is ',average)
except ValueError:
print('Enter n and all elements as integer.')

OUTPUT :

You might also like