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
Lenny copied and pasted content from a commercial website into his research paper without citing his source, passing the work of
Sedbober [7]
Lenny might be either suspended
Or might be failed in that particular course
6 0
1 year ago
Chat messages are most likely to be found where on a computer? firewall nic internet history ram
miv72 [106K]
<span>The answer is RAM.  Chat messages are most likely to be found in the RAM of the computer.  It is Random Access Memory.  </span><span>RAM is considered volatile memory, which means that the stored information is lost when there is no more power.</span>
3 0
3 years ago
Can you help me with Computer issues graphic organizer?<br> Will give out brainly
tino4ka555 [31]
Just put for first: coding, graphics and for second : designing, writing
Third?: put all of the abov
6 0
3 years ago
2. Which of the following statements accurately describes enzymes? A. Enzymes increase the activation energy of reactions. B. Te
Bas_tet [7]
B.temperatute and pH can affect how enzymes work
5 0
3 years ago
Which data type is 2.5?
Phoenix [80]

2.5 is a float.

Float stands for floating point. Floating point types are numbers with decimal places. I hope this helps!

6 0
3 years ago
Other questions:
  • Como hacer una pagina web
    15·1 answer
  • Allows an administrator to query a dns database and find the host name associated with a specific ip address or
    15·1 answer
  • The while loop is a pre-test loop? TRUE OR FALSE
    9·2 answers
  • Chevening is looking for individuals with strong professional relationship building skills, who will engage with the Chevening c
    15·1 answer
  • Select the characteristics that describe the evolution of computers that predate the personal computer (select all correct answe
    12·1 answer
  • What's another word for contact print?
    15·2 answers
  • Spencer wants to choose a career path that wouldn’t hold him to an office or laboratory. Which of the following career paths wou
    13·2 answers
  • Legal functions are the most important area of IG impact. Under the FRCP amendments, corporations must proactively manage the e-
    9·1 answer
  • I need a utube name for a gaming channel....PLEASE HELP...BRAINLIEST
    5·1 answer
  • Can anyone figure this out???? I need help ASAP!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!