Guest User

Untitled

a guest
Jun 7th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.75 KB | None | 0 0
  1. registeredUsers=[[{"name":"Jose","age":18,"email":"josebermudez.com","ID":1234,"password":"1234"}],[{"name":"Fidel","age":18,"email":"fidel.com","ID":12345,"password":"1234"}]]
  2. country = []
  3. politicalParties =[]
  4. PresidentialBallot=[]
  5.  
  6. provintialVotes=[]
  7. cantonVotes=[]
  8. totalVotes=[]
  9.  
  10. #Main menu method
  11. def menu():
  12. print("Welcome \nWhat do you want to do? ")
  13. print("1)Sing in \n2)Log in\n3)exit")
  14. option=int(input("Select an option"))
  15. if option == 1:
  16. print("**************")
  17. menuForAdminOrInvited()
  18. elif option == 2:
  19. print("**************")
  20. logIn()
  21. else:
  22. print("Good bye")
  23. exit()
  24.  
  25.  
  26. #method to register as admin
  27. def singInUserAdmin():
  28. newUser = {}
  29. name=input("Your name.")
  30. newUser["name"]=name
  31. age=int(input("Your age."))
  32. newUser["age"]=age
  33. email=input("Your email.")
  34. newUser["email"]=email
  35. ID=int(input("Your ID."))
  36. newUser["ID"]=ID
  37. password =input("Your password.")
  38. newUser["password"]=password
  39.  
  40.  
  41. # método para verificar si el usuario ya está registrado
  42. def verfyUserAdmin():
  43. for user in registeredUsers[0]:
  44. if user["ID"] != ID:
  45. registeredUsers[0].append(newUser)
  46. print(registeredUsers)
  47. menu()
  48. else:
  49. print("**************")
  50. print("You're already signed in.\nEnter your ID and password")
  51. logIn()
  52. verfyUserAdmin()
  53.  
  54. #Method to register as a guest
  55. def singInUserGuest():
  56. newUser = {}
  57. name=input("Your name.")
  58. newUser["name"]=name
  59. age=int(input("Your age."))
  60. newUser["age"]=age
  61. email=input("Your email.")
  62. newUser["email"]=email
  63. ID=int(input("Your ID."))
  64. newUser["ID"]=ID
  65. password =input("Your password.")
  66. newUser["password"]=password
  67. verfyUserGuest()
  68. # método para verificar si el usuario ya está registrado
  69. def verfyUserGuest():
  70. for user in registeredUsers[1]:
  71. if user["ID"]!=ID:
  72. registeredUsers[1].append(newUser)
  73. menu()
  74. else:
  75. print("**************")
  76. print("You're already signed in.\nEnter your ID and password")
  77. logIn()
  78.  
  79. verfyUserGuest()
  80.  
  81. #method to choose to be admin or guest
  82. def menuForAdminOrInvited():
  83. print("What kind of user do you want to be")
  84. print("1)Admin \n2)Guest")
  85. option = int(input("Select an option"))
  86. if option == 1:
  87. singInUserAdmin()
  88. elif option == 2:
  89. singInUserGuest()
  90.  
  91. #Method to login
  92. def logIn():
  93. ID = int(input("Type your ID."))
  94. password = input("Type your password.")
  95. i = 0
  96. while i < len(registeredUsers):
  97. for user in registeredUsers[i]:
  98. if user["ID"] == ID:
  99. for user in registeredUsers[i]:
  100. if user["password"] == password:
  101. if i == 0:
  102. adminMenu()
  103.  
  104. elif i == 1:
  105. guestMenu()
  106.  
  107.  
  108. print("Your password is incorrect. Try again.")
  109. logIn()
  110.  
  111. else:
  112. i += 1
  113. print("You ID is incorrect. Try again.")
  114. menu()
  115.  
  116. #method of admins menu
  117. def adminMenu():
  118. #tratar de compilar con ID
  119. print("Welcome:")
  120. print("What do you want to do?\n"
  121. "1)Territorial distribution.\n"
  122. "2)Administration of political parties.\n"
  123. "3)Administration of ballots.\n"
  124. "4)Results.\n"
  125. "5)Queries\n"
  126. "6)Exit")
  127.  
  128. option = input("What is your option?: ")
  129. if option == "1":
  130. ditribuctionMenu()
  131. elif option == "2":
  132. politicalMenu()
  133. elif option == "3":
  134. menuBallots()
  135. elif option == "4":
  136. menuVotes()
  137. elif option == "5":
  138. menuQueriesAdmin()
  139. elif option == "6":
  140. print("Good bye.")
  141. print("**************")
  142. menu()
  143. else:
  144. print("Type a valid option")
  145. print("**************")
  146. adminMenu()
  147.  
  148. #guest menu method
  149. def guestMenu ():
  150. print("Welcome:")
  151. print("What do you want to do?\n"
  152. "1)Queries.\n"
  153. "2)Exit")
  154. option = input("What is your option?")
  155. if option == "1":
  156. menuQueriesGuest()
  157. elif option == "2":
  158. print("Good bye.")
  159. print("**************")
  160. menu()
  161. else:
  162. print("Type a valid option")
  163. print("**************")
  164. guestMenu()
  165.  
  166. #Territorial distribution menu
  167. def ditribuctionMenu():
  168. print("What do you want to do?")
  169. print("1)Add provinces, cantons or districts.\n"
  170. "2)Modify provinces, cantons or districts.\n"
  171. "3)Remove provinces, cantons or districts.\n"
  172. "4)Exit")
  173. option = input("Enter your option: ")
  174. if option =="1":
  175. creationPCDMenu()
  176. elif option =="2":
  177. modifyMenu()
  178. elif option == "3":
  179. menuDelete()
  180. elif option =="4":
  181. print("**************")
  182. adminMenu()
  183. else:
  184. print("Type a valid option")
  185. print("**************")
  186.  
  187. #Creation method of Province Canton District
  188. def creationPCDMenu():
  189. print("What do you want to create?")
  190. print("1)Province.\n"
  191. "2)Canton.\n"
  192. "3)District.\n"
  193. "4)Exit")
  194. option = input("Enter your option:")
  195. if option == "1":
  196. print("**************")
  197. createProvince()
  198. elif option == "2":
  199. print("**************")
  200. createCanton()
  201. elif option == "3":
  202. print("**************")
  203. createDistrict()
  204. elif option == "4":
  205. print("**************")
  206. ditribuctionMenu()
  207. else:
  208. print("Type a valid option")
  209. print("**************")
  210. creationPCDMenu()
  211.  
  212. #Territorial distribution methods
  213. def createProvince():
  214. newProvince={}
  215. nameProvince=input("Enter the name of the province: ")
  216. newProvince["Province"]=nameProvince
  217. newProvince["Ballots"]=[]
  218. numberOfDeputies= int(input("Type the number of deputies: "))
  219. newProvince["Deputies"]=numberOfDeputies
  220. newProvince["Cantons"] = []
  221. country.append(newProvince)
  222. print("The province was created successfully.")
  223. print("**************")
  224. ditribuctionMenu()
  225.  
  226. #Method to create canton
  227. def createCanton():
  228. nameProvince = input("To which province you want to add cantons?")
  229. for province in country:
  230. if nameProvince == province["Province"]:
  231. newCanton={}
  232. nameCanton=input("Enter the name of the canton")
  233. newCanton["Name"]=nameCanton
  234. newCanton["Districts"]= []
  235. province["Cantons"].append(newCanton)
  236. print("The canton was created successfully.")
  237. print("**************")
  238. print(country)
  239. ditribuctionMenu()
  240. print("The province does not exist or its name is misspelled.")
  241. createCanton()
  242.  
  243. #method to create district
  244. def createDistrict():
  245. nameProvince = input("To which province you want to add districts?: ")
  246. for province in country:
  247. if nameProvince == province["Province"]:
  248. nameCanton = input("To which canton you want to add districts?: ")
  249. for canton in province["Cantons"]:
  250. if nameCanton ==canton["Name"]:
  251. newDictrict = {}
  252. newDictrict["VotesPB"]=[]
  253. newDictrict["VotesLB"] = []
  254. nameDistrict = input("Enter the name of the district: ")
  255. newDictrict["Name"] = nameDistrict
  256. canton["Districts"].append(newDictrict)
  257. print("The district was created successfully.")
  258. print("**************")
  259. print(country)
  260. ditribuctionMenu()
  261. print("The canton does not exist or its name is misspelled")
  262. createDistrict()
  263. print("The province does not exist or its name is misspelled.")
  264. createDistrict()
  265.  
  266. #Method to modify Cantonese and District Parties
  267. def modifyMenu():
  268. print("What do you want do?\n1)Modify Province.\n2)Modify Canton.\n3)Modify District.\n4)Exit.")
  269. option=input("Enter your option: ")
  270. if option == "1":
  271. print("**************")
  272. modifyProvince()
  273. elif option == "2":
  274. print("**************")
  275. modifyCanton()
  276. elif option == "3":
  277. print("**************")
  278. modifyDistritcs()
  279. elif option == "4":
  280. print("**************")
  281. ditribuctionMenu()
  282. else:
  283. print("Type a valid option")
  284. print("**************")
  285. modifyMenu()
  286.  
  287. #method to modify provinces
  288. def modifyProvince():
  289. print("What do you want to modify?\n1)Name.\n2)Number of deputies.\n3)Exit.")
  290. option = input("Enter your option: ")
  291. if option == "1":
  292. province = input("Enter the name of the province you want to modify: ")
  293. i=0
  294. while i < len(country):
  295. if province == country[i]["Province"]:
  296. newName = input("Enter the new name of the province: ")
  297. country[i]["Province"] = newName
  298. print("The name of the province was successfully changed.")
  299. print("**************")
  300. modifyMenu()
  301.  
  302. i+=1
  303. print("**************")
  304. print("The name of the province is incorrect or not exist.Try again.")
  305. modifyProvince()
  306.  
  307. elif option == "2":
  308. province = input("Enter the name of the province you want to modify: ")
  309. i=0
  310. while i < len(country):
  311. if province == country[i]["Province"]:
  312. numberDeputies = int(input("Enter the new number of deputies."))
  313. country[i]["Deputies"] = numberDeputies
  314. print("The number of deputies was successfully changed.")
  315. print("**************")
  316. modifyMenu()
  317. i+=1
  318. print("**************")
  319. print("The name of the canton is incorrect or not exist.Try again.")
  320. modifyProvince()
  321.  
  322. elif option == "3":
  323. print("Good bye.")
  324. print("**************")
  325. modifyMenu()
  326.  
  327. else:
  328. print("Type a valid option")
  329. print("**************")
  330. modifyProvince()
  331.  
  332. #method to modify cantons
  333. def modifyCanton():
  334. province=input("To which province does the canton you wish to modify belong?: ")
  335. i = 0
  336. while i < len(country):
  337. if province == country[i]["Province"]:
  338. canton = input("Enter the name of the canton: ")
  339. j=0
  340. while j < len(country[i]["Cantons"]):
  341. if canton == country[i]["Cantons"][j]["Name"]:
  342. nameCanton = input("Enter the new name of the canton: ")
  343. country[i]["Cantons"][j]["Name"] = nameCanton
  344. print(country)
  345. print("The name of the canton was successfully changed.")
  346. print("**************")
  347. modifyMenu()
  348. j+=1
  349. print("**************")
  350. print("The name of the canton is incorrect or not exist.Try again.")
  351. modifyMenu()
  352. i += 1
  353. print("**************")
  354. print("The name of the province is incorrect or not exist.Try again.")
  355. modifyMenu()
  356.  
  357. #method to modify district
  358. def modifyDistritcs():
  359. nameProvince = input("To which province does the district you wish to modify belong?: ")
  360. for province in country:
  361. if province["Province"] == nameProvince:
  362. nameCanton = input("To which canton does the district you wish to modify belong?: ")
  363. for canton in province["Cantons"]:
  364. if nameCanton == canton["Name"]:
  365. nameDistrict = input(" Type the name of the district you want to modify: ")
  366. for district in canton["Districts"]:
  367. if nameDistrict == district["Name"]:
  368. newName= input("Enter the new name of the district: ")
  369. district["Name"] = newName
  370. print(country)
  371. print("The name of the district was successfully changed.")
  372. print("**************")
  373. modifyMenu()
  374. print("**************")
  375. print("The name of the district is incorrect or not exist.Try again.")
  376. modifyMenu()
  377. print("**************")
  378. print("The name of the canton is incorrect or not exist.Try again.")
  379. modifyMenu()
  380. print("**************")
  381. print("The name of the province is incorrect or not exist.Try again.")
  382. modifyMenu()
  383.  
  384. #Delete Menu
  385. def menuDelete():
  386. print(" What do you want to delete?\n1)Province\n2)Canton\n3)District\n4)exit ")
  387. option=input("Enter your opcion: ")
  388. if option == "1":
  389. deleteProvince()
  390. elif option =="2":
  391. deleteCanton()
  392. elif option=="3":
  393. deleteDistricts()
  394. elif option =="4":
  395. ditribuctionMenu()
  396. else:
  397. print("Your option is in valid\nTry again")
  398. menuDelete()
  399.  
  400. #Method that eliminates the provinces
  401. def deleteProvince():
  402. nameProvince=input("Enter the name of the province you want to delete: ")
  403. i=0
  404. while i < len(country):
  405. if nameProvince== country[i]["Province"]:
  406. country.remove(country[i])
  407. print("**************")
  408. print("His province was successfully eliminated")
  409. i+=1
  410. print("Your province does not exist")
  411. menuDelete()
  412.  
  413. #Method to eliminate the cantons
  414. def deleteCanton():
  415. nameProvince = input("Enter the name of the province where the canton you want to delete is located: ")
  416. for province in country:
  417. if province["Province"] == nameProvince:
  418. nameCanton = input("Enter the name of the canton you want to delete: ")
  419. for canton in province["Cantons"]:
  420. if canton["Name"] == nameCanton:
  421. province["Cantons"].remove(canton)
  422. print("**************")
  423. print("The name of the canton is incorrect or not exist.Try again.")
  424. menuDelete()
  425. print("**************")
  426. print("The name of the province is incorrect or not exist.Try again.")
  427. menuDelete()
  428.  
  429. #method to eliminate districts
  430. def deleteDistricts():
  431. nameProvince = input("Enter the name of the province where the canton you want to delete is located: ")
  432. for province in country:
  433. if province["Province"] == nameProvince:
  434. nameCanton = input("Enter the name of the canton where the canton you want to delete is located: ")
  435. for canton in province["Cantons"]:
  436. if canton["Name"] == nameCanton:
  437. nameDistrict = input("Enter the name of the district you want to delete: ")
  438. for district in canton["Districts"]:
  439. if nameDistrict == district["Name"]:
  440. canton["Districts"].remove(district)
  441. print(country)
  442. print("**************")
  443. print("The name of the district is incorrect or not exist.Try again.")
  444. menuDelete()
  445. print("**************")
  446. print("The name of the canton is incorrect or not exist.Try again.")
  447. menuDelete()
  448. print("**************")
  449. print("The name of the province is incorrect or not exist.Try again.")
  450. menuDelete()
  451.  
  452. #method of menu of political parties
  453. def politicalMenu ():
  454. print("**************")
  455. print("What do you want to do?\n1)Create a Political Party.\n2)Modify a Political Paty.\n3)Delete a Political Party.\n4)Exit")
  456. option = input("Enter your option: ")
  457. if option =="1":
  458. createPoliticalParty()
  459. elif option == "2":
  460. menuModifyPP()
  461. elif option == "3":
  462. deletePP()
  463. elif option == "4":
  464. print("**************")
  465. adminMenu()
  466. else:
  467. print("Type a valid option")
  468. print("**************")
  469. politicalMenu()
  470.  
  471. #method to create political parties
  472. def createPoliticalParty():
  473. politicalP={}
  474. namePoliticalP=input("Write the name of the political party you want to create: ")
  475. for name in politicalParties:
  476. if namePoliticalP == name["Name"]:
  477. print("There is already a political party with that name")
  478. createPoliticalParty()
  479. politicalP["Name"]=namePoliticalP
  480. yearF=input("Enter the year of creating the political party: ")
  481. politicalP["Foundation"]=yearF
  482. colors=input("Enter the all colors of the political party: ")
  483. politicalP["Colors"]=colors
  484. ideology=input("What is the ideology of the political party?: ")
  485. politicalP["Idelogy"]=ideology
  486. politicalParties.append(politicalP)
  487. print(politicalParties)
  488. print("Your political party was created successfully")
  489. print("**************")
  490. print("Want to create another Political Party\n1)Yes\n2)No")
  491. option=input("Enter your option")
  492. if option=="1":
  493. print("**************")
  494. createPoliticalParty()
  495. elif option=="2":
  496. politicalMenu()
  497. else:
  498. print("Invalid option will be sent to the previous menu")
  499. politicalMenu()
  500.  
  501. #Method that modifies political partiess
  502. def menuModifyPP():
  503. if len(politicalParties) > 0:
  504. print("**************")
  505. print(" What do you want to do: ")
  506. print("1) Modify name of political Party\n2) Modify the year of foundation\n3) Modify the colors of the political party\n4) Modify the ideology of the political party\n5) Exit")
  507. option=input("Enter you option: ")
  508. if option=="1":
  509. modifyNamePoliticalParty()
  510. elif option=="2":
  511. modifyFPoliticalParty()
  512. elif option=="3":
  513. modifyColorsPoliticalParty()
  514. elif option=="4":
  515. modifyIdeologyPoliticalParty()
  516. elif option=="5":
  517. print("**************")
  518. politicalMenu()
  519. else:
  520. print("Type a valid option")
  521. print("**************")
  522. menuModifyPP()
  523. print("**************")
  524. print("The list is empty. You must add political parties.")
  525. politicalMenu()
  526.  
  527. #Method that changes the name of the political party
  528. def modifyNamePoliticalParty():
  529. namePP=input("Enter the name of the political party you want to modify: ")
  530. i=0
  531. while i < len(politicalParties):
  532. if namePP==politicalParties[i]["Name"]:
  533. newNamePP=input("Enter the new name of the political party: ")
  534. politicalParties[i]["Name"]=newNamePP
  535. print("The name was successfully changed")
  536. print("**************")
  537. print("You want to change the name of another political party\n1)Yes\n2)No")
  538. option=input("Enter your option")
  539. if option=="1":
  540. modifyNamePoliticalParty()
  541. elif option =="2":
  542. print("**************")
  543. menuModifyPP()
  544.  
  545. i+=1
  546. print("**************")
  547. print("The political party that you introduced does not exist or is badly written, try again")
  548. modifyNamePoliticalParty()
  549.  
  550. #method that changes the foundation of the political party
  551. def modifyFPoliticalParty():
  552. namePP=input("Enter the name of the political party that wants to change the foundation: ")
  553. i=0
  554. while i < len(politicalParties):
  555. if namePP==politicalParties[i]["Name"]:
  556. newNameFPP=input("Enter the new year of foudation: ")
  557. politicalParties[i]["Foundation"]=newNameFPP
  558. print("Foudation was successfully changed")
  559. print("**************")
  560. print("Want to change the foundation of another political party\n1)Yes\n2)No")
  561. option=input("Enter your option")
  562. if option=="1":
  563. modifyFPoliticalParty()
  564. elif option =="2":
  565. print("**************")
  566. menuModifyPP()
  567. i+=1
  568. print("**************")
  569. print("The political party that you introduced does not exist or is badly written, try again")
  570. modifyFPoliticalParty()
  571.  
  572. #Method that changes the colors of the political party
  573. def modifyColorsPoliticalParty():
  574. namePP=input("Enter the name of the political party that wants to change the colors: ")
  575. i=0
  576. while i < len(politicalParties):
  577. if namePP==politicalParties[i]["Name"]:
  578. newNameColorsPP=input("Enter the new colors of political party: ")
  579. politicalParties[i]["Colors"]=newNameColorsPP
  580. print("The colors was successfully changed")
  581. print("**************")
  582. print("Want to change the colors of another political party\n1)Yes\n2)No")
  583. option=input("Enter your option")
  584. if option=="1":
  585. modifyColorsPoliticalParty()
  586. elif option =="2":
  587. print("**************")
  588. menuModifyPP()
  589.  
  590. i+=1
  591. print("**************")
  592. print("The political party that you introduced does not exist or is badly written, try again")
  593. modifyColorsPoliticalParty()
  594.  
  595. #method that changes the ideology of the political party
  596. def modifyIdeologyPoliticalParty():
  597. if len(politicalParties) > 0:
  598. namePP=input("Enter the political party that wishes to change the ideology: ")
  599. i=0
  600. while i < len(politicalParties):
  601. if namePP==politicalParties[i]["Name"]:
  602. newNameIdeologyPP=input("Enter the new ideology of political party: ")
  603. politicalParties[i]["Ideology"]=newNameIdeologyPP
  604. print("The ideology was successfully changed")
  605. print("**************")
  606. print("Want to change the ideology of another political party?\n1)Yes\n2)No")
  607. option=input("Enter your option")
  608. if option=="1":
  609. modifyIdeologyPoliticalParty()
  610. elif option =="2":
  611. print("**************")
  612. menuModifyPP()
  613. i+=1
  614. print("**************")
  615. print("The political party that you introduced does not exist or is badly written, try again")
  616. modifyIdeologyPoliticalParty()
  617. print("**************")
  618. print("The list is empty. You must add political parties.")
  619. politicalMenu()
  620.  
  621. #method to eliminate political parties
  622. def deletePP():
  623. if len(politicalParties) > 0:
  624. namePP = input("Enter the name of the political party you want to delete: ")
  625. i = 0
  626. while i < len(politicalParties):
  627. if namePP == politicalParties[i]["Name"]:
  628. politicalParties.remove(politicalParties[i])
  629. print("The political party was successfully eliminated.")
  630. print("**************")
  631. print("Do you want to eliminate another political party?\n1)Yes\n2)No")
  632. option = input("Enter your option")
  633. if option == "1":
  634. deletePP()
  635. elif option == "2":
  636. print("**************")
  637. menuModifyPP()
  638. i += 1
  639. print("The name of the political party is badly written or does not exist. Try again.")
  640. print("**************")
  641. deletePP()
  642. print("**************")
  643. print("The list is empty. You must add political parties.")
  644. politicalMenu()
  645.  
  646. #Ballot menu
  647. def menuBallots():
  648. print("**************")
  649. print("What would you like to do")
  650. print("1)Create ballot\n2)Modify ballot\n3)Delete a ballot\n4)exit")
  651. option=input("Enter your option")
  652. if option=="1":
  653. menuCreateBallots()
  654. elif option=="2":
  655. menuModifyBallots()
  656. elif option=="3":
  657. menuDeleteBallots()
  658. elif option=="4":
  659. adminMenu()
  660. else:
  661. print("Your option is invalid\nTry again")
  662. menuBallots()
  663.  
  664. #ballot creation menu
  665. def menuCreateBallots():
  666. print("**************")
  667. print("What would you like to do?")
  668. print("1)Create presidential ballot\n2)Create legislative ballot\n3)Exit")
  669. option=input("Enter your option")
  670. if option=="1":
  671. ballotPresidentialCreate()
  672. elif option=="2":
  673. requeritProvince()
  674. elif option=="3":
  675. menuBallots()
  676. else:
  677. print("Your option is invalid.\n Try again ")
  678. menuCreateBallots()
  679.  
  680. #Method to print list of matches
  681. def PrintList():
  682. print("**************")
  683. print("List of political parties")
  684. i=0
  685. while i < len(politicalParties):
  686. print("Name:"+politicalParties[i]["Name"])
  687. i+=1
  688.  
  689. #Method that creates the presidential ballot
  690. def ballotPresidentialCreate():
  691. PrintList()
  692. print("**************")
  693. name = input("Enter one by one the political parties that you want to add: ")
  694. for ballot in politicalParties:
  695. if name == ballot["Name"]:
  696. PresidentialBallot.append(ballot)
  697. print("Want to add another political party\n1)Yes\n2)No")
  698. option=input("Enter your Option: ")
  699. if option=="1":
  700. ballotPresidentialCreate()
  701. elif option=="2":
  702. menuCreateBallots()
  703. else:
  704. print("Option invalid\nYou will be sent to the previous menu")
  705. menuCreateBallots()
  706. else:
  707. print("The political party does not exist\nYou want to create it\n1)Yes\n2)No")
  708. option=input("Enter your option")
  709. if option=="1":
  710. createPoliticalParty()
  711. elif option=="2":
  712. menuCreateBallots()
  713. else:
  714. print("Your option is invalid\nIt will be sent to the previous menu")
  715. menuCreateBallots()
  716.  
  717. #Method to request a province
  718. def requeritProvince():
  719. namePro = input("Enter the name of the province to which you want to add the ballot: ")
  720. ballotLegislativeCreate(namePro)
  721.  
  722. #Method to create legislative paper
  723. def ballotLegislativeCreate(namePro):
  724. for province in country:
  725. if namePro in province["Province"]:
  726. if province["Ballots"]==[]:
  727. addNewPP(namePro)
  728. print("The ballot already exists, you can only modify it\nIt will be sent to the previous menu")
  729. menuCreateBallots()
  730. print("The name of the province is incorrect or not exist.Try again.")
  731. menuCreateBallots()
  732. # metodo para añadir ms de un partido a la papeleta legislativa
  733. def addNewPP(namePro):
  734. PrintList()
  735. for province in country:
  736. if namePro == province["Province"]:
  737. nameParty = input("Enter the name of the political party you want to add to the ballot: ")
  738. if province["Ballots"] == []:
  739. for party in politicalParties:
  740. if nameParty == party["Name"]:
  741. province["Ballots"].append(party)
  742. print(province)
  743. print("Political party successfully added\nWant to add another political party\n1)Yes\n2)No")
  744. option = input("Enter your option: ")
  745. if option == "1":
  746. addNewPP(namePro)
  747. elif option == "2":
  748. menuCreateBallots()
  749. else:
  750. print("Your option is invalid\nIt will be sent to the previous menu")
  751. menuCreateBallots()
  752. print("The name of political party is incorrect.")
  753. menuCreateBallots()
  754. else:
  755. for pp in province["Ballots"]:
  756. if nameParty == pp["Name"]:
  757. print("You can not add the political party because it already exists on the ballot.\nThe only thing you can do is modify the ballot.")
  758. print("Do you want to add another political party?\n1)Yes\n2)No")
  759. option = input("Enter your option: ")
  760. if option == "1":
  761. addNewPP(namePro)
  762. elif option =="2":
  763. menuCreateBallots()
  764. else:
  765. print("Your option is invalid\nIt will be sent to the previous menu")
  766. menuCreateBallots()
  767. for party in politicalParties:
  768. if nameParty == party["Name"]:
  769. province["Ballots"].append(party)
  770. print(province)
  771. print("Political party successfully added\nWant to add another political party\n1)Yes\n2)No")
  772. option = input("Enter your option: ")
  773. if option == "1":
  774. addNewPP(namePro)
  775. elif option == "2":
  776. menuCreateBallots()
  777. else:
  778. print("Your option is invalid\nIt will be sent to the previous menu")
  779. menuCreateBallots()
  780. print("The name of political party is incoerrect.")
  781. menuCreateBallots()
  782.  
  783. #Method that modifies the ballot, first the ecnuentra in the ballot that is indicated, the ballot is positioned in a key and this in turn is in the province the part to modify will be to add a match to the pepleta created
  784. def menuModifyBallots():
  785. print(" What do you want to do ?")
  786. print("1)Modify presidential ballot\n2)Modify legislative ballot.\n3)Exit")
  787. option= input("Enter your option")
  788. if option=="1":
  789. modifyPresidentialBallot()
  790. elif option=="2":
  791. requeritModifyBallots()
  792. elif option =="3":
  793. menuBallots()
  794. else:
  795. print("Invalid option\nwill be sent to the previous menu")
  796. menuBallots()
  797.  
  798. #This method sends the name of the province where the created ballot is located
  799. def requeritModifyBallots():
  800. namePro=input("Enter the name of the province where the created ballot is located: ")
  801. for province in country:
  802. if namePro == province["Province"]:
  803. print("What would you like to do\n1)Remove Political Party in ballot\n2)Modify political party in ballot.\n3)Exit")
  804. option=input("Enter your option")
  805. if option=="1":
  806. modifyBallotsLegislativeRemove(namePro)
  807. elif option=="2":
  808. modifyBallotlegislative(namePro)
  809. elif option =="3":
  810. menuModifyBallots()
  811. else:
  812. print("Option invalid\nWill be sent to the previous menu")
  813. menuModifyBallots()
  814. print("Province incorrect")
  815. menuModifyBallots()
  816.  
  817. #This method removes the political party that was admitted, which is on the legislative ballot
  818. def modifyBallotsLegislativeRemove(namePro):
  819. for province in country:
  820. if namePro==province["Province"]:
  821. for ballots in province["Ballots"]:
  822. printLB(namePro)
  823. nameParty=input("Enter the political party you want to modify")
  824. if nameParty==ballots["Name"]:
  825. province["Ballots"].remove(ballots)
  826. print("The political party has been successfully removed")
  827. print("want to remove some other political party\n1)Yes\n2)No")
  828. option2=input("Enter Your Option")
  829. if option2=="1":
  830. modifyBallotsLegislativeRemove(namePro)
  831. elif option2=="2":
  832. menuModifyBallots()
  833. print("Province that is incorrect")
  834. menuModifyBallots()
  835.  
  836. #This method changes a political party of the pepeleta by the political party typed by the user
  837. def modifyBallotlegislative(namePro):
  838. for province in country:
  839. if namePro==province["Province"]:
  840. for ballots in province["Ballots"]:
  841. printLB(namePro)
  842. nameParty=input("Enter the political party you want to modify: ")
  843. if nameParty==ballots["Name"]:
  844. PrintList()
  845. newParty=input("Enter the new political party you want to add")
  846. for party in politicalParties:
  847. if newParty==party["Name"]:
  848. province["Ballots"].append(party)
  849. print("The political party has been successfully added")
  850. print("want to add another political party\n1)Yes\n1)No")
  851. option =input("Enter your option: ")
  852. if option == "1":
  853. modifyBallotlegislative(namePro)
  854. elif option == "2":
  855. menuModifyBallots()
  856. else:
  857. print("The province does not exist, or is badly written.")
  858. menuModifyBallots()
  859.  
  860. #MENU MODIFY THE PRESIDENTIAL PAPER
  861. def modifyPresidentialBallot():
  862. print("What would you like to do\n1)Add a new political party\n2)Eliminate a political party\n3)Exit")
  863. option=input("Enter your option: ")
  864. if option=="1":
  865. modifyPresidentialBallotADD()
  866. elif option=="2":
  867. removePartyPB()
  868. elif option=="3":
  869. menuModifyBallots()
  870. else:
  871. print("Invalid option\nwill be sent to the previous menu")
  872. modifyPresidentialBallot()
  873.  
  874.  
  875. #method that adds a political party to the presidential ballot
  876. def modifyPresidentialBallotADD():
  877. PrintList()
  878. nameParty=input("Enter the name of political party you want to add: ")
  879. for Party in politicalParties:
  880. if nameParty == Party["Name"]:
  881. if len(PresidentialBallot) == []:
  882. for Party4 in politicalParties:
  883. if nameParty == Party4["Name"]:
  884. PresidentialBallot.append(Party4)
  885. print("The name of political party is incoerrect or not exist.")
  886. modifyPresidentialBallotADD()
  887. else:
  888. for Party2 in PresidentialBallot:
  889. if nameParty==Party2["Name"]:
  890. print("The political party is already on the ballot")
  891. print("Do you want to add some other political party?\n1) Yes\n2)No")
  892. option=input("Enter your option: ")
  893. if option=="1":
  894. modifyPresidentialBallotADD()
  895. elif option=="2":
  896. modifyPresidentialBallot()
  897. else:
  898. print("Your option is invalid\nYou will be sent to the previous menu")
  899. modifyPresidentialBallot()
  900. for Party3 in politicalParties:
  901. if nameParty == Party3["Name"]:
  902. PresidentialBallot.append(Party3)
  903. print("The political party has been successfully added")
  904. print("Do you want to add some other political party?\n1)Yes\n2)No")
  905. option = input("Enter your option: ")
  906. if option == "1":
  907. modifyPresidentialBallotADD()
  908. elif option == "2":
  909. modifyPresidentialBallot()
  910. else:
  911. print("Your option is invalid\nYou will be sent to the previous menu")
  912. modifyPresidentialBallot()
  913. print("The name of political party is incoerrect or not exist.")
  914. modifyPresidentialBallotADD()
  915. print("The political party entered does not exist")
  916. modifyPresidentialBallot()
  917.  
  918. #method to print the matches of the ballots
  919. def printLB(namePro):
  920. for province in country:
  921. if namePro == province["Province"]:
  922. for ballot in province["Ballots"]:
  923. print("Name: "+ballot["Name"])
  924.  
  925. #method menu to choose which ballot to remove one or more political parties
  926. def menuRemovePartyBallot():
  927. print("What do you like to do?\n1)Remove Party in Predidencial Ballot.\n2)Remove Party in Legislative Ballot.\n3)Exit")
  928. option = input("Enter your option: ")
  929. if option == "1":
  930. removePartyPB()
  931. elif option == "2":
  932. removePartyLB()
  933. elif option == "3":
  934. menuBallots()
  935. else:
  936. print("Invalid option\nwill be sent to the previous menu")
  937. menuBallots()
  938.  
  939.  
  940. #method to remove a political party from the presidential ballot
  941. def removePartyPB():
  942. if len(PresidentialBallot) != 0:
  943. printListPB()
  944. nameParty = input("Enter the name of the political party you wish to eliminate from the ballot: ")
  945. for party in PresidentialBallot:
  946. if nameParty == party["Name"]:
  947. PresidentialBallot.remove(party)
  948. print("The political party was eliminated correctly.")
  949. print("Do you want to eliminate another political party?\n1)Yes\n2)No")
  950. option = input("Enter your option : ")
  951. if option == "1":
  952. removePartyPB()
  953. elif option == "2":
  954. menuRemovePartyBallot()
  955. else:
  956. print("Invalid option\nwill be sent to the previous menu")
  957. menuBallots()
  958. print("The political party entered does not exist")
  959. menuRemovePartyBallot()
  960. print("The ballot does not contain any political party.\nDo you want to add political parties to the ballot?\nYes\nNo")
  961. option2 = input("Enter your option: ")
  962. if option2 == "1":
  963. ballotPresidentialCreate()
  964. elif option2 == "2":
  965. menuRemovePartyBallot()
  966. else:
  967. print("Invalid option\nwill be sent to the previous menu")
  968. menuRemovePartyBallot()
  969.  
  970. #method to print the list of the 'parties of the presidential ballot
  971. def printListPB():
  972. for party in PresidentialBallot:
  973. print("Name: "+party["Name"])
  974.  
  975.  
  976. #method to eliminate one or more political parties from the legislative ballot
  977. def removePartyLB():
  978. if len(country) != 0:
  979. namePro = input("Enter the name of the province where the political party you want to eliminate is located: ")
  980. for province in country:
  981. if namePro == province["Province"]:
  982. if len(province["Ballots"]) != 0:
  983. printLB(namePro)
  984. nameParty = input("Enter the name of the political party you want to eliminate: ")
  985. for party in province["Ballots"]:
  986. if nameParty == party["Name"]:
  987. province["Ballots"].remove(party)
  988. print("The political party was successfully eliminated.\nDo you want to eliminate another political party?\n1)Yes\n2)No")
  989. option = input("Enter your option: ")
  990. if option == "1":
  991. removePartyLB()
  992. elif option == "2":
  993. menuRemovePartyBallot()
  994. else:
  995. print("Invalid option\nwill be sent to the previous menu")
  996. menuRemovePartyBallot()
  997.  
  998. print("The political party does not exist, or is badly written.")
  999. menuRemovePartyBallot()
  1000.  
  1001. print("There are no political parties on the ballot.\nDo you want to add political parties to the ballot?\n1)Yes\n2)No")
  1002. option2 = input("Enter your option: ")
  1003. if option2 == "1":
  1004. requeritProvince()
  1005. elif option2 == "2":
  1006. menuRemovePartyBallot()
  1007. else:
  1008. print("Invalid option\nwill be sent to the previous menu")
  1009. menuRemovePartyBallot()
  1010.  
  1011. print("The province does not exist, or is badly written.")
  1012. menuRemovePartyBallot()
  1013.  
  1014. print("There are no provinces.\nDo you want to create provinces?\n1)Yes\n2)No")
  1015. option3 = input("Enter your option: ")
  1016. if option3 == "1":
  1017. createProvince()
  1018. elif option3 == "2":
  1019. menuRemovePartyBallot()
  1020. else:
  1021. print("Invalid option\nwill be sent to the previous menu")
  1022. menuRemovePartyBallot()
  1023.  
  1024. #elimination menu of ballots
  1025. def menuDeleteBallots():
  1026. print("What do you like to do?\n1)Delete Presidential Ballot.\n2)Delete Legislative Ballot.\n3)Exit")
  1027. option = input("Enter your option: ")
  1028. if option == "1":
  1029. deletePresidentialBallot()
  1030. elif option == "2":
  1031. deleteLegislativeBallot()
  1032. elif option == "3":
  1033. menuBallots()
  1034. else:
  1035. print("Type a valid option.")
  1036. menuDeleteBallots()
  1037.  
  1038.  
  1039. #method to eliminate the presidential ballot
  1040. def deletePresidentialBallot():
  1041. if len(PresidentialBallot) == 0:
  1042. print("There is no ballot to be deleted")
  1043. menuDelete()
  1044. i =0
  1045. while i < len(PresidentialBallot):
  1046. PresidentialBallot.remove(PresidentialBallot[i])
  1047.  
  1048. print("The ballot has been eliminated")
  1049. print(PresidentialBallot)
  1050. menuDeleteBallots()
  1051.  
  1052. #method to eliminate the legislative ballot
  1053. def deleteLegislativeBallot():
  1054. if len(country) != 0:
  1055. namePro = input("Enter the name of the province where the ballot you want to delete is located: ")
  1056. i = 0
  1057. while i < len(country):
  1058. if country[i]["Province"] == namePro:
  1059. if len(country[i]["Ballots"]) != 0:
  1060. j = 0
  1061. while j < len(country[i]["Ballots"]):
  1062. country[i]["Ballots"].remove(country[i]["Ballots"][j])
  1063.  
  1064. print("The ballot has been eliminated")
  1065. print(country)
  1066. print("Do you want to eliminate another legislative ballot?\n1)Yes\n2)No")
  1067. option = input("Enter your option: ")
  1068. if option == "1":
  1069. deleteLegislativeBallot()
  1070. elif option == "2":
  1071. menuBallots()
  1072. else:
  1073. print("Type a valid option.")
  1074. menuDelete()
  1075.  
  1076. print("There is no ballot to be deleted")
  1077. menuDeleteBallots()
  1078.  
  1079. i += 1
  1080.  
  1081. print("The province does not exist, or is badly written.")
  1082. menuDeleteBallots()
  1083.  
  1084. print("There are no provinces.\nDo you want to create provinces?\n1)Yes\n2)No")
  1085. option2 = input("Enter your option: ")
  1086. if option2 == "1":
  1087. createProvince()
  1088. elif option2 == "2":
  1089. menuDeleteBallots()
  1090. else:
  1091. print("Invalid option\nwill be sent to the previous menu")
  1092. menuDeleteBallots()
  1093.  
  1094. #results menu
  1095. def menuVotes():
  1096. print("What do you like to do?\n1)Enter Presidential results.\n2)Enter Legislative results\n3)Exit")
  1097. option = input("Enter your option: ")
  1098. if option == "1":
  1099. presidentialVotes()
  1100. elif option == "2":
  1101. legislativeVotes()
  1102. elif option == "3":
  1103. adminMenu()
  1104. else:
  1105. print("Type a valid option")
  1106. menuVotes()
  1107.  
  1108.  
  1109. #Method to specify to which way to add the votes (presidential ballot)
  1110. def presidentialVotes():
  1111. for province in country:
  1112. for canton in province["Cantons"]:
  1113. for district in canton["Districts"]:
  1114. print(district["Name"])
  1115. PrintList()
  1116. addVotesPresidential(district)
  1117. print("The votes were added successfully.")
  1118. menuVotes()
  1119.  
  1120. #Method to add votes in the presidential ballot
  1121. def addVotesPresidential(district):
  1122. for party in PresidentialBallot:
  1123. newResults={}
  1124. newResults["Name"]=party["Name"]
  1125. newResults["Votes"]= int(input("How many votes for "+party["Name"]+"?"))
  1126. district["VotesPB"].append(newResults)
  1127.  
  1128.  
  1129. #method to specify in which district to add the votes (legislative ballot)
  1130. def legislativeVotes():
  1131. for province in country:
  1132. for canton in province["Cantons"]:
  1133. for district in canton["Districts"]:
  1134. print("District to which the votes will be added:")
  1135. print(district["Name"])
  1136. printLB(province)
  1137. addVotesLegislative(district)
  1138. print("The votes were added successfully.")
  1139. menuVotes()
  1140.  
  1141. # method to add votes on the legislative ballot
  1142. def addVotesLegislative(district):
  1143. for province in country:
  1144. for party in province["Ballots"]:
  1145. newResults = {}
  1146. newResults["Name"] = party["Name"]
  1147. newResults["Votes"] = int(input("How many votes for " + party["Name"] + "?"))
  1148. district["VotesLB"].append(newResults)
  1149.  
  1150. #query menu for administrators
  1151. def menuQueriesAdmin():
  1152. print("What do you like to do?\n1)National Results\n2)Provincial Results\n3)Canton Results\n4)Districts Results\n5)Know Assembly Conformation\n6)Exit")
  1153. option = input("What is your option?: ")
  1154. if option == "1":
  1155. addPartiesVotes()
  1156. elif option == "2":
  1157. provintialResults()
  1158. elif option == "3":
  1159. print("Could not complete")
  1160. menuQueriesAdmin()
  1161. elif option == "4":
  1162. resultsDistricts()
  1163. elif option == "5":
  1164. print("Could not complete")
  1165. menuQueriesAdmin()
  1166. elif option == "6":
  1167. print("Good bye.")
  1168. print("**************")
  1169. adminMenu()
  1170. else:
  1171. print("Type a valid option")
  1172. print("**************")
  1173. menuQueriesAdmin()
  1174.  
  1175. #Guest consultation menu
  1176. def menuQueriesGuest():
  1177. print(
  1178. "What do you like to do?\n1)National Results\n2)Provincial Results\n3)Canton Results\n4)Districts Results\n5)Know Assembly Conformation\n6)Exit")
  1179. option = input("What is your option?: ")
  1180. if option == "1":
  1181. addPartiesVotes()
  1182. elif option == "2":
  1183. provintialResults()
  1184. elif option == "3":
  1185. print("Could not complete")
  1186. menuQueriesAdmin()
  1187. elif option == "4":
  1188. resultsDistricts()
  1189. elif option == "5":
  1190. print("Could not complete")
  1191. menuQueriesAdmin()
  1192. elif option == "6":
  1193. print("Good bye.")
  1194. print("**************")
  1195. guestMenu()
  1196. else:
  1197. print("Type a valid option")
  1198. print("**************")
  1199. menuQueriesAdmin()
  1200.  
  1201.  
  1202. # Method that adds the presidential parties to which later the votes would be added
  1203. def addPartiesVotes():
  1204. for province in country:
  1205. vote={}
  1206. vote["Province"]=province["Province"]
  1207. vote["Parties"]=[]
  1208. for party in PresidentialBallot:
  1209. newParty={}
  1210. newParty["Name"]=party["Name"]
  1211. newParty["Votes"]=0
  1212. vote["Parties"].append(newParty)
  1213. provintialVotes.append(vote)
  1214. for province in provintialVotes:
  1215. addVotes(province)
  1216. totalVotesNational()
  1217.  
  1218.  
  1219. #method that adds the votes to the presidential political parties
  1220. def addVotes(province2):
  1221. for province in country:
  1222. for canton in province["Cantons"]:
  1223. for district in canton["Districts"]:
  1224. for party in district["VotesPB"]:
  1225. for nameParty in province2["Parties"]:
  1226. if nameParty["Name"] == party["Name"]:
  1227. nameParty["Votes"]+= party["Votes"]
  1228. return (provintialVotes)
  1229.  
  1230.  
  1231. #Method that adds the presidential parties to which the total of votes would be added later
  1232. def totalVotesNational():
  1233. vote={}
  1234. vote["Parties"]=[]
  1235. for party in PresidentialBallot:
  1236. newParty={}
  1237. newParty["Name"]=party["Name"]
  1238. newParty["TotalVotes"]=0
  1239. vote=newParty
  1240. totalVotes.append(vote)
  1241. getTotalPartyVotesProvintial()
  1242.  
  1243. #method that adds the total votes to the political parties, based on the provinces
  1244. def getTotalPartyVotesProvintial():
  1245. for province in provintialVotes:
  1246. for parties in province["Parties"]:
  1247. for party in totalVotes:
  1248. if party["Name"]==parties["Name"]:
  1249. party["TotalVotes"]+=parties["Votes"]
  1250. nationalResults()
  1251.  
  1252. #method to know the national results
  1253. def nationalResults():
  1254. print("******************")
  1255. total=0
  1256. if len(totalVotes)!=0:
  1257. for party in totalVotes:
  1258. total+=party["TotalVotes"]
  1259. for party in totalVotes:
  1260. porcentTotal= 100*party["TotalVotes"]/total
  1261. print(party["Name"],":",porcentTotal,"%"," ","Votes: ",party["TotalVotes"])
  1262. else:
  1263. print("No votes assigned to political parties")
  1264.  
  1265. #method to know the results by province
  1266. def provintialResults():
  1267. provintialVotes = 0
  1268. namePro = input("Enter the name of the province from which you want to know the results: ")
  1269. for province in provintialVotes:
  1270. if namePro == province["Province"]:
  1271. for party in province["Parties"]:
  1272. provintialVotes += party["Votes"]
  1273. for province in provintialVotes:
  1274. if namePro == province["Province"]:
  1275. for party in province["Parties"]:
  1276. percentProvince = party["Votes"]*100/provintialVotes
  1277. print(party["Name"],":",percentProvince,"%"," ","Votes:",party["Votes"])
  1278.  
  1279. #method to know the results by district
  1280. def resultsDistricts():
  1281. nameDistrict=input("Enter the name of the district: ")
  1282. for province in country:
  1283. for canton in province["Cantons"]:
  1284. for district in canton["Districts"]:
  1285. if nameDistrict==district["Name"]:
  1286. assistantResultsDstricts(district)
  1287.  
  1288. #auxiliary method of the "resultsDistricts" method
  1289. def assistantResultsDstricts(district):
  1290. totalVotes=0
  1291. for party in district["VotesPB"]:
  1292. totalVotes+= party["Votes"]
  1293. for party in district["VotesPB"]:
  1294. percentProvince = party["Votes"] * 100 / totalVotes
  1295. print(party["Name"], ":", percentProvince, "%", " ", "Votes:", party["Votes"])
  1296.  
  1297. menu()
Add Comment
Please, Sign In to add comment