Build a simple calculator module using Python Create a new file and save it as myModule.py Define four functions and name them add, subtract, multiply, divide and write the function body for each to return the calculated values for two or three numbers - set the default value to something smart to allow this Create a new file in the same directory and save it as myCalculator.py Make sure to write import myModule so that the math functions you've written are included in your driver (myCalculator.py). Write a python program that: includes function to ask for user name, and two or three numbers (you need to decide how to allow the user to only enter two.) has docstrings for each function uses the functions defined in myModule.py to calculate addition, subtraction, multiplication, division of two or three numbers. Gets input from and displays output to the user

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Build a simple calculator module using Python

  • Create a new file and save it as myModule.py
  • Define four functions and name them add, subtract, multiply, divide and write the
    function body for each to return the calculated values for two or three numbers - set the default value to something smart to allow this
  • Create a new file in the same directory and save it as myCalculator.py
  • Make sure to write import myModule so that the math functions you've written are included in your driver (myCalculator.py).
  • Write a python program that:
    • includes function to ask for user name, and two or three numbers (you need to decide how to allow the user to only enter two.)
    • has docstrings for each function
    • uses the functions defined in myModule.py to calculate addition, subtraction, multiplication, division of two or three numbers.
    • Gets input from and displays output to the user

Write a second python program called myTrip.py that uses functions to calculate your trip's costs. Note: You should display the costs to the user with proper prompts.

  • Define a function called hotel_cost with one-argument nights as input. The hotel costs $140 per night. Therefore, the function hotel_cost should return 140 x nights.
  • Define a function called plane_ride_cost that takes city names as input parameters. The function should return a different price depending on the location for a round trip. Below are the valid destinations and their corresponding one-way trip prices. 
    • "Charlotte": $183
    • "Tampa": $220
    • "Pittsburgh": $222
    • "Los Angeles": $475
  • Define a function called rental_car_cost with an argument called days. Calculate the cost of renting the car: Every day you rent the car costs $40 (cost = 40 x days). Return that cost.
  • Then, define a function called trip_cost that takes city names and days as arguments, and have your function return the sum of calling the rental_car_cost (days), hotel_cost (days), and plane_ride_cost (city) functions – for each city.
  • Modify your trip_cost function definition. Add a third argument, spending_money. Modify what the trip_cost function does. Add the variable spending_money to the sum that it returns.

How hard is it to modify your program to update the per day and flight costs?  Could you use constants at the top of your program to facilitate this?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education