Menu

[Solved]Dictphone Lst Lstappend Type Lstappend Name Lstappend Manufacturer Lstappend Year Manufact Q37155809

dict_phone = {}
lst = []
lst.append(‘Type:’)
lst.append(‘Name:’)
lst.append(‘Manufacturer:’)
lst.append(‘Year of Manufacture:’)
lst.append(‘Place of Manufacture:’)
lst.append(‘Price:’)
lst.append(‘Success:’)

def takeRecords(fName):
   dict_phone = {}
   file = open(fName,’r’)
   for line in file:
       lst = [x.strip() for x inline.rstrip().split(“,”)]
       dict_phone[lst[0]] = lst[1:]
   file.close()

   return dict_phone

def printPopular(dict_ph):
   for type in dict_ph:
       if ‘Popular’ indict_ph[type]:
           print(lst[0] +type)
           for i inrange(0, len(dict_ph[type])):
              print(lst[i+1] + dict_ph[type][i])
       print()
             
def main():
   dict_phone = takeRecords(“data2.txt”)
   what_to_do = ‘0’
   while what_to_do.lower() != ‘quit’:
       what_to_do = input()
       if what_to_do == ‘1’:
          printPopular(dict_phone)
       else:
           print(‘EnterCorrect Input.’)
   return

if __name__ == ‘__main__’:
   main()

TXT file :

1, Note 7, Samsung, 2017,`New York , 15000, Popular
3, Galaxy S10, Samsung, 2019, London, 12000, Popular
5, I phone 6s, Apple, 2016, Washington, 3000, Not Popular

How to write a function that allow user to search for a phoneand print all required information as below (If phone does notexists in dictionary then print Invalid request)

suppose search is Note 7

Type: 1

Name: Note 7

Manufacturer: Samsung

Year of Manufacture: 2017

Place of Manufacture: New York

Price: 15000

Success: Popular

Expert Answer


Answer to dict_phone = {} lst = [] lst.append(‘Type:’) lst.append(‘Name:’) lst.append(‘Manufacturer:’) lst.append(‘Year of Manufac… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *