You are on page 1of 6

CSD 1133 Problem Solving/Program Logic

Assignment #9-10 [4%]


Sequential Data Files

Submitted by:
Aditya Chauhan (C0796941)
For either of the exercises write:
1. Choice of Pseudo or Raptor
2. Python

Submit all files, Input file, .py, .rap if you chose Raptor instead of Pseudo. Two input files if needed separately
for Python and Raptor. Do not submit snapshots.

Question 1:
The Department of Motor Vehicles in the state of Euphoria has finally decided to computerize its list of
licensed drivers. Write a program that makes use of an existing file named "licenses" with records of the
following form:

driver_name (String), license_number (String), number_of_tickets (Integer)

The program will prompt the user to enter the license number, then it displays the corresponding driver’s
name and number of tickets.

Hint: load the "licenses" file into three parallel arrays and search one of these for the license number
input.

def reading_file():
num = input("PLEASE ENTER THE LICENSE NUMBER:")
dl_number = ['DL111', 'DL222', 'DL333', 'DL444', 'DL555']
for i in range(5):
if num == dl_number[i]:
with open('list_drivers.txt', 'r') as filehandle :
lines_to_read = [i]

for position, line in enumerate(filehandle):

if position in lines_to_read:
print(line)
break
else:
print("SORRY! NO MATCH FOUND")
print("THANKS")

def writting_file():
dl_number = ['DL111', 'DL222', 'DL333', 'DL444', 'DL555']
driver_name = ['Aditya', 'manveer', 'moksh', 'manpreet', 'harpreet']
Count_tickets = [6, 21, 1, 0, 11]
variable1 = 0
variable2 = 0
variable3 = 0
with open('list_drivers.txt','w') as filehandle:
for i in range(5):
variable1 = driver_name[i]
variable2 = dl_number[i]
variable3 = Count_tickets[i]

filehandle.write(f'License Number : {variable2}, Driver Name :


{variable1}, Number of tickets :{variable3}\n')
filehandle.close()

writting_file()
reading_file()

1. Module main()
2. Call Module file_writing()
3. Call Module file_reading()
4. End main Module
5. Module writing_file()
6. Declare DL_number as string
7. Declare driver_name as string
8. Declare count_tickets as int
9. Declare variable1 as Integer, variable 2, variable 3 as Int
10. Set DL_number = [‘DL111’, ‘DL222’, ‘DL333’, ‘DL444’, ‘DL555’]
11. Set driver_name = [‘'Aditya', 'manveer', 'moksh', 'manpreet', 'harpreet']
12. Set count_tickets = [6,21,0,11,22]
13. Open "list_drivers.txt" For Input As filehandle
14. For(i=0;i<=4;i++)
15. Set variable1 = driver_name [i]
16. Set variable2 = DL_number [i]
17. Set variable3 = count_tickets i]
18. Write filehandle, variable 1, variable 2, variable 3, ,
19. End For
20. Close filehandle
21. End file_writting Module
22. Module reading_file()
23. Declare Anum as Int
24. Print “PLEASE ENTER THE LICENSE NUMBER: “
25. Input Anum
26. For (i=0;i<=4;i++)
27. If Anum == DL_number[i] Then
28. Open "list_license.txt" For Input As filehandle
29. Set lines_to_read = [i]
30. For position, line in enumerate (filehandle)
31. If position == lines_to_read Then
32. Write line
33. End If
34. End For
35. Else
36. Print(“sorry”)
37. End If-Else
38. End file_reading Module

Question 2:

The information of credit card transactions are stored in file with the following format:
date, company, amount

Example:
15/1/2021, Best Buy, TV, $1200.54
20/1/2021, Costco, Chair, $220.37

Develop a program that reads the information of transactions from a file and calculates the total
amount of payments that are made. Then, adds the following sentence to the end of that file:

Total amount spent: $total calculated amount.

def file_reading():

file= open('credit.txt','r')
reading = f.read()
print(reading)
file.close()

def file_writting():
date = ['16-11-2020', '11-12-2021', '22-01-2021', '12-02-2021']
amount = [900.64, 240.37, 80, 46.7]
company = ['flipkart, AC ', 'myntra, clothes ', 'ccd,chocolates', 'starbucks,
hot-coffee']
variable1 = 0
variable2 = 0
variable3 = 0
total_amount = 0
file= open('credit.txt', 'w')

with open('credit.txt','w') as filehandle:


for i in range(4):
variable1 = date[i]
variable2 = company[i]
variable3 = amount[i]
total_amount += variable3
filehandle.write(file'{variable1},{variable2},${variable3}\n')
filehandle.write(file'Overall money spent: ${total_amount}.')
file.close()

file_writting()
file_reading()

Pseudocode

1. Module main()
2. Call Module file_writing()
3. Call Module file_reading()
4. End main Module
5. Module file_writing()
6. Declare date as Array
7. Declare company as Array
8. Declare amount as Array
9. Declare variable1 as Integer
10. Declare variable2 as Integer
11. Declare variable3 as Integer
12. SET date = ['16-11-2020', '11-12-2021', '22-01-2021', '12-02-2021']
13. Amount = [900.64, 240.37, 80, 46.7]
14. company = ['flipkart, AC ', 'myntra, clothes ', 'ccd,chocolates', 'starbucks, hot-coffee']
15. Open "credit.txt" For Input As filehandl
16. For(A=0;A<=3;i++
17. Set variable 1 = date[A]
18. Set variable 2 = company[A]
19. Set variable 3 = amount[A]
20. Set Amount_total = Amount_total + variable
21. write filehandle, variable 1, variable 2, variable 3
22. write filehandle total
23. End For
24. Close filehandle
25. End file_writting Module
26. Module file_reading()
27. Declare reading as Integer
28. Open “credit.txt” For read as filehandle
29. Set fileread = Read filehandle
30. print fileread
31. Close filehandle
32. End file_reading Module

You might also like