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
You can access various sites on the WWW by using hyperlinks or by______. A. entering a key word for your search B. following dir
saw5 [17]
The correct answer is C
8 0
3 years ago
Read 2 more answers
There is a feature that allows you to lock the document, to avoid others making changes. True or False
Burka [1]

Answer:

yes there is

Explanation:

6 0
3 years ago
A cell has an unlimited number of conditions for Conditional Formatting.<br> A.true<br> B.false
Mekhanik [1.2K]
I believe the answer is false.
I Hope this helps! :)
If you don't understand plz message me
If you do plz brainlest
Thank you!
7 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
Which new development in malware caused sandbox technology to automate and introduce artificial intelligence learning
Karo-lina-s [1.5K]

AI-driven attacks caused sandbox technology to automate and introduce artificial intelligence learning. AI and machine learning can be used to fight against malware attacks.

<h3>Artificial intelligence, machine learning, and malware</h3>

Artificial intelligence (AI) refers to the ability of a PC to perform tasks done by humans due to the requirement of discernment.

Machine learning is a subdivision of (AI) based on the use of data and algorithms to mimic human learning.

Malware is malicious software generated by cybercriminals, which are capable of stealing unauthorized information.

Learn more about malware here:

brainly.com/question/399317

4 0
2 years ago
Other questions:
  • Which of the following is considered to be intellectual property?
    9·1 answer
  • When Lisa purchased her house the mortgage lender required homeowners insurance to cover 100% of the loan amount. After many yea
    7·2 answers
  • When you copy a formula that contains an absolute reference to a new location, the reference ____. a. has a dotted outline in it
    6·1 answer
  • Write a program that asks for the names of three runners and the time, in minutes (no seconds, etc.), it took each of them to fi
    7·1 answer
  • How can you stretch or skew an object in paint
    12·2 answers
  • Implement a metho d to nd the k-th largest element in an array of size N using a minimum priority queue (MinPQ). Assume that the
    8·1 answer
  • WILL MARK BRAINLIEST FOR ANYONES ANSWER!
    12·1 answer
  • What are the main dimensions of information system and their components
    13·1 answer
  • Help pweeze this is due today :(<br><br> I will give u brainliest just pweeze, I need this answer :(
    8·1 answer
  • A(n) ________ will clear all user data and setting changes, returning the device's software to the state it was in when it left
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!