Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views12 pages

PPS - Assignment No 1&3

The document outlines three assignments focused on Python programming. Assignment 1 involves creating a program for basic arithmetic operations and expression evaluation, Assignment 2 calculates an employee's salary based on inputted basic pay, and Assignment 3 checks if a number is an Armstrong number. Each assignment includes objectives, required software, algorithms, and sample programs.
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)
4 views12 pages

PPS - Assignment No 1&3

The document outlines three assignments focused on Python programming. Assignment 1 involves creating a program for basic arithmetic operations and expression evaluation, Assignment 2 calculates an employee's salary based on inputted basic pay, and Assignment 3 checks if a number is an Armstrong number. Each assignment includes objectives, required software, algorithms, and sample programs.
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/ 12

Assignment no: 1

Problem statement: Program to perform all operation (addition, multiplication, subtraction,


division, modules) and expression.

Objective: Define the core functionality of the program, ensuring it performs basic
operations, evaluates expressions, and provides a smooth user experience.

Required software/hardware: Lab computer, ubuntu, python 3 interpreter /anaconda


navigator.

Outcomes: Getting knowledge of data types, identifiers, literals used in python.

Theory:
1. List and Explain Features of python Programming
2. Expalin Floor division //, Modulus %, Operator in pyhton
3. Explain eval() function in python
4. Application of Python Language.

Algorithm:

Step1: Start
Step2: Accept Two numbers as input using built in function input () function
Step 3: Compute Addition of two numbers
ADD= num1+num2

Step 4: Compute Subtraction of two numbers


SUB= num1+num2

Step 5: Compute Product of two numbers


MUL= num1*num2

Step 6: Compute floor Division of two numbers


DIV= num1//num2

Step 7: Compute floor Modulus of two numbers


MOD= num1 % num2

Step 8: Evaluate Expression using built-in function


eval()

Step 9: Display All results

Step10: Stop
Flowchart:
Program:

Here’s a Python program that performs all the operations (addition, multiplication,
subtraction, division, modulus) and evaluates an expression,

# Input: Two numbers from the user

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))

# Perform basic arithmetic operations

addition = num1 + num2


subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2 if num2 != 0 else "undefined (division by zero)"
modulus = num1 % num2 if num2 != 0 else "undefined (division by zero)"

# Display results of basic operations

print(f"Addition: {num1} + {num2} = {addition}")


print(f"Subtraction: {num1} - {num2} = {subtraction}")
print(f"Multiplication: {num1} * {num2} = {multiplication}")
print(f"Division: {num1} / {num2} = {division}")
print(f"Modulus: {num1} % {num2} = {modulus}")

# Input: Expression for evaluation


expression = input("Enter a mathematical expression to evaluate (e.g.,
3+2*5): ")

# Evaluate and display the result of the expression


result = eval(expression)
print(f"Result of the expression '{expression}': {result}")

Explanation:

• The program first prompts the user to enter two numbers.


• It then calculates the results for the arithmetic operations (addition, subtraction, multiplication,
division, and modulus).
• Next, it asks the user for a mathematical expression (like 3 + 2 * 5), evaluates it using Python's
eval() function, and displays the result.
• If the expression entered by the user is invalid, the program will catch the error and display an
appropriate message.

Output:
Conclusion:

By implementing this problem statement, we learn the concepts and use of mathematical
operators and expression.

Date of Performance:

Date of Completion:

Continuous Assessment of student:

TC PR IN EC PN Total Marks
Faculty Signature
02 02 02 02 02 10

TC: Timely Completion, PR: Performance, IN: Innovation, EC: Efficient Code,
PN: Punctuality and Neatness
Assignment no: 2
Problem statement: 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.

Objective: To read salary details as input from user and display the gross salary.

Required software/hardware: Lab computer, ubuntu, python 3 interpreter /anaconda


navigator.

Outcomes: Getting knowledge of data types, identifiers, literals used in python.

Theory:
1. Explain all data types with syntax and examples
3. List and Explain all operators in python with example

Algorithm:

Step1: Start
Step2: Variable initializations
Step3: Accept basic pay from user
Step4: If value of basic pay is negative then ask user to enter positive value for basic pay
step5: Compute salary as
Hra = (basic_pay/100)*10; ta = (basic_pay/100)*5;
Temp_salary = basic_pay + hra + ta; ptax = (temp_salary/100)*2
Salary = temp_salary - ptax;
Step6: Display salary
Step7: Stop
Flowchart:
Program:

basic_pay = float(input("Enter the basic pay of employee: "))

hra = basic_pay*0.1 # hra is 10 % of basic pay

