Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

ASSIGNMENT 3

Q.WRITE A PYTHON PROGRAM TO IMPLEMENT ALL THE MODULES


CONCEPTS (INCLUDING BUILD-IN) USING ANY REAL TIME
APPLICATION. REFER MY NOTES IN THEORY UNIT – 4 AND LAB EX
SOLUTIONS.

CALCULATOR
1.Creating files;
mymodule,mymodule1,basic,operations,specialmenu in
workfromhome folder

2.Entering the desired code in mymodule1


import sys
from mymodule import*
from basic import*
from specialmenu import*
print("Name:",sys.argv[1])
name=sys.argv[1]
introduction(name)
basicoperations()
specialoperations()

3.Entering the desired code in mymodule

-> def introduction(name):


print("Hello",name)
print("Welcome to the calculator")
3.Entering the desired code in basic.py
import operations as op
def basicoperations():
a=int(input("Enter a number"))
b=int(input("Enter another number"))
print('''Enter your
choice:1.Additon,2.Subtraction,3.Multiplication,4.Division''')
ch=int(input())
if(ch==1):
op.addition(a,b)
elif(ch==2):
op.subtracion(a,b)
elif(ch==3):
op.multiplication(a,b)
elif(ch==4):
op.division(a,b)

5.Entering the code in operations.py


def addition(a,b):
print("The addition of two numbers is",a+b)
def subtraction(a,b):
print("The addition of two numbers is",a-b)
def multiplication(a,b):
print("The addition of two numbers is",a*b)
def division(a,b):
if(b==0):
print("Division by zero not possible")
else:
print("The addition of two numbers is",a/b)

6.Entering the code in specialmenu.py

import math
def specialoperations():
n=int(input("Enter a number"))
ch1=int(input("Enter choice 1.Square root,2.Factorial"))
if(ch1==1)
print("Square root",math.sqrt(n))
elif(ch2==2)
print("Factorial",math.factorial(n))

Executing the program

Cases:
i) Addition:
ii) Subtraction:

iii) Multiplication:

iv) Division

Square root and factorial

MODULE CONCEPTS WHICH WERE USED IN THE ABOVE APPLICATION


 BUILT IN MODULES
 AS KEYWORD
 * KEYWORD
 %RUN AND SYS
 FROM KEYWORD

- Sivadanus.S
- 2019109036
- Department of
Manufacturing
Engineering

You might also like