python 3: I am trying to code a bingo game which asks the user for 1-3 players, assigns each player a name, and then creates their Bingo card by choosing 25 elements from the list listOfStrings. the list contains 53 elements which are all strings. I am getting the error "ValueError: Sample larger than population or is negative" but 25<53 ? is the size of my list incorrect or do I have to assign each element a number? not sure why this is happening. im new to programming so probably a simple mistake or miscomprehension. thanks in advance
import urllib.request
import random
listOfStrings = []
def createList():
try:
with urllib.request.urlopen('https://www.cs.queensu.ca/home/cords2/bingo.txt') as f:
d = f.read().decode('utf-8')
split= d.split("\n")
listOfStrings = split
except urllib.error.URLError as e:
print(e.reason)
def players(listOfStrings):
noPlayers = input("How many players would like to play Bingo? Choose 1-3: ")
if noPlayers == "1":
name = input("What is the name of player 1? ")
player1card = random.sample(list(listOfStrings), 25)
createList()
players(listOfStrings)
print(player1card)
Aucun commentaire:
Enregistrer un commentaire