ta = basic_pay*0.05 # ta is 5 % of basic pay

da= basic_pay*125/100 # da is 125% of basic pay

total_salary = basic_pay + hra + ta + da

professional_tax = total_salary*0.02 # professional tax is 2 % of total salary

salary_payable = total_salary - professional_tax

print("\n------------Employee Salary Structure On Given Basic Pay------------------")

print("\nHousing Rent Allowance (HRA) on Basic Pay is::",hra)

print("\nTravelling Allowance (TA) on Basic Pay is::",ta)

print("\nDaily Allowance (DA) on Basic Pay is::",da)

print("\nTotal Salary of Employee::",total_salary)

print("\nProfessional Tax on Total Salary is::",professional_tax)

print("\nSalary Payable to Employee ::",salary_payable).

Output:

Enter the basic pay of employee: 12000

------------Employee Salary Structure On Given Basic Pay------------------

Housing Rent Allowance (HRA) on Basic Pay is:: 1200.0

Travelling Allowance (TA) on Basic Pay is:: 600.0

Daily Allowance (DA) on Basic Pay is:: 15000.0

Total Salary of Employee:: 28800.0

Professional Tax on Total Salary is:: 576.0

Salary Payable to Employee :: 28224.0


Conclusion:

By implementing this problem statement, we implement salary structure of an employee


on his basics pay and given values.

Date of Performance:

Date of Completion:

Continuous Assessment of student:

TC PR IN EC PN Total Marks
Faculty Signature
02 02 02 02 02 10

TC: Timely Completion, PR: Performance, IN: Innovation, EC: Efficient Code,
PN: Punctuality and Neatness
Assignment 3

Problem Statement: To check whether input number is Armstrong number or not.

Objective: To read number, extract individual digit from it and check number is
Armstrong or not

Required Software/Hardware: Lab Computer, Ubuntu, Python 3 interpreter


/Anaconda navigator

Outcomes: Getting Knowledge of number separation using string and list concept

Theory
1. Explain Armstrong number with Logic and an example
2. Explains Loop structures in python
3. Explain Conditional Statement into python

Algorithm:

Step 1: Start

Step 2: Accept a number from user

Step 3: sum =0

Step 4: For each digit in the number repeat steps 5 and 6

Step 5: Calculate cube = cube of the digit

Step 6: Calculate sum = sum + cube

Step 7: Check if sum is equal to the number entered by user if yes go to step 8

otherwise go to step 9

Step 8: Display message “Number is a Armstrong number” and go to step 10

Step 9: Display message “Number is not a Armstrong number”

Step 10: Stop


Flowchart:
Program:

import math
arm_num=int(input("Enter number to check it is Armstrong or Not::"))
copy_num=arm_num # assign given value to new variable
totl_dig=0

while copy_num!=0:
copy_num=copy_num//10
print("\nQuotient of division::",copy_num)
totl_dig+=1
print("Total digits in given Number::",totl_dig)
print("\n------------------------------------------------------------")
copy_num=arm_num
pow_sum=0

while copy_num!=0:
rem_num=copy_num%10
print("\nRemainder of division::",rem_num)
print("Power of",rem_num,"is::",pow(rem_num,totl_dig))
pow_sum= pow_sum+pow(rem_num,totl_dig)
print("Sum of number after caluating power of number::",pow_sum)
copy_num=copy_num//10

if pow_sum == arm_num:

print("\nInputed value is 'ARMSTRONG' number ")

else:

print("\nInputed value is 'NOT ARMSTRONG' number ")

Output:

Enter number to check it is Armstrong or Not::371

Quotient of division:: 37
Total digits in given Number:: 1

Quotient of division:: 3
Total digits in given Number:: 2

Quotient of division:: 0
Total digits in given Number:: 3

------------------------------------------------------------
Remainder of division:: 1
Power of 1 is:: 1
Sum of number after caluating power of number:: 1

Remainder of division:: 7
Power of 7 is:: 343
Sum of number after caluating power of number:: 344

Remainder of division:: 3
Power of 3 is:: 27
Sum of number after caluating power of number:: 371

Inputed value is 'ARMSTRONG' number

Conclusion:

By implementing this assignment, we learn the concepts of Armstrong number


and use of Looping structure in python.

Date of Performance:

Date of Completion:

Continuous Assessment of student:

TC PR IN EC PN Total Marks
Faculty Signature
02 02 02 02 02 10

TC: Timely Completion, PR: Performance, IN: Innovation, EC: Efficient Code,
PN: Punctuality and Neatness

You might also like