Python uses lists and dictionaries to store information

Source: Internet
Author: User

""      White      Time: January 9, 2018      demand: Suppose you have a lot of cars, By constantly asking if you want to add a vehicle to your inventory,     if you do, then it will ask for details of the car. If not, the application prints the details of all cars and exits.      function: Loop to add information about the car and record information into the dictionary "" "Def main ():     car_list =  []    while  true:      add_inventory =  input (' Do you want to add car info? (y/n): ')       if add_inventory ==  ' y ':         car_model = input (' Please enter the model of the car: ')          car_color = input (' Please enter the color of the car: ')          car_year  = input (' Please enter the number of years of the car: ')         car_ Miles = input (' Please enter the car's kilometer: ')         car_dict={' model ': Car_ Model, ' Color ': Car_color, ' Year ': Car_year, ' Miles ': car_miles}         print (car_dict)         car_ List.append (car_dict)       elif  add_inventory ==  ' n ':         print (car_list)          breakif __name__ ==  ' __main__ ':     main ()


Python uses lists and dictionaries to store information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.