1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anni [7]
3 years ago
6

Write a program that accepts cost of food ordered, and it computes Tips (15%), Sales Tax (7%), and Total cost. The program displ

ays food price, sales tax, tip, and total cost of the food. Modify the program to get input from a text file, and create an output file for the same program
Computers and Technology
1 answer:
Mariulka [41]3 years ago
4 0

Answer:

The solution code is written in Python.

<u>First version (user input through terminal)</u>

  1. food_price = float(input("Enter food price: "))
  2. sales_tax = food_price * 0.07
  3. tips = food_price * 0.15  
  4. total_cost = food_price + sales_tax + tips  
  5. print("Food price: $" + str(food_price))
  6. print("Sale tax: $" + str(sales_tax))
  7. print("Tips: $" + str(tips))
  8. print("Total cost: $" + str(total_cost))
  9. print("\n")

<u>Second version (input from text file)</u>

  1. with open("text.txt") as file:
  2.    data = file.readlines()
  3.    for r in data:
  4.        food_price = float(r)
  5.        sales_tax = food_price * 0.07
  6.        tips = food_price * 0.15  
  7.        total_cost = food_price + sales_tax + tips  
  8.        print("Food price: $" + str(food_price))
  9.        print("Sale tax: $" + str(sales_tax))
  10.        print("Tips: $" + str(tips))
  11.        print("Total cost: $" + str(total_cost))
  12.        print("\n")

Explanation:

<u>First version</u>

In the first version of code, we can create all the necessary variables to hold the value of food price, sales tax, tips and total cost (Line 1 -4). Please note we get the food price using the input() function to prompt user to enter the value through terminal (Line 1).

Next display the values using print() function (Line 5 - 8)

<u>Second version</u>

The second version of code is similar to the first version except that we need to change the code to accept input from a text file (Line 1 -2) instead of using the input function.

We presume there might be multiple values in the text file and therefore it is recommended to use readlines() method to get the value line by line from the text file (Line 2) and use for loop to traverse through each row of food price value and calculate the sales tax, tips and total cost (Line 4-7).

You might be interested in
Which ribbon tab is home to the Function library used to insert functions into worksheets?
Sedaia [141]
The correct answer is C: Formulas
3 0
3 years ago
Read 2 more answers
True/false operating systems of mobile devices can support full-scale software programs like Microsoft word or excel
Anestetic [448]
This statement is false.
7 0
3 years ago
Will, there be any presents this year
garri49 [273]

Answer:

no why

Explanation:

8 0
3 years ago
Which of the following statements about light-emitting diodes is correct?
defon

The correct answer if B

4 0
3 years ago
Refer to the film, actor, and film_actor tables of the Sakila database. The tables in this lab have the same columns and data ty
julsineya [31]

Using the knowledge of computational language in python it is possible to write a code that organizes film, actor and film and actor at the same time.

<h3>Writting the code:</h3>

<em>SELECT a.last_name, a.first_name, ROUND(AVG(f.length)) AS 'average' </em>

<em>FROM film f </em>

<em>INNER JOIN film_actor fa ON f.film_id = fa.film_id</em>

<em>INNER JOIN actor a ON a.actor_id = fa.actor_id</em>

<em>GROUP BY a.last_name, a.first_name</em>

<em>ORDER BY average DESC, last_name ASC;</em>

See more about python at brainly.com/question/18502436

#SPJ1

5 0
2 years ago
Other questions:
  • Which type of footwear should be worn while working on a hybrid vehicle?
    8·2 answers
  • Indicate if the following statements are True or False. Statement Circle one Internet Service Providers (ISPs) are proprietary n
    13·1 answer
  • Why do i get message notifications but when i click on it it says i have no new messages?
    7·1 answer
  • 3 applications of cumulative probability distribution in medical field?​
    9·1 answer
  • If you ship bakudeku. I swear. <br> *RANTS*
    11·1 answer
  • Write a line of code that declares a variable called shipName and set it equal to the string SpaceX3000.
    9·1 answer
  • The retention of encoded information over time refers to
    14·1 answer
  • Give the names of two different places you might find a number represented in hexadecimal
    6·1 answer
  • What is the best example of how computers have changed the way people communicate?
    6·1 answer
  • television broadcasts were originally delivered by using which technology? ethernet wireless coaxial cable broadband
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!