Question

In: Computer Science

create a PYTHON program that will determine the cost per 3" serving for a giant sub...

create a PYTHON program that will determine the cost per 3" serving for a giant sub sandwich you will be ordering for a get-together with your friends.
Within main(), get the input of the length in inches for the sub and the cost.
Create function named numServings() that will receive the length in inches and return the number of servings. Each 3" is considered serving. Servings should be a whole number, so you will need to find a way to drop the fraction and return only the integer portion, you should call this function from within main() and return the number of servings to main().
Then create a function named costPerServing(). This function which will receive both the cost of the giant sub and the number of servings. This function will return the cost per serving . Call the function within main().
Then within main(), print cost per serving using this format $2.67 print the number of servings!, then put the code in main() inside a loop, the loop will ask the user if they want to enter information for another sub sandwich. if so, data is requested and everything including the print statements process again!

Solutions

Expert Solution

Note: Variable names and function names are used in such a way for a better understanding. These can be changed according to the user's choice. Please refer to code snippets for a better understanding of comments and indentations.

IDE Used: PyCharm

Program Code

# function to get number of serving
def numServing(len_inch):
    num_serve = len_inch//3

    return num_serve

# function to get cost per serving
def costPerServing(sand_cost, num_serve):
    cost_per_serve = sand_cost/num_serve

    return cost_per_serve

# main function
def main():

    # variable to ask if order more sandwich
    more_sub = 'y'

    # loop until user input 'n'
    while more_sub == 'y':
        print("Give Sandwich Order Details\n")

        # promt user for sandwich length and cost
        len_inch = float(input("Sandwich length in inches : "))
        sand_cost = float(input("Sandwich cost : $"))

        # call function to get number of serve and cost per serve
        num_serve = int(numServing(len_inch))
        cost_per_serve = costPerServing(sand_cost, num_serve)

        # display the final values
        # i.e number of serve and cost of each serve
        print("Number of Serving : ", num_serve)
        print("Cost per serving : $%0.2f" %cost_per_serve)

        # prompt to know if want more sub
        more_sub = input("Request another sub ? (y/n) : ")
        if more_sub == 'n':
            print("Thank You for your Sandwich order!")
        print("\n")


# main declaration
if __name__=="__main__":
    main()


Code Snippets

Sample Input Output


Related Solutions

Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a class named GroceryItem. This class should contain: - an __init__ method that initializes the item’s name and price - a get_name method that returns the item’s name - a get_price method that returns the item’s price - a __str__ method that returns a string representation of that GroceryItem - an unimplemented method is_perishable Save this class in GroceryItem.py. 2. Create a subclass Perishable that...
Create a python program to determine which years are leap years (see key information at the...
Create a python program to determine which years are leap years (see key information at the bottom). Note: Do not use any lists. 1. Define a function that takes a parameter (year) and verifies if the parameter year is a leap year. If it is a leap year, the function returns True. Else, it returns False. Note: the function should not print anything. 2. Using the function, check if each of the years from 2000 to 2200 (both inclusive) is...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
create a file with 1000 alphanumeric ones written one per line. Write a program in python...
create a file with 1000 alphanumeric ones written one per line. Write a program in python that randomly selects 100 of them, holds the index of each alphanumeric, adds the hash of the previous 100 and tries to find a random alphanumeric so that if it adds it to the list of indicators the SHA256 of the whole to have 10 zeros at the end. You start with the original Hash: 1111..111 my solution so far: import random import string...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
In Python Create customer information system as follows: Python 3 Create customer information system as follows:...
In Python Create customer information system as follows: Python 3 Create customer information system as follows: Ask the user to enter name, phonenumber, email for each customer. Build a dictionary of dictionaries to hold 10 customers with each customer having a unique customer id. (random number generated) Take the keys of the above mentioned dictionary which are customer ids and make a list. Ask the use to enter a customer id and do a binary search to find if the...
Problem 2. You wish to determine the energy content per gram and Calories per serving of...
Problem 2. You wish to determine the energy content per gram and Calories per serving of a chocolate chip cookie and a banana bread slice from the Student Union to decide which is less “fattening.” The intact cookie and banana bread slice you are analyzing weigh 72.501 g and 69.003 g, respectively. Before you can analyze the samples, the calorimeter heat capacity must be determined. It is known that combustion of 1.000 g of benzoic acid releases 26.44 kJ of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT