Assignment (B) - PSP F-20
Assignment (B) - PSP F-20
Roll No.F-20
Div-F
Assignment no.1:
Title: To calculate salary of an employee.
Input:
days = float(input("Enter number of days present: "))
wage = float(input("Enter wage per day: "))
basic = wage*days
HRA=basic*0.1
DA=basic*0.05
PF =basic*0.12
netsalary = basic + HRA + DA- PF
print("Basic: %lf\nHRA: %lf\nDA: %lf\nPF: %lf\nNet salary: %lf"
%(basic,HRA,DA,PF,netsalary)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.3
Title:To accept student’s five courses marks and compute his/her result.
Input:
Assignment no.3
Title: To check whether the input is Armstrong
number or not.
Input:
num =int(input("Enter a number: "))
sum = 0 temp = num
while temp>0:
digit = temp%10
sum += digit**3
temp //= 10
if num == sum:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.4
Title: To simulate simple calulator.
Input:
def add(x,y):
return x+y
#this function subtracts two numbers
def subtract(x,y):
return x-y
#this function multiplies two numbers
def multiply(x,y):
return x*y
#this function divides two numbers
def divide(x,y):
return x/y
print("Select Operation:\n1. Add\n2. Subtract\n3. Multiply\n4. Divide")
while True:
#take input from user
choice = input("Enter choice (1/2/3/4): ")
#check if choice is one of the four options
if choice in ('1','2','3','4’):
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input. Please enter a number.")
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))
#check if use wants another calculation
#break the loop if answer is no
next_calculation = input("Let's do next calculation? (yes/no): ")
if next_calculation == "no":
break
elif next_calculation == "yes":
continue
else:
print("Invalid input")
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.05
Title: To accept number and compute
a)square root of number
Input:
import math
num =float(input("Enter any number: "))
print("The square root of", num, "is", math.sqrt(num))
OUTPUT:
b)square of number
Input:
number = float(input("Please enter any numberic value: "))
square = number*number
print("The square of the given number {0} =
{1}".format(number,square))
OUTPUT:
c)cube of number
Input:
number = float(input("Enter any numeric value: "))
cube = number**3
print("The cube of the given number {0} = {1}".format(number,cube))
OUTPUT:
OUTPUT:
e)factorial of number
Input:
num =int(input("Enter the num: "))
fac = 1
for i in range(2,num+1):
fac *= i
print("Factorial of",num,"is",fac)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.06
Title: Computing Smallest Divisor and Greatest Common Divisor Input:
import math
def smallest_divisor(num):
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return i
return num
def gcd(num1, num2):
while num2 != 0:
num1, num2 = num2, num1 % num2
return num1
# Accept two numbers from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Compute the smallest divisor of each number
divisor1 = smallest_divisor(num1)
divisor2 = smallest_divisor(num2)
# Compute the greatest common divisor (GCD)
gcd_result = gcd(num1, num2)
# Print the results
print("The smallest divisor of", num1, "is:", divisor1)
print("The smallest divisor of", num2, "is:", divisor2)
print("The greatest common divisor of", num1, "and", num2, "is:", gcd_result)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.:-07
Input :
def Reverse(number):
reverse=0
while (number>0):
reminder=number%10
reverse=(reverse*10)+reminder
number=number//10
return reverse
number=int(input("Enter any number : "))
reverse=Reverse(number)
print("Reverse of entered number is = %d"%reverse)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no :- 08
Input :
#Binary to decimal
print("Enter 'x' to exit.")
binary = input("Enter number in Binary Format: ")
if binary == 'x’:
exit()
else:
decimal = int(binary, 2)
print(binary, "in Decimal =", decimal)
#decimal to binary
decimal = int(input("Enter a decimal number: "))
binary = ""
If decimal == 0:
binary = "0"
else:
while decimal > 0:
binary = str(decimal % 2) + binary
decimal = decimal // 2
print("The binary representation is:", binary)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment No.09
INPUT:
a=[ ]
n=int(input(“enter number of elements :”))
For i in range ( 1 ,n+1):
b=int(input(“enter elements{i} :”))
a.append(b)
even=[ ]
odd=[ ]
For j in a:
If j%2==0:
even.append( j )
else:
odd.append( j )
Print(“the even list: ” ,even)
Print(“the odd list: ” ,odd)
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F
Assignment no.10
fibonacci series:
INPUT:
num=10
n1 , n2=0 ,1
Print(“fibonacci series:” , n1, n2, end= “ ”)
for I in range(2 ,num):
n3=n1+n2
n1=n2
n2=n3
Print(n3, end= “ ”)
Print( )
OUTPUT: