Advertisement
fevzi02

Untitled

Dec 3rd, 2020
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. 7. Викторина со столицами. Напишите программу, которая создает словарь,
  3. содержащий в качестве ключей названия американских штатов и в качестве значений их столицы.
  4. (Список штатов и соответствующих им столиц можно найти в Интернете.)
  5. Затем про грамма должна провести викторину, случайным образом выводя название штата и предлагая ввести его столицу.
  6. Программа должна провести подсчет количества правильных и неправильных ответов.
  7. """
  8. import random
  9.  
  10. positive_points=0
  11. bad_points=0
  12.  
  13. dict={"District of Columbia":"Washington","Alabama":"Montgomery","Alaska":"Juneau","Arizona":"Phoenix","Arkansas":"Little Rock",
  14. "California":"Sacramento","Colorado":"Denver","Connecticut":"Hartford","Delaware":"Delaware","Florida":"Tallahassee",
  15. "Georgia":"Atlanta","Hawaii":"Honolulu","Idaho":"Boise","Illinois":"Springfield","Indiana":"Indianapolis",
  16. "Iowa":"Des Moines","Kansas":"Topeka","Kentucky":"Frankfort","Louisiana":"Baton Rouge","Maine":"Augusta",
  17. "Maryland":"Annapolis","Massachusetts":"Boston","Michigan":"Lansing","Minnesota":"Saint Paul","Mississippi":"Jackson",
  18. "Missouri":"Jefferson City","Montana":"Helena","Nebraska":"LincolnNevada","Nevada":"Carson City","New Hampshire":"Concord",
  19. "New Jersey":"Trenton","New Mexico":"Santa Fe","New York":"Albany","North Carolina":"Raleigh","North Dakota":"Bismarck",
  20. "Ohio":"Columbus","Oklahoma":"Oklahoma City","Oregon":"Salem","Pennsylvania":"Harrisburg","Rhode Island":"Providence",
  21. "South Carolina":"Columbia","South Dakota":"Pierre","Tennessee":"Nashville","Texas":"Austin","Utah":"Salt Lake City",
  22. "Vermont":"Montpelier","Virginia":"Richmond","Washington":"Olympia","West Virginia":"Charleston","Wisconsin":"Madison","Wyoming":"Cheyenne"}
  23.  
  24. list = [i for i in dict]
  25. for i in range(5):
  26.     rand = random.randint(0, len(dict)-1)
  27.     print("Штат - ",list[rand],", Введите его сталицу -",end=" ")
  28.     capital = input("")
  29.     if capital in dict.values():
  30.         for i in dict.keys():
  31.             if i == list[rand]:
  32.                 if capital == dict.get(list[rand]):
  33.                     positive_points += 1
  34.                 else:
  35.                     bad_points += 1
  36.     else:
  37.         bad_points += 1
  38.  
  39. print("Правильных ответов - ",positive_points," / | \ Неправильных ответов - ",bad_points)
  40.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement