I'm confused, the if statement should by all means run imo, but of course this is programming so its not going to work.
def create_player():
name = str()
names = []
print("hey there")
if numberofplayers == 2:
name = input("Please enter Player 1's name: ")
names.append(name)
name = input("Please enter Player 2's name: ")
names.append(name)
elif numberofplayers == 3:
name = input("Please enter Player 1's name: ")
names.append(name)
name = input("Please enter Player 2's name: ")
names.append(name)
name = input("Please enter Player 3's name: ")
names.append(name)
elif numberofplayers == 4:
name = input("Please enter Player 1's name: ")
names.append(name)
name = input("Please enter Player 2's name: ")
names.append(name)
name = input("Please enter Player 3's name: ")
names.append(name)
name = input("Please enter Player 4's name: ")
names.append(name)
print("Welcome to the game " + names[0] + ", " +names[1]+ ", "+names[2]+ " and "+names[3]+"!")
print("test")
numberofplayers = int(0)
numberofplayers = input("# of players")
create_player()
print ("aha")
(By the way this code is not be any means anywhere near finished) The random print operations were there for testing, the program seems to ignore the whole if statement, as it prints all of the print operations outside of the if statement, but none that are inside the statement. Any help would be very much appreciatted, thank you in advance.
global numberofplayersinsidecreate_player()for n in range(numberofplayers): names.append(input("Enter player {0}'s name".format(n+1))). This removes much of the duplication and works for any number of players.