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

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter14: Files And Streams
Section: Chapter Questions
Problem 2E: Create a program named FileComparison that compares two files. First, use a text editor such as...
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:
9781337569798
Author:
ECKERT
Publisher:
CENGAGE L
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT