dimanche 25 novembre 2018

Can't use randint() directly in the .format() string?

Complete beginner here.

I'm making a short game where one of the two players is randomly chosen to start the game:

from random import randint
player1 = input("First player, enter your name: ")
player2 = input("Second player, enter your name: ")

print("{randint(0,1)} will go first".format(name1, name2))

I want randint() to choose either player1 or player2, but I'm getting a TypeError. If I were to put either 0 or 1 into the {} instead of randint(0, 1) it works fine. Why doesn't this work? What other options are there besides an if/elif statement?




Aucun commentaire:

Enregistrer un commentaire