Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("**Welcome**")
- t="y"
- while t=='y':
- print("Enter the number of opertion you want")
- print("1-Write on the file")
- print("2-Read from the file")
- print("3-search on the file")
- print("4-Copy the file")
- print("5-length of the file")
- print("6-update on the file")
- print("7-Delete from the file")
- s=int(input("Enter the number of operation you want to do "))
- match s:
- case 1:
- c="y"
- while c=='y':
- with open('carpy','w') as file:
- id = input('Enter ID: ')
- name = input('Enter Name: ')
- model = input('Enter Model: ')
- ownerofcar = input('Enter the owner of car: ')
- file.write(id + '\t' + name + '\t' + model + '\t' + ownerofcar + '\n')
- print('File saved successfully')
- c=input("Enter another record? (y/n)")
- t=input("Do you want to do anothe opertion (y/n):")
- case 2:
- with open('carpy', 'r') as file:
- print('ID\tName\tModel\tOwnerofcar')
- print('----------------------------------------')
- for line in file:
- print(line, end='')
- t = input("Do you want to do anothe opertion (y/n):")
- case 3:
- id = input('Enter the id to search for: ')
- with open('carpy', 'r') as file:
- found = False
- for line in file:
- fields = line.split('\t')
- if fields[0] == id:
- found = True
- print('ID\tName\tModel\tOwnerofcar')
- print('----------------------------------------')
- print(line)
- if not found:
- print('car not found')
- t = input("Do you want to do anothe opertion (y/n):")
- case 4:
- # your code
- t = input("Do you want to do anothe opertion (y/n):")
- case 5:
- # your code
- t = input("Do you want to do anothe opertion (y/n):")
- case 6:
- # your code
- t = input("Do you want to do anothe opertion (y/n):")
- case 7:
- # your code
- t = input("Do you want to do anothe opertion (y/n):")
- print("**THE END**")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement