Assignment No: 01 Salary Calculation
Assignment No: 01 Salary Calculation
'''
Assignment No: 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: ")
try:
basic_pay = float(basic_pay)
if basic_pay<0: # basic pay cannot be less than zero
print("Basic pay can't be negative.")
exit()
hra = basic_pay*0.1 # hra is 10 % of basic pay
ta = basic_pay*0.05 # ta is 5 % of basic pay
total_salary = basic_pay + hra + ta
professional_tax = total_salary*0.02 # professional tax is 2 % of total salary
salary_payable = total_salary - professional_tax
print("Salary Payable is",salary_payable)
except ValueError:
print("Enter amount in digits.")
Assignment No: 02 Momentum calculation
Assignment No: 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.
try:
mass = float(input("Enter mass in kgs: ")) # m is mass in kgs
velocity = float(input("Enter velocity in m/s: ")) # c is velocity in m/s
momentum = mass*(velocity**2) # e=mc2
print('Momentum of object is', momentum)
except ValueError:
print("Enter mass and velocity in int/float")
Assignment No: 03 Finding Max No & Min No in List Using Built-In
Function
Assignment No: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): # for loop
num = int(input("Enter no: "))
nos_list.append(num) # numbers are added in nos_list list
maxNo = max(nos_list) # maximum number in list
minNo = min(nos_list) # minimum number in list
sumNos = sum(nos_list) # sum of numbers in list
average = sumNos/len(nos_list) # average of numbers in list
print('Max no is ',maxNo)
print('Min no is ',minNo)
print('Count: ',len(nos_list)) # length of list
print('Sum of nos is ',sumNos)
print('Average of nos is ',average)
except ValueError:
print('Enter n and all elements as integer.')
Assignment No: 4 Student Result Calculation
Assignment No: 4
To accept students five courses marks and compute his/her result.
Student is passing if he/she scores marks equal to and above 40 in each course.
If student scores aggregate greater than 75%, then the grade is distinction.
If aggregate is 60>= and <75 then the grade if first division.
If aggregate is 50>= and <60, then the grade is second division.
If aggregate is 40>= and <50, then the grade is third division.
if __name__ == '__main__':
student = Student()
student.input() # function calling
student.grade()
Assignment No: 6 Simple Calculator
Assignment No: 6
To simulate simple calculator that performs basic tasks such
as,addition,subtraction,multiplication and division.
def main():
while(1):
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
if __name__ == '__main__':
main()
Assignment No: 9 Printing Reverse No using Function
Assignment No: 9
To accept a number from user and print digits of number in a reverse order using
built-in function.
Assignment No: 10
To input binary number from user and convert it into decimal number.
Assignment NO: 11
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")
Assignment No: 16 Character Conversion UPPER to lower and lower
to UPPER case
Assignment No: 16
To copy contents of one file to other. While copying a) all full stops are to be
replaced with commas b) lower case are to be replaced with upper case c) upper
case
are to be replaced with lower case.
try:
fin = open("input.txt",'r') # file opening in read mode
fout = open("output.txt",'w') # file is created
void setup() {
Serial.begin(9600);
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
pinMode(relay3,OUTPUT);
pinMode(relay4,OUTPUT);
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
}
void loop() {
//Relay is on
if( val == 1 ) {
digitalWrite(relay1,HIGH); }
else if( val == 2 ) {
digitalWrite(relay2,HIGH); } else if( val == 3 ) {
digitalWrite(relay3,HIGH); }
else if( val == 4 ) {
digitalWrite(relay4,HIGH); }
//relay all on
else if( val == 0 ) {
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
}
//relay is off
else if( val == 5 ) {
digitalWrite(relay1,LOW); }
else if( val == 6 ) {
digitalWrite(relay2,LOW); }
else if( val == 7 ) {
digitalWrite(relay3,LOW); }
else if( val == 8 ) {
digitalWrite(relay4,LOW); }
num1 = 1.5
num2 = 6.3
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
year = 2000
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
a = 5
b = 6
c = 7