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...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT