Guest User

Untitled

a guest
Jun 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.11 KB | None | 0 0
  1. userList=[]
  2. listPlaces = []
  3. listPoliticalParties=[]
  4. listBallotPresidential=[]
  5. votesCantons=[]
  6. listLegislativeElection =[]
  7. finalResults =[]
  8.  
  9. #This first menu allows to the user to register or log in
  10. def startMenu():
  11. print("1.Register\n2.Log-in")
  12. option=input("What do you want to do?:___")
  13. if option=="1":
  14. storeInformation()
  15. elif option=="2":
  16. login()
  17. else:
  18. print("Incorrect opction")
  19. startMenu()
  20.  
  21. #This method saves user's data for be registered
  22. def storeInformation():
  23. id = input("Introduce your ID:")
  24. fullName = input("Introduce your full name:")
  25. age = input("Introduce your age:")
  26. email = input("Introduce your email:")
  27. password = input("Introduce your password:")
  28. print("..........................")
  29. print("Write your type of user:\n1)Administrator\n2)Guest")
  30. option = input("Introduce your option:_____")
  31. if option == "1":
  32. kind = "Administrator"
  33. elif option == "2":
  34. kind = "Guest"
  35. else:
  36. print("Incorrect option!!\nTry again")
  37. storeInformation()
  38. print("Register completed!!!\nNow, you can log in!!\n..........................")
  39. userRegister(id, fullName, age, email, password, kind)
  40.  
  41. #This method allows to register the user
  42. def userRegister(id,fullName,age,email,password,kind):
  43. userNew = {}
  44. userNew["name"] = fullName
  45. userNew["id"] = id
  46. userNew["Kind"] = kind
  47. userNew["age"] = age
  48. userNew["email"] = email
  49. userNew["password"] = password
  50. userList.append(userNew)
  51.  
  52. #This method is to start session when the user is registered
  53. def login():
  54. userId = input("Introduce your ID:____")
  55. passwordUser = input("Introduce your password:____")
  56. for user in userList:
  57. if userId==user["id"] and passwordUser == user["password"]:
  58. print("You can login!!!\nWelcome!!!\n......................")
  59. if user["Kind"]=="Administrator":
  60. administratorsMenu()
  61. else:
  62. questions()
  63. print("You can't login.\nAccount does not exist, you need to create an account\n......................")
  64.  
  65. #This is the menu for administrators.
  66. def administratorsMenu():
  67. print("What do you want to do?:____")
  68. print("1)Territorial Distribution.\n2)Administration of political parties.\n3)Administration of ballot papers.\n4)Results.\n5)Quetions.\n6)Exit.")
  69. option = input("Introduce your option:_____")
  70. if option == "1":
  71. territorialDistribution()
  72. elif option == "2":
  73. politicalPartyAdministration()
  74. elif option == "3":
  75. ballotsAdministration()
  76. elif option == "4":
  77. results()
  78. elif option == "5":
  79. questions()
  80. elif option =="6":
  81. print("See you later!!")
  82. startMenu()
  83. else:
  84. print("Incorrect opction\nTry again !!")
  85. administratorsMenu()
  86.  
  87. #This is the menu for territorial distribution.
  88. def territorialDistribution():
  89. print("What do you want to do?\n1)Option of province.\n2)Option of cantons.\n3)Option of district.\n4)Go back to the main menu.")
  90. opcion = input("Introduce your option:_____")
  91. print("........................")
  92. if opcion == "1":
  93. menuInteractProvince()
  94. elif opcion == "2":
  95. menuInteractCantons()
  96. elif opcion == "3":
  97. menuInterctsDistrits()
  98. elif opcion=="4":
  99. administratorsMenu()
  100. else:
  101. print("Incorrect Option.\nTry again")
  102. territorialDistribution()
  103.  
  104. #This method is the menu for create, modify and delete provinces.
  105. def menuInteractProvince():
  106. print("What do you want to do?\n1)Create province.\n2)Modify province.\n3)Delete province.\n4)Go back")
  107. option = input("Introduce your option:_____")
  108. print("............................")
  109. if option == "1":
  110. createProvinceUI()
  111. elif option == "2":
  112. modifyProvince()
  113. elif option == "3":
  114. deleteProvince()
  115. elif option == "4":
  116. territorialDistribution()
  117. else:
  118. print("Incorrect option!!")
  119. menuInteractProvince()
  120.  
  121. #This method ask for the province's information for create it.
  122. def createProvinceUI():
  123. nameP = input("Introduce the name of province:______").capitalize()
  124. cuantityD =int(input("Introduce the deputy's cuantity:______"))
  125. createProvince(nameP, cuantityD)
  126.  
  127. #This method add the province at the global list
  128. def createProvince(name, diputes):
  129. newProvince = {}
  130. dataP = {}
  131. newProvince["Name"] = name
  132. newProvince["Ballot"]={}
  133. dataP["Diputes"] = diputes
  134. dataP["Cantons"] = []
  135. newProvince["Data"] = dataP
  136. listPlaces.append(newProvince)
  137. print("Province created!!\nCongratulations!!!\n......................")
  138. menuInteractProvince()
  139.  
  140. #This method modify provinces.
  141. def modifyProvince():
  142. province = input("Introduce the name of the province that you wants to modify:_________").capitalize()
  143. print("...............................")
  144. if len(listPlaces) != 0:
  145. for num in listPlaces:
  146. if num["Name"] == province:
  147. menuModifyProvince(num)
  148. print("The name of the province not exist, try again!!")
  149. modifyProvince()
  150. else:
  151. print("Not exists province, create a province,please.")
  152. menuInteractProvince()
  153.  
  154. #This is the menu for modify provinces
  155. def menuModifyProvince(num):
  156. print("What do you want to do?\n1)Modify name.\n2)Modify cuantity of deputies.\n3)Modify other province.\n4)Go back ")
  157. option = input("Introduce your option:_____")
  158. print("...........................")
  159. if option == "1":
  160. changeName(num)
  161. elif option == "2":
  162. changeCuantityDiputs(num)
  163. elif option == "3":
  164. modifyProvince()
  165. elif option == "4":
  166. menuInteractProvince()
  167. else:
  168. print("Incorrect option!!\nPlease, try again")
  169. menuModifyProvince(num)
  170.  
  171. #This method change the name of the province
  172. def changeName(num):
  173. newName = input("Introduce the new name of the province:______").capitalize()
  174. num["Name"] = newName
  175. print("Name of province was changed!!\nCongratulations!!!\n........................")
  176. menuModifyProvince(num)
  177.  
  178. #This method change the cuantity of diputes of the province
  179. def changeCuantityDiputs(num):
  180. nnewCantDiputs = int(input("Introduce the new cuantity of deputies:_____"))
  181. num["Diputs"] = nnewCantDiputs
  182. print("Cuantity of deputies was changed!!!\nCongratulations\n..........................")
  183. menuModifyProvince(num)
  184.  
  185. #Delete the province
  186. def deleteProvince():
  187. provinces = input("Introduce the name of the province that you want to eliminate:_____").capitalize()
  188. if len(listPlaces) != 0:
  189. for num in listPlaces:
  190. if num["Name"] == provinces:
  191. listPlaces.remove(num)
  192. print("Province was deleted!!!\nCongratulations!!!\n......................")
  193. menuInteractProvince()
  194. print("Name of province not exist, try again.")
  195. deleteProvince()
  196. else:
  197. print("There not province, create a province.")
  198. menuInteractProvince()
  199.  
  200. #Menu for create, modify and delete cantons.
  201. def menuInteractCantons():
  202. print("What do you want to do?\n1)Create canton.\n2)Change name of canton.\n3)Delete canton.\n4)Go back.\n.......................")
  203. opcion = input("Introduce your option:____")
  204. if opcion == "1":
  205. checkCreateCanton()
  206. elif opcion == "2":
  207. checkModifyCanton()
  208. elif opcion == "3":
  209. checkDeletCanton()
  210. elif opcion == "4":
  211. territorialDistribution()
  212. else:
  213. print("Incorrect option!! Try again.")
  214. menuInteractCantons()
  215.  
  216. #Check the name of the province in which you want to create the canton and verify that province exist
  217. def checkCreateCanton():
  218. province = input("To create canton it needs to introduce the name of the province where it belongs.\n......................\nWrite the name of the province:______").capitalize()
  219. if len(listPlaces) != 0:
  220. for num in listPlaces:
  221. if num["Name"] == province:
  222. positionC = num["Data"]
  223. createCanton(positionC)
  224. print("Name of province not exist, try again.")
  225. checkCreateCanton()
  226. else:
  227. print("There are not province, create a province.")
  228. menuInteractProvince()
  229.  
  230. #Create the canton and add the canton to the main list
  231. def createCanton(positionCanton):
  232. nameC = input("Introduce the name of canton:______").capitalize()
  233. newCanton = {}
  234. newCanton["Name"] = nameC
  235. newCanton["Distrits"] = []
  236. positionCanton["Cantons"].append(newCanton)
  237. print("Canton created!!!\nCongratulations!!!\n.........................")
  238. menuInteractCantons()
  239.  
  240. #Verify the province where is the canton for then be modified.
  241. def checkModifyCanton():
  242. if listPlaces != 0:
  243. nameP = input("Introduce the name of the province where it belongs the canton:______").capitalize()
  244. print("..............................")
  245. for num in listPlaces:
  246. if num["Name"] == nameP:
  247. positionC = num["Data"]["Cantons"]
  248. checkCanton(positionC)
  249. print("Name of province not exist, try again.")
  250. checkModifyCanton()
  251. else:
  252. print("There are not province, create a province.")
  253. menuInteractProvince()
  254.  
  255. #Check which is the canton that you want to modify and modify it.
  256. def checkCanton(positionCanton):
  257. nameC = input("Introduce the name of the canton that you wants to modify:_____").capitalize()
  258. print(".............................")
  259. for num in positionCanton:
  260. if num["Name"] == nameC:
  261. num["Name"] = input("Introduce the new name of the canton:_____")
  262. print("Name was changed!!!\nCongratulations!!!\n.........................")
  263. menuInteractCantons()
  264. print("Name of canton not exist, try again.")
  265. checkCanton(positionCanton)
  266. print("The province don't have any canton, create a canton.")
  267. menuInteractCantons()
  268.  
  269. #Verify which is the canton that you want to delete and seek it.
  270. def checkDeletCanton():
  271. if listPlaces != 0:
  272. nameP = input("Introduce the name of the province where it belongs the canton:_____").capitalize()
  273. print("............................")
  274. for num in listPlaces:
  275. if num["Name"] == nameP:
  276. placeC = num["Data"]["Cantons"]
  277. deleteCanton(placeC)
  278. print("Name of province not exist, try again.")
  279. checkDeletCanton()
  280. else:
  281. print("There are not province, create a province.")
  282. menuInteractProvince()
  283.  
  284. # Delete the cantons
  285. def deleteCanton(placeC):
  286. if len(placeC)>0:
  287. nameCanton = input("Introduce the name of the canton that you want to eliminate:_____").capitalize()
  288. for num in placeC:
  289. if num["Name"] == nameCanton:
  290. placeC.remove(num)
  291. print("Canton was eliminated!!!\nCongratulations\n......................\nNow, what do you want to do?:")
  292. menuInteractCantons()
  293. print("The canton's name is incorrect!!!")
  294. deleteCanton(placeC)
  295. else:
  296. print("The province not have any canton, create a canton.")
  297. menuInteractCantons()
  298.  
  299. # This is the menu for interact with the districts.
  300. def menuInterctsDistrits():
  301. print("What do you want to do?\n1)Create distrit.\n2)Modify name.\n3)Delete distrit.\n4)Go back.\n.........................")
  302. option = input("Introduce your option:_____")
  303. print("..........................")
  304. if option == "1":
  305. locateDistrit()
  306. elif option == "2":
  307. changeNameD()
  308. elif option =="3":
  309. deleteDistrict()
  310. elif option=="4":
  311. territorialDistribution()
  312. else:
  313. menuInterctsDistrits()
  314.  
  315. # This method allows to verify that exist provinces and cantons for create districts
  316. def locateDistrit():
  317. if len(listPlaces)!= 0:
  318. nombreP = input("Introduce the name of the province where it belongs the distrit:______").capitalize()
  319. print("............................")
  320. for positionProvince in listPlaces:
  321. if nombreP == positionProvince["Name"]:
  322. nameCanton = input("Introduce the name of the canton where it belongs the district:______").capitalize()
  323. print("........................")
  324. for positionCanton in positionProvince["Data"]["Cantons"]:
  325. if nameCanton == positionCanton["Name"]:
  326. placeD = positionCanton["Distrits"]
  327. createDistritUI(placeD)
  328. print("The canton's name is incorrect.")
  329. locateDistrit()
  330. print("The province not exist, try again.")
  331. locateDistrit()
  332. print("There are not province, create a province.")
  333. menuInteractProvince()
  334.  
  335. # User's interface for create districts
  336. def createDistritUI(lugarD):
  337. name = input("Introduce the name of the district that you want to create:_____").capitalize()
  338. print("..........................")
  339. createDistrit(lugarD,name)
  340.  
  341. #Create districts inside the cantons.
  342. def createDistrit(lugarD, name):
  343. newDistrit = {}
  344. newDistrit["Name"] = name
  345. newDistrit["PresidentialVotes"] = []
  346. newDistrit["LegislativeVotes"] = []
  347. lugarD.append(newDistrit)
  348. print("Distrit created!!")
  349. menuInterctsDistrits()
  350. createDistrit(lugarD,name)
  351.  
  352. #This method allows to change the name of the district.
  353. def changeNameD():
  354. if len(listPlaces)!=[]:
  355. provinceName = input("Introduce the name of the province where it belongs the district:______").capitalize()
  356. print(".............................")
  357. for province in listPlaces:
  358. if provinceName == province["Name"]:
  359. if province["Data"]["Cantons"]!=0:
  360. cantonName = input("Introduce the name of the canton where it belongs the district:______").capitalize()
  361. print(".........................")
  362. for canton in province["Data"]["Cantons"]:
  363. if cantonName == canton["Name"]:
  364. distritName = input("Introduce the name of the district that you want to change:______").capitalize()
  365. print("..........................")
  366. for distrit in canton["Distrits"]:
  367. if distrit["Name"]==distritName:
  368. newName=input("Write the new name of the district:______").capitalize()
  369. distrit["Name"]=newName
  370. print("The district was changed!!!\nCongratulations!!!")
  371. print(".............................")
  372. menuInterctsDistrits()
  373. print("District's name is incorrect!!Try again, please")
  374. changeNameD()
  375. print("Canton's name is incorrect!!")
  376. changeNameD()
  377. print("There are not cantons in the province")
  378. print("The province not exist\nTry again")
  379. changeNameD()
  380. else:
  381. print("There are not province.")
  382. menuInteractProvince()
  383.  
  384. #This function allows to delete a distric if user wants.
  385. def deleteDistrict():
  386. eliminatedistric=input("Introduce the name of the district that you want to delete:______").capitalize()
  387. print(".........................")
  388. for province in listPlaces:
  389. for canton in province["Data"]["Cantons"]:
  390. for district in canton["Distrits"]:
  391. if district["Name"]==eliminatedistric:
  392. canton["Distrits"].remove(district)
  393. print("The district was deleted!!!\nCongratulations!!!\n...........................")
  394. menuInterctsDistrits()
  395. print("The district not exist.\nTry again.")
  396. deleteDistrict()
  397. menuInterctsDistrits()
  398.  
  399. # This is the menu for political parties administration.
  400. def politicalPartyAdministration():
  401. print("What do you want to do?:\n1)Create political party.\n2)Modify political party.\n3)Delete political party.\n4)Go back to the main menu.\n......................")
  402. option = input("Introduce your option:____")
  403. print("........................")
  404. if option == "1":
  405. createPartyUI()
  406. elif option == "2":
  407. modifyParty()
  408. elif option == "3":
  409. deleteParty()
  410. elif option == "4":
  411. administratorsMenu()
  412.  
  413. # Create political parties(Graphics interface).
  414. def createPartyUI():
  415. nameP = input("Introduce the initials of the political party:_____").upper()
  416. dateFundation = int(input("Introduce date's fundation of political party:_____"))
  417. colorP = input("Introduce the color of the political party:_____")
  418. ideology = input("Introduce the ideology of the political party:_____")
  419. createParty(nameP, dateFundation, colorP, ideology,votes=0)
  420.  
  421. #Create political parties(Logical interface).
  422. def createParty(name, date, color, ideology,votes):
  423. dataP = {}
  424. newParty = {}
  425. newParty["NameP"] = name
  426. newParty["Votes"]=0
  427. dataP["Date"] = date
  428. dataP["Color"] = color
  429. dataP["Ideology"] = ideology
  430. newParty["Data"] = dataP
  431. listPoliticalParties.append(newParty)
  432. print("Political party was added!!!\nCongratulations!!!\n......................")
  433. politicalPartyAdministration()
  434.  
  435. # Modify political parties menu.
  436. def modifyParty():
  437. print("What do you want to do?:\n1)Modify political party.\n2)Go back.")
  438. opcion = input("Introduce your option:_____")
  439. print("............................")
  440. if opcion == "1":
  441. nameP = input("Introduce the initials of the political party that you want to modify:______").upper()
  442. print("..........................")
  443. i = 0
  444. while i <= len(listPoliticalParties):
  445. if nameP == listPoliticalParties[i]["NameP"]:
  446. menuModifyParty[i]
  447. i += 1
  448. print("The name of the political party is incorrect or does not exist.")
  449. modifyParty()
  450. elif opcion == "2":
  451. politicalPartyAdministration()
  452.  
  453. #This is the menu for modify information of the political party.
  454. def menuModifyParty(position):
  455. print("1)Modify the name. \n2)Modify fundation's date.\n3)Modify the color. \n4)Modify th ideology.\n5)Go back.")
  456. option = input("Introduce your option:_____")
  457. print("...........................")
  458. if option == "1":
  459. newName = input("Introduce the new name of the political party:_____").upper()
  460. listPoliticalParties[position]["Name"] = newName
  461. menuModifyParty(position)
  462. elif option == "2":
  463. newDate = int(input("Introduce the new foundation's date of the political party:_____"))
  464. print("..............................")
  465. listPoliticalParties[position]["Data"]["Date"] = newDate
  466. menuModifyParty(position)
  467. elif option == "3":
  468. newColor = input("Introduce the new color of the political party:_____")
  469. print("...............................")
  470. listPoliticalParties[position]["Data"]["Color"] = newColor
  471. menuModifyParty(position)
  472. elif option == "4":
  473. newIdeology = input("Introduce the new ideology of the political party:_____")
  474. print("............................")
  475. listPoliticalParties[position]["Data"]["Ideology"] = newIdeology
  476. menuModifyParty(position)
  477. elif option == "5":
  478. politicalPartyAdministration()
  479.  
  480. #Delete the political party.
  481. def deleteParty():
  482. if listPoliticalParties != []:
  483. nameParty = input("Introduce the initials of the political party:_____").upper()
  484. print("..............................")
  485. for party in listPoliticalParties:
  486. if nameParty == party["NameP"]:
  487. print("Party was deleted!!\nCongratulations!!!\n........................")
  488. politicalPartyAdministration()
  489. print("Party's name is incorrect!!\nTry again\n........................")
  490. deleteParty()
  491. print("There are not political parties")
  492. politicalPartyAdministration()
  493.  
  494. #Administration of ballots Menu
  495. def ballotsAdministration():
  496. print("What do you want to do?\n1)Create Ballot.\n2)Delete Ballot\n3)Modify Ballot.\n4)Go back.")
  497. option = input("Introduce your option:_____")
  498. print("...........................")
  499. if option == "1":
  500. if len(listPoliticalParties) != 0:
  501. createBallotsUI()
  502. print("There are not political parties.\nYou need to create a political party\n.......................")
  503. politicalPartyAdministration()
  504. elif option == "2":
  505. deleteBallots()
  506. elif option == "3":
  507. modifyBallots()
  508. elif option == "4":
  509. administratorsMenu()
  510. else:
  511. ballotsAdministration()
  512.  
  513. #This method calls the funtion of create ballots
  514. def createBallotsUI():
  515. listPoliticalPartiesBallots = []
  516. createBallots(listPoliticalPartiesBallots)
  517.  
  518. #This method add political parties to the ballots, legislative or presidential. Also print the list of political parties that exist.
  519. def createBallots(listPoliticalPartiesBallots):
  520. print("Do you want to add a political party to the ballot?")
  521. print("List of political parties:")
  522. for nameParty in listPoliticalParties:
  523. print(nameParty["NameP"])
  524. print("1)Yes\n2)No")
  525. option = input("Introduce your option:")
  526. print(".........................")
  527. if option == "1":
  528. namePartyAdd = input("Introduce the name of the political party:_____").upper()
  529. for politicalParty in listPoliticalParties:
  530. if namePartyAdd == politicalParty["NameP"]:
  531. listPoliticalPartiesBallots.append(politicalParty)
  532. print(listPoliticalPartiesBallots)
  533. createBallots(listPoliticalPartiesBallots)
  534. print("Political party not exist!!! Try again")
  535. createBallots(listPoliticalPartiesBallots)
  536. elif option == "2":
  537. if len(listPoliticalPartiesBallots) != 0:
  538. print("What type of ballot is?")
  539. print("1)Presidential\n2)Legislative")
  540. option2 = input("Introduce your option:____")
  541. print(".........................")
  542. if option2 == "1":
  543. listBallotPresidential.append(listPoliticalPartiesBallots)
  544. print("Political ballot was created!!!\nCongratulations!!!\n..........................")
  545. ballotsAdministration()
  546. elif option == "2":
  547. print("What province do you want to add to the ballot?")
  548. nameProvince = input("Introduce the name of the province:_____").capitalize()
  549. for province in listPlaces:
  550. if nameProvince == province["Name"]:
  551. province["Ballot"] = listPoliticalPartiesBallots
  552. print("Political ballot was created!!!\nCongratulations!!!\n........................")
  553. ballotsAdministration()
  554. else:
  555. print("Province not exist!! Try again\n.......................")
  556. createBallots(listPoliticalPartiesBallots)
  557. print("You need to add at least a political party to the ballot.\nAdd a political party to the ballot, please.")
  558. createBallotsUI()
  559. else:
  560. print("Incorrect option!!! Try again\n..........................")
  561. createBallotsUI()
  562.  
  563. #This method allows to modify the ballots.
  564. def modifyBallots():
  565. modifyballot=input("What kind of ballot do you want to modify?\n1)Legislative\n2)Presidential\n3)Go back\nChoose your option:____")
  566. print("..........................")
  567. if modifyballot=="1":
  568. print("What do you want to do?:_____\n.............................")
  569. option=input("1)Add more political parties to the ballot\n2)Delete political parties of the ballot\n3)Go back\n.............................\nIntroduce your option:_____")
  570. if option=="1":
  571. place=input("Write the name of the province where is the ballot:_____").capitalize()
  572. print("...........................")
  573. for province in listPlaces:
  574. if place==province["Name"]:
  575. if province["Ballot"] != []:
  576. newBallot=province["Ballot"]
  577. addPoliticalPartytoBallot(newBallot)
  578. else:
  579. print("Ballot not exist in the province. Please,create a ballot\n.......................")
  580. ballotsAdministration()
  581. print("Name of province is incorrect.Try again!!")
  582. modifyBallots()
  583. elif option=="2":
  584. deletePoliticalPartyBallot()
  585. elif option == "3":
  586. ballotsAdministration()
  587. else:
  588. print("Incorrect option.Try again!!")
  589. modifyBallots()
  590. elif modifyballot=="2":
  591. if listBallotPresidential!= []:
  592. modifyPresidencialBallot()
  593. else:
  594. print("Presidential ballot not exist. Please, create a ballot")
  595. ballotsAdministration()
  596. elif modifyballot=="3":
  597. ballotsAdministration()
  598. else:
  599. print("Empty list")
  600.  
  601. #This method allows to add political parties to the legislative ballot.
  602. def addPoliticalPartytoBallot(newBallot):
  603. print("Do you want to add political parties to the ballot?")
  604. print("List of political parties is:")
  605. for nameParty in listPoliticalParties:
  606. print(nameParty["NameP"])
  607. print("1)Yes\n2)No")
  608. option = input("Introduce your option:_____")
  609. if option == "1":
  610. namePartyAdd = input("Introduce the initials of the political party:").upper()
  611. for politicalParty in listPoliticalParties:
  612. if namePartyAdd == politicalParty["NameP"]:
  613. print("Political party was removed!!\nCongratulations!!!\n......................")
  614. newBallot.append(politicalParty)
  615. modifyBallots()
  616. print("Political party not exist.Try again\nWrite the initials of the political party.")
  617. elif option == "2":
  618. modifyBallots()
  619. else:
  620. print("Incorrect option\nTry again!!\n.......................")
  621.  
  622. #This method allows to remove political parties of the legislative ballot.
  623. def deletePoliticalPartyBallot():
  624. place = input("Write the name of the province where is the ballot:_____").capitalize()
  625. print(".........................")
  626. for province in listPlaces:
  627. if place == province["Name"]:
  628. if province["Ballot"]!=[]:
  629. print("List of political parties is:")
  630. for nameParty in province["Ballot"]:
  631. print(nameParty["NameP"])
  632. delete = input("Write the initials of the political party that you want to eliminate:_____").upper()
  633. for party in province["Ballot"]:
  634. if delete==party["NameP"]:
  635. province["Ballot"].remove(party)
  636. print("Political party was eliminated\nCongratulations!!!\n........................")
  637. modifyBallots()
  638. else:
  639. print("Ballot not exist in the province\nPlease, you need to create a ballot")
  640. ballotsAdministration()
  641. print("Name of province is incorrect.\nTry again")
  642. modifyBallots()
  643.  
  644. #This method allows to delete as much as the legislative ballot like the presidential ballot
  645. def deleteBallots():
  646. print("What kind of ballot do you want to delete?\n1)Presidential.\n2)Legislative.")
  647. option = input("Choose your option:___")
  648. print("...........................")
  649. if option =="1":
  650. if len(listBallotPresidential) ==[]:
  651. print("There are not presidential ballot.\nYou need to create a presidential ballot.\n........................")
  652. ballotsAdministration()
  653. else:
  654. print("There are not presidential ballot.\nYou need to create a presidential ballot.\n........................")
  655. ballotsAdministration()
  656. listBallotPresidential.clear()
  657. print("Ballot was deleted!!\nCongratulations!!!\n........................")
  658. ballotsAdministration()
  659. elif option == "2":
  660. print("For delete legislative ballot, you need to write the name of the province where is the ballot.")
  661. nameProvince=input("Write the name of the province where is the ballot:______").capitalize()
  662. for province in listPlaces:
  663. if nameProvince == province["Name"]:
  664. if len(province["Ballot"]) != 0:
  665. province["Ballot"] = []
  666. print("Delete ballot!!\nCongratulations!!!\n...........................")
  667. print(listPlaces)
  668. ballotsAdministration()
  669. else:
  670. print("There are not ballot in the province.\nCreate a ballot, please", province["Name"])
  671. ballotsAdministration()
  672. print("Province not exist.Try again\n..........................")
  673. deleteBallots()
  674. else:
  675. print("Incorrect option.Try again.\n..........................")
  676. ballotsAdministration()
  677.  
  678. #This method allows to modify the presidential ballot.
  679. def modifyPresidencialBallot():
  680. print("What do you want to do?:\n........................")
  681. option = input("1)Add more political parties to the ballot\n2)Delete political parties of the ballot\n3)Go back\nIntroduce your option:_____")
  682. print("...............................")
  683. if option == "1":
  684. print("List of political parties is:")
  685. for nameParty in listPoliticalParties:
  686. print(nameParty["NameP"])
  687. namePartyAdd = input("Introduce the initials of the political party:_____").upper()
  688. for politicalParty in listPoliticalParties:
  689. if namePartyAdd == politicalParty["NameP"]:
  690. listBallotPresidential.append(politicalParty)
  691. print(listBallotPresidential)
  692. print("Political party was added successfully\nCongratulations!!!\n.......................")
  693. modifyBallots()
  694. print("Party's name is incorrect!! Try again, please.\n..........................")
  695. if option=="2":
  696. print("List of political parties is:")
  697. for nameParty in listBallotPresidential:
  698. print(nameParty["NameP"])
  699. politicalParty = input("Write the initials of the political party for eliminate it:_____").upper()
  700. for party in listBallotPresidential:
  701. if politicalParty==party["NameP"]:
  702. listBallotPresidential.remove(party)
  703. print("Political party was eliminated successfully\nCongratulations!!!\n..........................")
  704. modifyBallots()
  705. else:
  706. print("Incorrect option.Try again, please.")
  707. modifyPresidencialBallot()
  708.  
  709. #Menu of results. This method allows to edit the presidential results or legislative results..
  710. def results():
  711. print("What do you want to do?:\n1)To edit presidential results.\n2)To edit legislative results.\n3)Go back.\n........................")
  712. option = input("Introduce your option:_____")
  713. print(".............................")
  714. if option == "1":
  715. if listBallotPresidential != []:
  716. if len(listPlaces)!= 0:
  717. print("It's necessary to save the voting results by district.")
  718. nameProvince = input("Write the name of the province where the district is located:_____").capitalize()
  719. for province in listPlaces:
  720. if province["Name"] == nameProvince:
  721. if province["Data"]["Cantons"] != 0:
  722. nameCanton = input("Write the name of the canton where the district is located:_____").capitalize()
  723. for canton in province["Data"]["Cantons"]:
  724. if nameCanton == canton["Name"]:
  725. if canton["Distrits"] != 0:
  726. nameDistrict = input("Write the name of the district that you want to edit the results:_____").capitalize()
  727. for district in canton["Distrits"]:
  728. if nameDistrict == district["Name"]:
  729. presidentialResults(district)
  730. print("The district's name is incorrect.Try again, please!!.")
  731. results()
  732. print("There are not districts in the canton.\n.......................")
  733. results()
  734. print("The canton's name is incorrect.\nTry again, please!!\n.......................")
  735. results()
  736. print("There are not cantons in the province.\nTry again, please\n......................")
  737. results()
  738. print("The province's name is incorrect\nTry again.")
  739. results()
  740. print("There are not province\nYou need to create a province.\n..........................")
  741. results()
  742. print("There are not presidential ballot.")
  743. results()
  744. elif option =="2":
  745. if len(listPlaces) != 0:
  746. print("It is necessary to save the voting results by district.")
  747. nameProvince = input("Write the name of the province where the district is located:_____").capitalize()
  748. for province in listPlaces:
  749. if province["Name"] == nameProvince:
  750. if province["Ballot"]!=[]:
  751. if province["Data"]["Cantons"] != 0:
  752. nameCanton = input("Write the name of the canton where the district is located:_____").capitalize()
  753. for canton in province["Data"]["Cantons"]:
  754. if nameCanton == canton["Name"]:
  755. if canton["Distrits"] != 0:
  756. nameDistrict = input("Write the name of the district that you want to edit the results:_____").capitalize()
  757. for district in canton["Distrits"]:
  758. if nameDistrict == district["Name"]:
  759. legislativeResults(province,district)
  760. print("The district's name is incorrect\nTry again, please.\n....................")
  761. results()
  762. print("There are not districts in the canton.\n......................")
  763. results()
  764. print("The canton's name is incorrect.\nTry again, please!!\n.....................")
  765. results()
  766. print("There are not cantons in the province.\n......................")
  767. results()
  768. print("There are not legislative ballot.\n........................")
  769. results()
  770. print("The province's name is incorrect\nTry again, please!!\n.....................")
  771. results()
  772. print("There are not province\nYou need to create a province.\n..........................")
  773. results()
  774. elif option == "3":
  775. administratorsMenu()
  776. else:
  777. print("Incorrect option!!!\n Try again.")
  778. results()
  779.  
  780. #Edit the results of the presidentials votes.
  781. def legislativeResults(province,district):
  782. newResults = {}
  783. print("The ballot is:")
  784. for party in province["Ballot"]:
  785. cantVotes = int(input("How many votes for "+ party["NameP"]+" ?:_____"))
  786. newResults[party["NameP"]]= cantVotes
  787. district["LegislativeVotes"].append(newResults)
  788. results()
  789.  
  790. #Edit the results of the legislatice votes.
  791. def presidentialResults(district):
  792. print("The ballot is:")
  793. for party in listBallotPresidential[0]:
  794. newResults = {}
  795. cantVotes = int(input("How many votes for " + party["NameP"] + " ?:_____"))
  796. newResults["Name"] = party["NameP"]
  797. newResults["Votes"] = cantVotes
  798. district["PresidentialVotes"].append(newResults)
  799. results()
  800.  
  801. #Menu of questions
  802. def questions():
  803. votesCantons.clear()
  804. print("What do you want to do?\n1) National results of the presidential election.\n2) Provincial results of the presidential election\n3) Cantonal results of the presidential election\n4) District results of the presidential election\n5) Results of the legislative election\n6) Exit")
  805. option = input("Introduce your option:______")
  806. print("..........................")
  807. if option =="1":
  808. nationalResultsElectionsUI()
  809. elif option =="2":
  810. presidentialProvince()
  811. elif option == "3":
  812. presidentialCantons()
  813. elif option == "4":
  814. presidentialDistricts()
  815. elif option== "5":
  816. legislativeElection()
  817. elif option=="6":
  818. print("See you later!!")
  819. exit()
  820. else:
  821. print("Incorrect option!!!! Try again, please\n........................")
  822.  
  823. #Locate the canton in the list, seek it and verify in case that canton not exist or misspelled.
  824. def presidentialCantons():
  825. if len(listPlaces) !=0:
  826. nameProvince = input("Introduce the province's name:_____").capitalize()
  827. for province in listPlaces:
  828. if province["Name"] == nameProvince:
  829. if province["Data"]["Cantons"]!=0:
  830. nameCanton = input("Introduce the canton's name:_____").capitalize()
  831. for canton in province["Data"]["Cantons"]:
  832. if nameCanton == canton["Name"]:
  833. cantonVotes = canton["Distrits"]
  834. presidentialCantonsUI(cantonVotes)
  835. print("Canton's name is incorrect\nTry again, please.\n..........................")
  836. questions()
  837. print("There are not cantons")
  838. questions()
  839. print("The province's name is incorrect\nTry again, please.\n.........................")
  840. questions()
  841. print("There are not provinces.")
  842. questions()
  843.  
  844. #Add to the global list the political parties that exist.
  845. def presidentialCantonsUI(canton):
  846. for nameParty in listBallotPresidential[0]:
  847. party ={}
  848. party["Name"]= nameParty["NameP"]
  849. party["Votes"]= 0
  850. votesCantons.append(party)
  851. addVotesCantons(canton)
  852.  
  853. #With the help of the previous method,this method sum all the votes of every party, saved in the global list previous mentioned.
  854. def addVotesCantons(canton):
  855. for district in canton:
  856. for party in district["PresidentialVotes"]:
  857. for partyLocated in votesCantons:
  858. if partyLocated["Name"] == party["Name"]:
  859. partyLocated["Votes"] += party["Votes"]
  860. printResultsPresidentialCantons()
  861.  
  862. #Print the results of the canton's elections.
  863. def printResultsPresidentialCantons():
  864. totalVotes=0
  865. print("The cuantity of votes are:")
  866. print("Party's name: Votes cuantity:")
  867. for party in votesCantons:
  868. print(party["Name"] + " " + str(party["Votes"]))
  869. totalVotes+= party["Votes"]
  870. print("Total Votes: " + str(totalVotes) + "\n.......................")
  871. print("The percentage are:")
  872. print("Party's name: Percentage:")
  873. for party in votesCantons:
  874. percentageParty = (party["Votes"] * 100) / totalVotes
  875. print(party["Name"] + " " + str(percentageParty) + "%")
  876. print(".......................")
  877. questions()
  878.  
  879. # Ask for the district for know the results.
  880. def presidentialDistricts():
  881. if len(listPlaces)!=0:
  882. nameProvince = input("Introduce the province's name:______").capitalize()
  883. print(".........................")
  884. for province in listPlaces:
  885. if province["Name"] == nameProvince:
  886. if province["Data"]["Cantons"]!=0:
  887. nameCanton = input("Introduce the canton's name:_____")
  888. for canton in province["Data"]["Cantons"]:
  889. if nameCanton == canton["Name"]:
  890. if canton["Distrits"]!=0:
  891. nameDistrict = input("Introduce the district's name:______").capitalize()
  892. for district in canton["Distrits"]:
  893. if nameDistrict == district["Name"]:
  894. presidentialVotes = district["PresidentialVotes"]
  895. resultPresidentialDistrictsUI(presidentialVotes)
  896. print("The district's name is incorrect\nTry again\n........................")
  897. questions()
  898. print("There are not districts in the canton\nTry again\n...........................")
  899. questions()
  900. print("The canton's name is incorrect")
  901. questions()
  902. print("There are not cantons in the province\nTry again\n.......................")
  903. questions()
  904. print("The province's name is incorrect")
  905. print("There are not province. You need to create a province.\nTry again\n........................")
  906. questions()
  907.  
  908. #Print the votes of every political party by district and print the total votes.
  909. def resultPresidentialDistrictsUI(presidentialVotes):
  910. totalVotes =0
  911. print("The cuantity of votes are:")
  912. print("Party's name: Votes cuantity:")
  913. for party in presidentialVotes:
  914. print(party["Name"]+" "+str(party["Votes"]))
  915. totalVotes+= party["Votes"]
  916. print("Total Votes: " +str(totalVotes)+"\n.......................")
  917. print("The percentage are:")
  918. print("Party's name: Percentage:")
  919. for party in presidentialVotes:
  920. percentageParty = (party["Votes"]*100)/totalVotes
  921. print(party["Name"]+" "+str(percentageParty)+"%")
  922. questions()
  923.  
  924. #Add to the global list the political parties that exist.
  925. def nationalResultsElectionsUI():
  926. for nameParty in listBallotPresidential[0]:
  927. party ={}
  928. party["Name"]= nameParty["NameP"]
  929. party["Votes"]= 0
  930. votesCantons.append(party)
  931. addVotesCountry()
  932.  
  933. #Sum all the votes of every political party saved in the global list.
  934. def addVotesCountry():
  935. for province in listPlaces:
  936. for canton in province["Data"]["Cantons"]:
  937. for district in canton["Distrits"]:
  938. for party in district["PresidentialVotes"]:
  939. for partyLocated in votesCantons:
  940. if partyLocated["Name"] == party["Name"]:
  941. partyLocated["Votes"] += party["Votes"]
  942. printnationalResultsElections()
  943.  
  944. #Print the results of the nationals elections.
  945. def printnationalResultsElections():
  946. totalVotes = 0
  947. print("The cuantity of votes are:")
  948. print("Party's name: Votes cuantity:")
  949. for party in votesCantons:
  950. print(party["Name"] + " " + str(party["Votes"]))
  951. totalVotes += party["Votes"]
  952. print("Total Votes: " + str(totalVotes) + "\n.......................")
  953. print("The percentage are:")
  954. print("Party's name: Percentage:")
  955. for party in votesCantons:
  956. percentageParty = (party["Votes"] * 100) / totalVotes
  957. print(party["Name"] + " " + str(percentageParty) + "%")
  958. print(".....................")
  959. questions()
  960.  
  961. #Locate the province for add the votes to the province
  962. def presidentialProvince():
  963. if listPlaces != []:
  964. nameProvince = input("Introduce the province's name:_____").capitalize()
  965. for province in listPlaces:
  966. if province["Name"]==nameProvince:
  967. addVotesProvinceListUI(province)
  968. print("Province's name is incorrect\nTry again\n..........................")
  969. presidentialProvince()
  970. print("There are not province. You need to create a province\nTry again\n...........................")
  971. questions()
  972.  
  973. #Create a dictionary in the general list, also named votesCantos, where the votes will saved.
  974. def addVotesProvinceListUI(province):
  975. for nameParty in listBallotPresidential[0]:
  976. party = {}
  977. party["Name"] = nameParty["NameP"]
  978. party["Votes"] = 0
  979. votesCantons.append(party)
  980. addVotesProvinceList(province)
  981.  
  982. #Add the canton's votes to the global list of votes.
  983. def addVotesProvinceList(province):
  984. for canton in province["Data"]["Cantons"]:
  985. for district in canton["Distrits"]:
  986. for party in district["PresidentialVotes"]:
  987. for partyLocated in votesCantons:
  988. if partyLocated["Name"] == party["Name"]:
  989. partyLocated["Votes"] += party["Votes"]
  990. printResultsPresidentialProvince()
  991.  
  992. #Print the results of the presidential election.
  993. def printResultsPresidentialProvince():
  994. totalVotes=0
  995. print("The cuantity of votes are:")
  996. print("Party's name: Cuantity of votes:")
  997. for party in votesCantons:
  998. print(party["Name"]+" "+str(party["Votes"]))
  999. totalVotes+=party["Votes"]
  1000. print("Total Votes: "+str(totalVotes)+"\n...........................")
  1001. print("The percentage are:")
  1002. print("Party's name: Percentage:")
  1003. for party in votesCantons:
  1004. percentageParty = (party["Votes"] * 100) / totalVotes
  1005. print(party["Name"] + " " + str(percentageParty) + "%")
  1006. questions()
  1007.  
  1008. #This method add a province to the legislative global list with the most important information.
  1009. def legislativeElection():
  1010. for province in listPlaces:
  1011. newResults={}
  1012. newResults["Province"]=province["Name"]
  1013. newResults["Diputs"]= province["Data"]["Diputes"]
  1014. totalParties(province,newResults)
  1015. resultsLegislativeElection()
  1016.  
  1017. #Create a list with the political parties of the ballot in the province and the results of the votes are added him.
  1018. def totalParties(province,newResults):
  1019. votesProvince=[]
  1020. for nameParty in province["Ballot"]:
  1021. party = {}
  1022. party["Name"] = nameParty["NameP"]
  1023. party["Votes"] = 0
  1024. party["Cont"]=0
  1025. votesProvince.append(party)
  1026. addVotesToList(votesProvince,province,newResults)
  1027.  
  1028. #It adds all the votes of the political party and adds the provinces with the most important information to the global list.
  1029. def addVotesToList(votesProvince,province,newResults):
  1030. for canton in province["Data"]["Cantons"]:
  1031. for district in canton["Distrits"]:
  1032. for party in district["LegislativeVotes"]:
  1033. for partyLocated in votesProvince:
  1034. if partyLocated["Name"] == party[partyLocated["Name"]]:
  1035. partyLocated["Votes"] += party["Votes"]
  1036. newResults["Parties"]=votesProvince
  1037. listLegislativeElection.append(newResults)
  1038.  
  1039. #Edit the list mentioned in the previous functions with the number of deputies that each political party can take.
  1040. def resultsLegislativeElection():
  1041. print(listLegislativeElection)
  1042. for province in listLegislativeElection:
  1043. totalVotes=0
  1044. for party in province["Parties"]:
  1045. totalVotes+=party["Votes"]
  1046. originalDeputy = province["Diputs"]
  1047. ratio = totalVotes/province["Diputs"]
  1048. while province["Diputs"]>0:
  1049. i=0
  1050. while i<len(province["Parties"]) and province["Diputs"]!=0:
  1051. if province["Parties"][i]["Votes"]>=ratio:
  1052. province["Parties"][i]["Cont"]+=1
  1053. province["Parties"][i]["Votes"]-=ratio
  1054. province["Diputs"]-=1
  1055. else:
  1056. i+=1
  1057. if province["Diputs"] !=0 :
  1058. if ratio == (totalVotes/originalDeputy)/2:
  1059. nameP= definWinnerLastDeputy(province)
  1060. for party in province["Parties"]:
  1061. if nameP ==party["Name"]:
  1062. party["Cont"]+=1
  1063. province["Diputies"]-=1
  1064. elif ratio == totalVotes/originalDeputy:
  1065. ratio= ratio/2
  1066. printFinalsResultsProvintial()
  1067.  
  1068. #Determine which match the last candidate takes by the simple majority method.
  1069. def definWinnerLastDeputy(province):
  1070. i=0
  1071. mayor=0
  1072. while i< len(province["Parties"]):
  1073. if mayor==0:
  1074. mayor= province["Parties"][i]["Votes"]
  1075. i+=1
  1076. if province["Parties"][i]["Votes"]>mayor:
  1077. mayor= provine[i]["Votes"]
  1078. i+=1
  1079. i+=1
  1080. for party in province["Parties"]:
  1081. if party["Votes"]==mayor:
  1082. return (party["Name"])
  1083.  
  1084. #Prints the final result of the legislative elections, by province.
  1085. def printFinalsResultsProvintial():
  1086. print("The results are:")
  1087. for province in listLegislativeElection:
  1088. print("......................\n"+province["Province"])
  1089. print("Party's name: Cuantity of deputies:")
  1090. for party in province["Parties"]:
  1091. print(party["Name"]+" "+str(party["Cont"]))
  1092. addResultsLegislativeConformation()
  1093.  
  1094. #It seeks the political parties to add the deputies' cuantity obtained for every party in the global list.
  1095. def addResultsLegislativeConformation():
  1096. for province in listLegislativeElection:
  1097. for party in province["Parties"]:
  1098. createListTemporal(party)
  1099. addDeputes()
  1100.  
  1101. #Add political parties to the global list and verify that the political parties does not be repeated.
  1102. def createListTemporal(party):
  1103. if votesCantons==[]:
  1104. newParty={}
  1105. newParty["Name"]=party["Name"]
  1106. newParty["Cont"]=0
  1107. votesCantons.append(newParty)
  1108. elif votesCantons!=0:
  1109. can = True
  1110. for nameParty in votesCantons:
  1111. if nameParty["Name"]==party["Name"]:
  1112. can= False
  1113. if can!=False:
  1114. newParty = {}
  1115. newParty["Name"] = party["Name"]
  1116. newParty["Cont"] = 0
  1117. votesCantons.append(newParty)
  1118.  
  1119. # Add deputies to the global list in position of parties:
  1120. def addDeputes():
  1121. for province in listLegislativeElection:
  1122. for party in province["Parties"]:
  1123. for partyLocated in votesCantons:
  1124. if partyLocated["Name"] == party["Name"]:
  1125. partyLocated["Cont"] += party["Cont"]
  1126. printFinalsResultsLegislativeConformation()
  1127.  
  1128. # Print the constitution of the legislative assembly.
  1129. def printFinalsResultsLegislativeConformation():
  1130. print("....................\n....................")
  1131. print("The constitution of Legislative Assembly is:")
  1132. print("Party's name: Cuantity of deputies:")
  1133. for party in votesCantons:
  1134. print(party["Name"] + " " + str(party["Cont"]))
  1135. print("....................\n....................")
  1136. questions()
  1137.  
  1138. startMenu()
Add Comment
Please, Sign In to add comment