Question

Write code snippets to do the following. You should write these in a Python editor and...

Write code snippets to do the following. You should write these in a Python editor and test them out as you go. When they work, copy and paste your final code snippet here.

Define a function that takes a total bill and the number of people at your table, and prints the amount that each person owes.

e.g. divide_bill(100, 5) would produce

Each person owes $20 for their meal.

e.g. divide_bill(50.25, 4)would produce

Each person owes $12.56 for their meal.

Note that the decimal number above may not be exactly the same as what you get. Yours might say 20.0 or 12.5625, for instance. We’ll learn about how to round to exactly two decimal points later (for Added Fun you could google how to do it now).

Make sure that you test your function by calling it at least twice in your main with different parameters.

Homework Answers

Answer #1

Please comment, if you need any corrections.Please give a Thumps up if you like the answer.

Program

def divide_bill(amount,persons):
meal_cost=amount/persons
print("Each person owes $",format(meal_cost, ',.2f'), " for their meal.")

divide_bill(100, 5)
divide_bill(50.25,4)

Output

Each person owes $ 20.00 for their meal.
Each person owes $ 12.56 for their meal.

Program Screenshot

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
You must write a function that works like a small editor. It should open an existing...
You must write a function that works like a small editor. It should open an existing file (let us say this is File1.txt. This file must exist before the function is run), read it line by line. Then write it to another file (let us say this is File2.txt. This file need not exist since Python will create it). However, if a certain line exists in the first file, it should be replaced by another line supplied by you. You...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n)...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n) sold by a restaurant in a month and calculates the monthly profit given the following information: The selling price of each meal is 12 USD (same for all meals) There is a fixed cost of 2500 USD per month regardless of the number of meals sold. There is a variable cost of 6 USD per each meal sold profit= total revenue- total cost =...
Python Code Use (for loops) inside another for loop (a nested loop) to do the following:...
Python Code Use (for loops) inside another for loop (a nested loop) to do the following: Print Hello 30 times followed by Bye 10 times. Do that whole thing 15 times. (for a total of 600 lines of output) #Hint: First write the code that prints 30 "Hello" and then 10 "Bye". Think of that as two separate tasks, each of which requires its own for loop. THEN, once you get that working, put all of that inside ANOTHER loop...
Using Python, write the following code. You are to allow the user to enter the daily...
Using Python, write the following code. You are to allow the user to enter the daily temperature as a floating-point number. You should make the assumption that you are recording temperatures in Fahrenheit. You should allow the user to continue entering temperatures until the value -999 is entered. This number should not be considered a temperature, but just a flag to stop the program. As the user enters a temperature, you should display the following each time: Current Temperature: 999...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
Question 1 Write functions that do the following: i) A function that takes 2 arguments and...
Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are...
Python question Write (and test) the following 10 functions (names are taken from old vi editor)...
Python question Write (and test) the following 10 functions (names are taken from old vi editor) for each implementation (1) cmd_h: move cursor one character to the left (2) cmd_I: move cursor one character to the right (3) cmd_j: move cursor vertically up one line (4) cmd_k: move cursor vertically down one line (5) cmd_X: delete the character to the left of the cursor (6) cmd_D: remove on current line from cursor to the end (7) cmd_dd: delete current line...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT