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 practice is the safest way to sit at a desk while typing on the computer?
qwelly [4]
Lol just lay back and unleash your gamer side
8 0
4 years ago
A methods and measurements analyst for Digital Devices needs to develop a time standard for the task of assembling a computer mo
Karo-lina-s [1.5K]

Answer:

34 seconds

Explanation:

Contingencies are not co soldered in the observed time because the time an individual takes to college a particular task is called observed time.

As the worker takes 34 seconds minimum to complete the task so 34 seconds is the answer.

4 0
3 years ago
Task manager is showing an application as “not responding.” what can you do?
34kurt
I think it's b because "end application" would make the most sence
8 0
4 years ago
What is qwerty and why is it on the keyboard?
Genrish500 [490]

Answer:

qwerty is the main way people sort out there keyboard as you can see on the left side of the keyboard there is W,A,S,D

Explanation:

6 0
4 years ago
Read 2 more answers
Explain what the problems with the implementation of the function are, and show a way to fix them.// return true if two C string
Nataly [62]

Answer:

The code is not dereferencing the pointers. You have to place an asterisk in front of the pointer to read the value the pointer points to.

Explanation:

So "if (str1 != str2)" must be "if (*str1 != *str2)".

likewise:

   while (*str1 != 0 && *str2 != 0)

and

     result = (*str1 == *str2);

7 0
3 years ago
Other questions:
  • Can using interior light help improve a drivers visibility at night
    9·1 answer
  • You have a subnetwork, 192.168.48.0/24. it is divided into subnet a and subnet
    8·1 answer
  • Which programming language is good for 14 year old like me​
    12·2 answers
  • How far from the bullet is text indented
    6·2 answers
  • What are some of the academic benefits of a later start time that Jordan mentions​
    12·1 answer
  • Software on your computer is taking a long time to load. What could help solve this problem?
    5·1 answer
  • What is the definition of “potential energy”?
    6·1 answer
  • What is the name of the FOLDER in which the file named "script" is contained?
    13·1 answer
  • What is another term for additive manufacturing
    7·1 answer
  • LIST THE BEST 10 3D PRINTERS WITH THEIR RESPECTIVE APPS.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!