Question

In: Computer Science

do not use these: {,},{} Python 3 APPL 276.75 15 A file named asset.txt consists of...

do not use these: {,},{}
Python 3

APPL

276.75

15

A file named asset.txt consists of only the three lines above. They describe the unit cost and quantity of shares of Apple stock. Write statement that open the file, read the data and use it to print this exact output:

My APPL stock is worth $4,151.25.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required. Also note that since you mentioned to not use '{}', I have formatted the currency using locale module. Otherwise it was very easy to format the currency using '${:,.2f}'

#code

# these two lines are needed for currency formatting (since you mentioned that
# you dont want to use {}, otherwise it would have been very simple)
import locale
locale.setlocale(locale.LC_ALL, '')

# opening asset.txt in read mode
file = open('asset.txt', 'r')
# reading first line as stock name
name = file.readline().strip()
# next line as unit cost, float
unit_cost = float(file.readline())
# next line as quantity, integer
quantity = int(file.readline())
# displaying the result in proper format
print("My " + name + " is worth " + str(locale.currency(unit_cost * quantity, grouping=True)) + ".")
# closing file
file.close()

Related Solutions

Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
Using Python. A file exists on the disk named students.txt. The file contains several records, and...
Using Python. A file exists on the disk named students.txt. The file contains several records, and each record contains two fields: (1) the student’s name, and (2) the student’s score for the final exam. Write code that deletes the record containing “John Perz”as the student name. This the code i have so far but it's not working: import os def main(): found=False search='John Perz' student_file = open('student.txt','r') temp_file = open('temp_students.txt','w') name=student_file.readline() score='' while name !='': score=student_file.readline() name=name.rstrip('/n') score=score.rstrip('/n') if name...
Please Use Python 3.The Problem: Read the name of a file and then open it for...
Please Use Python 3.The Problem: Read the name of a file and then open it for reading. Read the name of another file and then open it for output. When the program completes, the output file must contain the lines in the input file, but in the reverse order. • Write the input, output, and the relationship between the input and output. • Develop the test data (A single test will be alright). Make the input file at least 3...
In Python: Assume a file containing a series of integers is named numbers.txt and exists on...
In Python: Assume a file containing a series of integers is named numbers.txt and exists on the computer's Disk. Write a program that reads al the numbers stored in the file and calculates their total. - create your own text file called numbers.txt and put in a set of 20 numbers (each number should be between 1 and 100). - Each number should be on its own line. - do not assume that the file will always have 20 numbers...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the code below in the new file (you may omit the comments, I included them for explanation #Python Code Begin x = int(input("Enter a number: ")) y = int(input("Enter another number: ")) print ("Values before", "x:", x, "y:", y) #add code to swap variables here #you may not use Python libraries or built in swap functions #you must use only the operators you have learned...
Python, filing and modules Modify the driver to write the statistics to a file named employee-stats.txt...
Python, filing and modules Modify the driver to write the statistics to a file named employee-stats.txt rather than to the console. driver.py code: from employee import Employee employees = [] # Load an employee object for each employee specified in 'employees.txt' into the employees list. employee.txt Jescie Craig VP 95947 Marny Mckenzie Staff 52429 Justin Fuller Manager 72895 Herman Love VP 108204 Hasad Wilkins Staff 96153 Aubrey Eaton Staff 76785 Yvonne Wilkinson Staff 35823 Dane Carlson Manager 91524 Emma Tate...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made,...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made, convert to a float, and assign to sales. 3. Prompt the user for number of days missed, covert to an int, and assign to days_missed 4. If the user have more than 3000 of sales and has missed less than or equal to two days of work, assign bonus to 100. 5.   Else if the user have more than 3000 of sales or has missed...
Solve using PYTHON 3 and use functions. You have been hired by a restaurant named "Burger...
Solve using PYTHON 3 and use functions. You have been hired by a restaurant named "Burger Shack" Per the client, you have the following information: the client’s name, burger’s name, time of the day, and the total bill. By the end of the day, your program will provide the following information: 1. Top three best clients (highest bills) 2. Name of the client with the second-to-last lowest bill 3. Busiest hour of the day (number of clients) Assumptions: 1. doesn't...
Assignment Requirements Write a python application that consists of two .py files. One file is a...
Assignment Requirements Write a python application that consists of two .py files. One file is a module that contains functions used by the main program. NOTE: Please name your module file: asgn4_module.py The first function that is defined in the module is named is_field_blank and it receives a string and checks to see whether or not it is blank. If so, it returns True, if not it return false. The second function that is defined in the module is named...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT