When i get to the last voting section the code seems to continue into the next if statement and i cant seem to understand why it wont just print the last statement and stop? i've had a thorough check through the code and cant seem to find anything wrong especially with the last function as it is the same as the previous three. And is there any faster way to repeat code like this?
def presvote():
with open("President.txt", "r+") as president:
president = open("President.txt", "r")
pres = [line.rstrip('\n', ) for line in open("President.txt")]
print("Here is a list of the people running for president: ")
print(pres)
pvote1(pres)
def pvote1(pres):
vote1 = input("Who would you like to vote for as the first choice?: ")
if vote1 in pres:
pres.remove(vote1)
print(pres)
pvote2(pres, vote1)
else:
print("That candidate is not running\nPlease enter a valid name")
pvote1(pres)
def pvote2(pres, vote1):
vote2 = input("Who would you like to vote for as the second choice?: ")
if vote2 in pres:
pres.remove(vote2)
print(pres)
pvote3(pres, vote1, vote2)
if vote2 == vote1:
print("That candidate has already been chosen, Please choose another")
pvote2(pres, vote1)
else:
print("That candidate is not running please try again")
pvote2(pres, vote1)
def pvote3(pres, vote1, vote2):
vote3 = input("Who would you like to vote for as the third choice?: ")
if vote3 in pres:
pres.remove(vote3)
print(pres)
pvote4(pres, vote1, vote2, vote3)
if vote3 == vote1 or vote2:
print("That candidate has already been chosen, Please choose another")
pvote3(pres, vote1, vote2)
else:
print("That candidate is not running please try again")
pvote3(pres, vote1, vote2)
def pvote4(pres, vote1, vote2, vote3):
vote4 = input("Who would you like to vote for as the fourth choice?: ")
if vote4 in pres:
pres.remove(vote4)
print(pres)
# print("Here is the list of your chosen candidates:\n",vote1,"\n",vote2,"\n",vote3,"\n",vote4)
if vote4 == vote1 or vote2 or vote3:
print("That candidate has already been chosen, Please choose another")
pvote4(pres, vote1, vote2, vote3)
else:
print("That candidate is not running please try again")
pvote4(pres, vote1, vote2, vote3)
presvote()```