Advertisement
sherry_ahmos

Untitled

May 16th, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. print("**Welcome**")
  2. t="y"
  3. while t=='y':
  4.     print("Enter the number of opertion you want")
  5.     print("1-Write on the file")
  6.     print("2-Read from the file")
  7.     print("3-search on the file")
  8.     print("4-Copy the file")
  9.     print("5-length of the file")
  10.     print("6-update on the file")
  11.     print("7-Delete from the file")
  12.     s=int(input("Enter the number of operation you want to do "))
  13.     match s:
  14.         case 1:
  15.             c="y"
  16.             while c=='y':
  17.                 with open('carpy','w') as file:
  18.                         id = input('Enter ID: ')
  19.                         name = input('Enter Name: ')
  20.                         model = input('Enter Model: ')
  21.                         ownerofcar = input('Enter the owner of car: ')
  22.                         file.write(id + '\t' + name + '\t' + model + '\t' + ownerofcar + '\n')
  23.                         print('File saved successfully')
  24.                 c=input("Enter another record? (y/n)")
  25.             t=input("Do you want to do anothe opertion (y/n):")
  26.         case 2:
  27.             with open('carpy', 'r') as file:
  28.                 print('ID\tName\tModel\tOwnerofcar')
  29.                 print('----------------------------------------')
  30.                 for line in file:
  31.                     print(line, end='')
  32.             t = input("Do you want to do anothe opertion (y/n):")
  33.         case 3:
  34.             id = input('Enter the id to search for: ')
  35.             with open('carpy', 'r') as file:
  36.                 found = False
  37.                 for line in file:
  38.                     fields = line.split('\t')
  39.                     if fields[0] == id:
  40.                         found = True
  41.                         print('ID\tName\tModel\tOwnerofcar')
  42.                         print('----------------------------------------')
  43.                         print(line)
  44.                 if not found:
  45.                     print('car not found')
  46.             t = input("Do you want to do anothe opertion (y/n):")
  47.         case 4:
  48.             # your code
  49.             t = input("Do you want to do anothe opertion (y/n):")
  50.         case 5:
  51.             # your code
  52.             t = input("Do you want to do anothe opertion (y/n):")
  53.         case 6:
  54.             # your code
  55.             t = input("Do you want to do anothe opertion (y/n):")
  56.         case 7:
  57.             # your code
  58.             t = input("Do you want to do anothe opertion (y/n):")
  59. print("**THE END**")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement