Question

1. The first small program realizes the following functions: (1) The program allows input of ID...

1. The first small program realizes the following functions:

(1) The program allows input of ID (3-digit integer representation), month (1-12), revenue and record these information in file1

(2) If the ID entered by the user and the income of the corresponding month already exist in file1, remind: the income information has been entered, please do not repeat the entry

2. The second small program realizes the following functions:

(1) Calculate the tax payable for each ID in file1 in each month (12% of revenue) and record it in each line of record in file1

3. The third small program realizes the following functions

(1) Write a search function, whose parameters are ID and month, and return the tax payable

(2) Call the find function to print the tax payable according to the ID and month entered by the user

(3) Reminder if there is no ID to query in file 1 or there is no tax payable record in the corresponding month, you need to give a text reminder

Requirement:

(1) Using markdown in the jupyter file first introduces the design idea and test effect of each small program (describes the information input during the test and adds the diagram)

Please use Python Programming Language   No explicit requirements for output results

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer for your question in Python Programming Language.

NOTE : According to Chegg Policy experts are allowed to answer a max of one question when given multiple questions in a single question. Answered as per the Chegg Policy. Apologies for this.

I have answered question no.1 (1.1 & 1.2). To help you have answered part-2 also.Please check

CODE :

"""Creates a new file """
file = open("file1.txt","w+")

""" To create new record with given parameters"""
def createRecord(ID,month,revenue):
  
"""Reads and stores current file data in records"""
with open("file1.txt") as f1:
lines = f1.readlines()
records = []
for eachLine in lines:
eachRecord = []
for data in eachLine.split(" "):
eachRecord.append(data.replace("\n",""))
records.append(eachRecord)
f1.close()
  
"""Inserts new record to file"""
with open("file1.txt","a+") as f2:
for eachRecord in records:
if (str(ID) in eachRecord) and (str(revenue) in eachRecord):
print("The income information has been entered, please do not repeat the entry")
return
f2.write("{0} {1} {2}\n".format(int(ID),int(month),float(revenue)))
print("Record inserted successfully...")
print("-------------------------------")
f2.close()

"""Part - (2) : To calculate tax payable and add the tax to each record"""
def TaxPayable():
  
"""Reads and stores file data in records"""
with open("file1.txt") as f:
lines = f.readlines()
records = []
for eachLine in lines:
eachRecord = []
for data in eachLine.split(" "):
eachRecord.append(data.replace("\n",""))
records.append(eachRecord)
f.close()
  
"""Calculates taxt and replaces every line including tax"""
with open("file1.txt","w") as f1:
for eachRecord in records:
tax = float(eachRecord[2])*(0.12)
f1.write("{0} {1} {2} {3}\n".format(int(eachRecord[0]),int(eachRecord[1]),float(eachRecord[2]),float(tax)))
f1.close()

"""Asks user for data continously until user wants to exit"""
while True:
try:
print("-------------------------------------------------\n")
ID = int(input("Please enter ID (Press -1 to exit) : "))
if ID == -1:
break;
  
while (ID < 100 or ID >999):
print("ID should be three digits only")
ID = int(input("Please enter ID (Press -1 to exit) : "))
  
month = int(input("Please enter month(1-12) (Press -1 to exit) : "))
if month == -1:
break
  
while (month < 1 or month >12):
print("Please enter month between 1 and 12")
month = int(input("Please enter month(1-12) (Press -1 to exit) : "))
  
revenue = float(input("Please enter revenue (Press -1 to exit) : "))
if revenue == -1:
break
print("-------------------------------------------------")
createRecord(ID,month,revenue)
  
except ValueError:
print("Value Error : Please enter correct values..")
  
TaxPayable()

SCREENSHOTS :

Please see he screenshots of the code below for the indentations of the code.As python is a language of indentations kindly check the identations before execution.

1 9 readData.py Creates a new file 2 file = open(file1.txt, w+) 3 4 To create new record with given parameters 5 de

readData.py 31 32 Reads and stores file data in records. 33 with open(file1.txt) as f: 34 lines = f.readlines() 35 record

ID = int(input(Please enter ID (Press -1 to exit) : )) month = int(input(Please enter month(1-12) (Press -1 to exit) : ))

OUTPUT :

Please enter ID (Press -1 to exit) : 908 Please enter month (1-12) (Press -1 to exit) : 10 Please enter revenue (Press -1 toPlease enter ID (Press -1 to exit) : 567 Please enter month (1-12) (Press -1 to exit) : 5 Please enter revenue (Press -1 to e

file1.txt

file 1.txt X 1 2 3 908 10 9000.0 1080.0 789 6 9000.0 1080.0 567 5 8700.0 1044.0 678 9 7800.0 936.0 4. 5

Any douts regarding this acn be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
1. The first small program realizes the following functions: (1) The program allows input of ID...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT