SlideShare a Scribd company logo
Mylib.py
def allInOne(n1, n2):
return {"add":plus(n1, n2),
"sub":subtract(n1, n2),
"mult":multiply(n1, n2),
"div": divide(n1, n2)}
def IsInRange(lr, hr, n):
return lr < n and n < hr
#add 2 numbers
def plus(n1,n2):
add = n1 + n2
return add
#subtract 2 numbers
def subtract(n1, n2):
sub = n1 - n2
return sub
#multiply 2 numbers
def multiply(n1, n2):
mult = n1 * n2
return mult
#division, n2 should not be zero
def divide(n1, n2):
try:
div = n1/(n2 + 0.0)
return div
except ZeroDivisionError as e:
print("The result of %s/%s = %s" % (n1, n2,"You cannot
divide by Zero"))
except Exception :
print("Invalid input" , n1, n2)
#expression calculator
def scalc(val):
try:
#the epression is assumed to be comma separated
ns = val.split(",")
#split it into 3 parts
#remove whitespaces in the components
n1 = int(ns[0].strip())
n2 = int(ns[1].strip())
op = ns[2].strip()
#check if operator is one of the supported
if op == "*":
return multiply(n1, n2)
elif op == "/":
return divide(n1, n2)
elif op == "+":
return plus(n1, n2)
elif op == "-":
return subtract(n1, n2)
else:
print("Unknown operator", op)
#in case of invalid input catch the error
except Exception :
print("Invalid input:" , val)
W6_first_last.py
# Program name :
# Student Name :
# Course : ENTD220
# Instructor :
# Date : 02/12/2020
# Description : Expression & Arithmetic Calculator
# Copy Wrong : This is my work
import Mylib
def doScalc():
print("---------Expression calculator------------------")
print("Enter the expression with format N1,N2,operator:")
print("Supported operator * , /, -, +")
print("E.g 5, 4, *)")
val = input()
res = Mylib.scalc(val)
print('The result of "' + val + '" is', res)
def showList():
print("1) Add two numbers")
print("2) Multiply two numbers")
print("3) Subtract two numbers")
print("4) Divide two numbers")
print("5) Scalc")
print("6) All in one")
print("7) Exit")
def getUserInput():
low = int(input("Enter Lower range:"))
high = int(input("Enter Higher range:"))
n1 = int(input("Enter first number:"))
n2 = int(input("Enter second number:"))
return [low, high, n1 , n2]
def doCalculation(op):
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and 
Mylib.IsInRange(low , high, n2):
if op == "+":
res = Mylib.plus(n1, n2)
elif op == "*":
res = Mylib.multiply(n1, n2)
elif op == "-":
res = Mylib.subtract(n1, n2)
elif op == "/":
res = Mylib.divide(n1, n2)
print("%d %s %d = %d" % (n1, op, n2, res))
else:
print("Error: input out of range")
def doAllInOne():
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and 
Mylib.IsInRange(low , high, n2):
mydict = Mylib.allInOne(n1, n2)
print("%d + %d = %d" % (n1, n2, mydict["add"]))
print("%d - %d = %d" % (n1, n2, mydict["sub"]))
print("%d * %d = %d" % (n1, n2, mydict["mult"]))
print("%d / %d = %d" % (n1, n2, mydict["div"]))
def main():
while True:
showList()
action = int(input("What do you want to do?"))
if action == 7:
break;
if action == 1:
user = getUserInput
doCalculation("+")
elif action == 2:
doCalculation("*")
elif action == 3:
doCalculation("-")
elif action == 4:
doCalculation("/")
elif action == 5:
doScalc()
elif action == 6:
doAllInOne()
print()
main()
print("Thanks for using our calculator!")

More Related Content

Similar to Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx

Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
GaneshPawar819187
 
Basic python programs
Basic python programsBasic python programs
Basic python programs
RaginiJain21
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
Mitchell Vitez
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdf
FriendsStationary
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
ArnabNath30
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
ArnabNath30
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
NeerajChauhan697157
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
GaneshPawar819187
 
Matlab project
Matlab projectMatlab project
Matlab project
iftikhar ali
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
Chaithanya89350
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 
xii cs practicals
xii cs practicalsxii cs practicals
xii cs practicals
JaswinderKaurSarao
 
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docxhotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
BHANUNANUPATRUNI
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
MUMAR57
 
Retos de Programación en Python
Retos de Programación en PythonRetos de Programación en Python
Retos de Programación en Python
Javier Abadía
 
C programs
C programsC programs
C programsMinu S
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
JkPoppy
 

Similar to Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx (20)

Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
Basic python programs
Basic python programsBasic python programs
Basic python programs
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdf
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
 
Matlab project
Matlab projectMatlab project
Matlab project
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
xii cs practicals
xii cs practicalsxii cs practicals
xii cs practicals
 
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docxhotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
hotelmangt project code connecting python wih Mysql cbse 2022-23 project .docx
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
 
Retos de Programación en Python
Retos de Programación en PythonRetos de Programación en Python
Retos de Programación en Python
 
C programs
C programsC programs
C programs
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 

More from roushhsiu

Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docx
roushhsiu
 
Morgan and Dunn JD have hired you to assist with a case involvin.docx
Morgan and Dunn JD have hired you to assist with a case involvin.docxMorgan and Dunn JD have hired you to assist with a case involvin.docx
Morgan and Dunn JD have hired you to assist with a case involvin.docx
roushhsiu
 
Mortality rates vary between the Hispanic community and the gene.docx
Mortality rates vary between the Hispanic community and the gene.docxMortality rates vary between the Hispanic community and the gene.docx
Mortality rates vary between the Hispanic community and the gene.docx
roushhsiu
 
Moreno Industries has adopted the following production budget for th.docx
Moreno Industries has adopted the following production budget for th.docxMoreno Industries has adopted the following production budget for th.docx
Moreno Industries has adopted the following production budget for th.docx
roushhsiu
 
Most people have a blend of leadership styles that they use. Some le.docx
Most people have a blend of leadership styles that they use. Some le.docxMost people have a blend of leadership styles that they use. Some le.docx
Most people have a blend of leadership styles that they use. Some le.docx
roushhsiu
 
Moral rights as opposed to legal rights are not dependent on a polit.docx
Moral rights as opposed to legal rights are not dependent on a polit.docxMoral rights as opposed to legal rights are not dependent on a polit.docx
Moral rights as opposed to legal rights are not dependent on a polit.docx
roushhsiu
 
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docxMontasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
roushhsiu
 
Module Outcome  You will be able to describe the historical force.docx
Module Outcome  You will be able to describe the historical force.docxModule Outcome  You will be able to describe the historical force.docx
Module Outcome  You will be able to describe the historical force.docx
roushhsiu
 
Molière believed that the duty of comedy is to correct human vices b.docx
Molière believed that the duty of comedy is to correct human vices b.docxMolière believed that the duty of comedy is to correct human vices b.docx
Molière believed that the duty of comedy is to correct human vices b.docx
roushhsiu
 
Module One Making Budgetary DecisionsDirectionsBased on the i.docx
Module One Making Budgetary DecisionsDirectionsBased on the i.docxModule One Making Budgetary DecisionsDirectionsBased on the i.docx
Module One Making Budgetary DecisionsDirectionsBased on the i.docx
roushhsiu
 
Monitoring Data and Quality ImprovementAnswer one of two que.docx
Monitoring Data and Quality ImprovementAnswer one of two que.docxMonitoring Data and Quality ImprovementAnswer one of two que.docx
Monitoring Data and Quality ImprovementAnswer one of two que.docx
roushhsiu
 
Monitoring Global Supply Chains† Jodi L. Short Prof.docx
Monitoring Global Supply Chains†   Jodi L. Short Prof.docxMonitoring Global Supply Chains†   Jodi L. Short Prof.docx
Monitoring Global Supply Chains† Jodi L. Short Prof.docx
roushhsiu
 
Morality Relativism & the Concerns it RaisesI want to g.docx
Morality Relativism & the Concerns it RaisesI want to g.docxMorality Relativism & the Concerns it RaisesI want to g.docx
Morality Relativism & the Concerns it RaisesI want to g.docx
roushhsiu
 
Module 9 content You will perform a history of a cardiac pro.docx
Module 9 content You will perform a history of a cardiac pro.docxModule 9 content You will perform a history of a cardiac pro.docx
Module 9 content You will perform a history of a cardiac pro.docx
roushhsiu
 
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docxModule Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
roushhsiu
 
Module Assignment Clinical Decision Support SystemsLearning Outcome.docx
Module Assignment Clinical Decision Support SystemsLearning Outcome.docxModule Assignment Clinical Decision Support SystemsLearning Outcome.docx
Module Assignment Clinical Decision Support SystemsLearning Outcome.docx
roushhsiu
 
MONTCLAIR UNIVERSITYLAWS 362 LEGAL WRITING MIDTERM.docx
MONTCLAIR UNIVERSITYLAWS 362  LEGAL WRITING   MIDTERM.docxMONTCLAIR UNIVERSITYLAWS 362  LEGAL WRITING   MIDTERM.docx
MONTCLAIR UNIVERSITYLAWS 362 LEGAL WRITING MIDTERM.docx
roushhsiu
 
MODULE 8You will perform a history of a respiratory problem th.docx
MODULE 8You will perform a history of a respiratory problem th.docxMODULE 8You will perform a history of a respiratory problem th.docx
MODULE 8You will perform a history of a respiratory problem th.docx
roushhsiu
 
Most organizations, including hospitals, adopt both Mission and Visi.docx
Most organizations, including hospitals, adopt both Mission and Visi.docxMost organizations, including hospitals, adopt both Mission and Visi.docx
Most organizations, including hospitals, adopt both Mission and Visi.docx
roushhsiu
 
More like this Abstract TranslateFull Text Translate.docx
More like this Abstract TranslateFull Text Translate.docxMore like this Abstract TranslateFull Text Translate.docx
More like this Abstract TranslateFull Text Translate.docx
roushhsiu
 

More from roushhsiu (20)

Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docx
 
Morgan and Dunn JD have hired you to assist with a case involvin.docx
Morgan and Dunn JD have hired you to assist with a case involvin.docxMorgan and Dunn JD have hired you to assist with a case involvin.docx
Morgan and Dunn JD have hired you to assist with a case involvin.docx
 
Mortality rates vary between the Hispanic community and the gene.docx
Mortality rates vary between the Hispanic community and the gene.docxMortality rates vary between the Hispanic community and the gene.docx
Mortality rates vary between the Hispanic community and the gene.docx
 
Moreno Industries has adopted the following production budget for th.docx
Moreno Industries has adopted the following production budget for th.docxMoreno Industries has adopted the following production budget for th.docx
Moreno Industries has adopted the following production budget for th.docx
 
Most people have a blend of leadership styles that they use. Some le.docx
Most people have a blend of leadership styles that they use. Some le.docxMost people have a blend of leadership styles that they use. Some le.docx
Most people have a blend of leadership styles that they use. Some le.docx
 
Moral rights as opposed to legal rights are not dependent on a polit.docx
Moral rights as opposed to legal rights are not dependent on a polit.docxMoral rights as opposed to legal rights are not dependent on a polit.docx
Moral rights as opposed to legal rights are not dependent on a polit.docx
 
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docxMontasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
Montasari, R., & Hill, R. (2019). Next-Generation Digital Forens.docx
 
Module Outcome  You will be able to describe the historical force.docx
Module Outcome  You will be able to describe the historical force.docxModule Outcome  You will be able to describe the historical force.docx
Module Outcome  You will be able to describe the historical force.docx
 
Molière believed that the duty of comedy is to correct human vices b.docx
Molière believed that the duty of comedy is to correct human vices b.docxMolière believed that the duty of comedy is to correct human vices b.docx
Molière believed that the duty of comedy is to correct human vices b.docx
 
Module One Making Budgetary DecisionsDirectionsBased on the i.docx
Module One Making Budgetary DecisionsDirectionsBased on the i.docxModule One Making Budgetary DecisionsDirectionsBased on the i.docx
Module One Making Budgetary DecisionsDirectionsBased on the i.docx
 
Monitoring Data and Quality ImprovementAnswer one of two que.docx
Monitoring Data and Quality ImprovementAnswer one of two que.docxMonitoring Data and Quality ImprovementAnswer one of two que.docx
Monitoring Data and Quality ImprovementAnswer one of two que.docx
 
Monitoring Global Supply Chains† Jodi L. Short Prof.docx
Monitoring Global Supply Chains†   Jodi L. Short Prof.docxMonitoring Global Supply Chains†   Jodi L. Short Prof.docx
Monitoring Global Supply Chains† Jodi L. Short Prof.docx
 
Morality Relativism & the Concerns it RaisesI want to g.docx
Morality Relativism & the Concerns it RaisesI want to g.docxMorality Relativism & the Concerns it RaisesI want to g.docx
Morality Relativism & the Concerns it RaisesI want to g.docx
 
Module 9 content You will perform a history of a cardiac pro.docx
Module 9 content You will perform a history of a cardiac pro.docxModule 9 content You will perform a history of a cardiac pro.docx
Module 9 content You will perform a history of a cardiac pro.docx
 
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docxModule Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
Module Assessment 4 TANM ApplicationsBUS2 190Last name, Fir.docx
 
Module Assignment Clinical Decision Support SystemsLearning Outcome.docx
Module Assignment Clinical Decision Support SystemsLearning Outcome.docxModule Assignment Clinical Decision Support SystemsLearning Outcome.docx
Module Assignment Clinical Decision Support SystemsLearning Outcome.docx
 
MONTCLAIR UNIVERSITYLAWS 362 LEGAL WRITING MIDTERM.docx
MONTCLAIR UNIVERSITYLAWS 362  LEGAL WRITING   MIDTERM.docxMONTCLAIR UNIVERSITYLAWS 362  LEGAL WRITING   MIDTERM.docx
MONTCLAIR UNIVERSITYLAWS 362 LEGAL WRITING MIDTERM.docx
 
MODULE 8You will perform a history of a respiratory problem th.docx
MODULE 8You will perform a history of a respiratory problem th.docxMODULE 8You will perform a history of a respiratory problem th.docx
MODULE 8You will perform a history of a respiratory problem th.docx
 
Most organizations, including hospitals, adopt both Mission and Visi.docx
Most organizations, including hospitals, adopt both Mission and Visi.docxMost organizations, including hospitals, adopt both Mission and Visi.docx
Most organizations, including hospitals, adopt both Mission and Visi.docx
 
More like this Abstract TranslateFull Text Translate.docx
More like this Abstract TranslateFull Text Translate.docxMore like this Abstract TranslateFull Text Translate.docx
More like this Abstract TranslateFull Text Translate.docx
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 

Mylib.pydef allInOne(n1, n2) return {addplus(n1, n2).docx

  • 1. Mylib.py def allInOne(n1, n2): return {"add":plus(n1, n2), "sub":subtract(n1, n2), "mult":multiply(n1, n2), "div": divide(n1, n2)} def IsInRange(lr, hr, n): return lr < n and n < hr #add 2 numbers def plus(n1,n2): add = n1 + n2 return add #subtract 2 numbers def subtract(n1, n2):
  • 2. sub = n1 - n2 return sub #multiply 2 numbers def multiply(n1, n2): mult = n1 * n2 return mult #division, n2 should not be zero def divide(n1, n2): try: div = n1/(n2 + 0.0) return div except ZeroDivisionError as e: print("The result of %s/%s = %s" % (n1, n2,"You cannot divide by Zero")) except Exception : print("Invalid input" , n1, n2)
  • 3. #expression calculator def scalc(val): try: #the epression is assumed to be comma separated ns = val.split(",") #split it into 3 parts #remove whitespaces in the components n1 = int(ns[0].strip()) n2 = int(ns[1].strip()) op = ns[2].strip() #check if operator is one of the supported if op == "*": return multiply(n1, n2) elif op == "/": return divide(n1, n2) elif op == "+": return plus(n1, n2)
  • 4. elif op == "-": return subtract(n1, n2) else: print("Unknown operator", op) #in case of invalid input catch the error except Exception : print("Invalid input:" , val) W6_first_last.py # Program name : # Student Name : # Course : ENTD220 # Instructor : # Date : 02/12/2020 # Description : Expression & Arithmetic Calculator # Copy Wrong : This is my work import Mylib def doScalc(): print("---------Expression calculator------------------") print("Enter the expression with format N1,N2,operator:") print("Supported operator * , /, -, +") print("E.g 5, 4, *)") val = input() res = Mylib.scalc(val)
  • 5. print('The result of "' + val + '" is', res) def showList(): print("1) Add two numbers") print("2) Multiply two numbers") print("3) Subtract two numbers") print("4) Divide two numbers") print("5) Scalc") print("6) All in one") print("7) Exit") def getUserInput(): low = int(input("Enter Lower range:")) high = int(input("Enter Higher range:")) n1 = int(input("Enter first number:")) n2 = int(input("Enter second number:")) return [low, high, n1 , n2] def doCalculation(op): user = getUserInput() low = user[0] high = user[1] n1 = user[2] n2 = user[3] if Mylib.IsInRange(low , high, n1) and Mylib.IsInRange(low , high, n2): if op == "+": res = Mylib.plus(n1, n2) elif op == "*": res = Mylib.multiply(n1, n2) elif op == "-": res = Mylib.subtract(n1, n2) elif op == "/": res = Mylib.divide(n1, n2) print("%d %s %d = %d" % (n1, op, n2, res))
  • 6. else: print("Error: input out of range") def doAllInOne(): user = getUserInput() low = user[0] high = user[1] n1 = user[2] n2 = user[3] if Mylib.IsInRange(low , high, n1) and Mylib.IsInRange(low , high, n2): mydict = Mylib.allInOne(n1, n2) print("%d + %d = %d" % (n1, n2, mydict["add"])) print("%d - %d = %d" % (n1, n2, mydict["sub"])) print("%d * %d = %d" % (n1, n2, mydict["mult"])) print("%d / %d = %d" % (n1, n2, mydict["div"])) def main(): while True: showList() action = int(input("What do you want to do?")) if action == 7: break; if action == 1: user = getUserInput doCalculation("+") elif action == 2: doCalculation("*") elif action == 3: doCalculation("-") elif action == 4: doCalculation("/") elif action == 5: doScalc() elif action == 6: doAllInOne()