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 tool allows multiple users to dynamically update a document at the same time? Question 3 options: Google Docs OneDrive Exc
GenaCL600 [577]

Answer:

Excel

Explanation:

7 0
2 years ago
What are the basic tasks performed by an operating system?​
Kruka [31]

Answer:

An operating system is a software which performs all the basic tasks like file management, memory management, process management, handling input and output, and controlling peripheral devices such as disk drives and printers.

Explanation:

i hope it helps:)

3 0
2 years ago
The term load is often used to describe opening a page in a ____. Answer
mote1985 [20]
The answer is b web page
8 0
2 years ago
Are the blank space around the edges of the page
Law Incorporation [45]

Answer:

The blank space around the edges of a sheet of paper — as with the page of a book — that surrounds the text is called the margin.

8 0
2 years ago
Points!!!!!!!! pls help
siniylev [52]
D. Rasterize

This answer makes the most since
7 0
3 years ago
Read 2 more answers
Other questions:
  • In a word processing program, the ribbon or menus contain the
    12·1 answer
  • Mark works as a Network Administrator for NetTech Inc. The company has a Windows Server 2008 domain-based network. The network c
    7·1 answer
  • Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An ho
    12·1 answer
  • A(n) ________ CPU has two processing paths, allowing it to process more than one instruction at a time.
    9·2 answers
  • A tracking signal A. is computed as the mean absolute deviation​ (MAD) divided by the running sum of the forecast errors​ (RSFE)
    10·1 answer
  • Dan works for an automobile company. He has designed a new model of a car based on an older version. Which technology can he use
    6·1 answer
  • A student registers for a course in a university. Courses may have limited enrollment i.e a student must
    5·1 answer
  • Ano ang ibig sabihin ng tanka<br>​
    5·1 answer
  • It is a JavaScript property used to call a function after a specified time, in milliseconds​
    9·2 answers
  • In disc brakes, pads are forced against the of a brake disc​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!