0% found this document useful (0 votes)
24 views15 pages

Assignment (B) - PSP F-20

The document contains a series of programming assignments completed by Aditya B Naikwadi, focusing on various computational tasks such as calculating employee salaries, determining student grades based on marks, checking for Armstrong numbers, simulating a simple calculator, and performing mathematical operations like square roots, prime checks, and GCD calculations. Each assignment includes input prompts, processing logic, and output statements. The assignments demonstrate a range of programming concepts and techniques.

Uploaded by

adityanaikwadi17
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)
24 views15 pages

Assignment (B) - PSP F-20

The document contains a series of programming assignments completed by Aditya B Naikwadi, focusing on various computational tasks such as calculating employee salaries, determining student grades based on marks, checking for Armstrong numbers, simulating a simple calculator, and performing mathematical operations like square roots, prime checks, and GCD calculations. Each assignment includes input prompts, processing logic, and output statements. The assignments demonstrate a range of programming concepts and techniques.

Uploaded by

adityanaikwadi17
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
You are on page 1/ 15

Name:Aditya B Naikwadi

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:

print("Enter marks obtained in 5 subjects: ")


markOne = int(input("Enter marks of first subject: "))
markTwo = int(input("Enter marks of second subject: "))
markThree = int(input("Enter marks of third subject: "))
markFour = int(input("Enter marks of fourth subject: "))
markFive = int(input("Enter marks of fifth subject: "))
tot = markOne + markTwo + markThree + markFour + markFive
avg = tot/5
if avg>=91 and avg<100:
print("Your grade is A1")
elif avg>=81 and avg<91:
print("Your grade is A2")
elif avg>=71 and avg<81:
print("Your grade is B1")
elif avg>=61 and avg<71:
print("Your grade is B2")
elif avg>=51 and avg<61:
print("Your grade is C1")
elif avg>=41 and avg<51:
print("Your grade is C2")
elif avg>=33 and avg<41:
print("Your grade is D")
elif avg>=21 and avg<33:
print("Your grade is E1")
elif avg>=0 and avg<21:
print("Your grade is E2")
else:
print("Invald input")
OUTPUT:
Name:Aditya B Naikwadi
Roll No.F-20
Div-F

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:

d)check for prime


Input:
num =int(input("Enter any number: "))
flag = 0
if num <= 1:
print(num, "is not a prime number")
else:
for i in range(2,num):
if num % i == 0:
flag = 1
break
If flag == 1:
print(num, "is not a prime number")
else:
print(num, "is a prime number")

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

List the even and odd number

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:

You might also like