Question

In: Computer Science

Reminder, remember to code, evaluate, save, execute (run), and check the Python program for possible errors....

Reminder, remember to code, evaluate, save, execute (run), and check the Python program for possible errors. Remember to create the sales.txt file with the following data (1000, 2000, 3000, 4000, 5000). Tip, the sales.txt file must be in the same directory as the read_sales_text_file.py Python program.

def main():

sales_file = open('sales.txt', 'r')

for line in sales_file:
amount = float(line)
print('$', format(amount, '.2f'))

sales_file.close()

main()


Output after you successfully run your code:

$ 1000.00
$ 2000.00
$ 3000.00
$ 4000.00
$ 5000.00


What you will submit:


Filename and extension: read_sales_text_file.py


Filename and extension: sales.txt


File type(s): Python and .txt


Solutions

Expert Solution

def main():

    with open('sales.txt', 'r') as sales_file:

        for line in sales_file:

            amount = float(line)

            print('$', format(amount, '.2f'))

main()


Related Solutions

In Python Find the errors, debug the program, and then execute to show the output. def...
In Python Find the errors, debug the program, and then execute to show the output. def main():     Calories1 = input( "How many calories are in the first food?")     Calories2 = input( "How many calories are in the first food?")     showCalories(calories1, calories2)    def showCalories():     print('The total calories you ate today', format(calories1 + calories2,'.2f'))
Write, save, and run a Python program Ask the user to enter a number of grams....
Write, save, and run a Python program Ask the user to enter a number of grams. Your program converts that to whole tones, then whole kilograms and whatever is left is in grams. It prints the entered grams , tones , kilograms and the remaining grams.      4 marks for i in range(0,10): print(i) 2    what is wrong in the above python code? display your explanation using print statement. mark 3    insert the following comments into your program of part...
There are logical and run time errors in the code, as well as compilation errors. **...
There are logical and run time errors in the code, as well as compilation errors. ** Your objective is get the code to run, fix any bugs in the code and ** place validation needed to prevent any memory issues. Each function has a ** description of what it does next to its prototype. ** When you find a problem, fix it in the code and note it in this header comment below. ** Please note each problem you find...
PYTHON Find anagrams of a word using recursion. This a possible run of your program: Enter...
PYTHON Find anagrams of a word using recursion. This a possible run of your program: Enter a word or empty string to finish: poster The word poster has the following 6 anagrams: presto repost respot stoper topers tropes
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
I have a python program that must check if an integer is the sum of the...
I have a python program that must check if an integer is the sum of the squares of four consecutive prime numbers. However, when I run the program, it goes into an infinite while loop, and it doesn't give me any answer. I can only use the while, if, else, True and False commands. The code I'm using is n1=2   n2=3   n3=5   n4=7   n = int(input("n: "))   if (n==(n1**2)+(n2**2)+(n3**2)+(n4**2)):     print(n1,n2,n3,n4)   else :     i = 2     pr = True     next =...
Modify this python program to print "Happy Birthday!" if today is the person's birthday. Remember that...
Modify this python program to print "Happy Birthday!" if today is the person's birthday. Remember that a person has a birthday every year. It is not likely that a newborn will wonder into a bar the day s/he is born. Your program should print "Happy Birthday!" if today's month and day are the same as the person's birthday. For example, if person is born November 3, 1984 and today is November 3, 2019, then a happy birthday message should print....
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT