question from a student: python code

IB Year 2 HL Computer Science
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
User avatar
Mr. MacKenty
Site Admin
Posts: 104
Joined: 28 Apr 2018, 17:06
Answers: 3

question from a student: python code

Post by Mr. MacKenty » 18 Oct 2018, 13:21

From a year 2 student. My comments are in the code as comments.

Code: Select all

# in general, false should be considered a BOOLEAN value, not a STRING. I suggest: 
# game = False 
game = "false"

start = input("Do you want to start game? answer y or n --> ")
if start == "n":
    print ("Goodbye.")
    game = True
players = {}
print ("the current players are" + str(players))
#ask for amt of players, create dict of players
# Why use a dictionary here? I am curious. There isn't a right or wrong answer, but a justification. 
amount_of_players = input("How many players would you like? (1-4)")
while len(players) < int(amount_of_players):
    new_player_name = ("player" + str(len(players)+1))
    players[new_player_name] = 0
#printing the scores
print ("here are the current scores:")
for key,val in players.items():
    print (key, "=>", str(val))
#asking for amount of rounds
turns = input("how many questions would you like each player to answer? -->")
amount_of_questions = int(turns) * int(amount_of_players)
print ("Okay. You will play the game for " + str(turns) + " rounds. This means that the game will generate " + str(amount_of_questions) + " questions in total.")
0 x


Post Reply