Python Scoreboard

Designing Solutions Through Programming. This course is also called introduction to programming.
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
User avatar
Maks123
New User
Posts: 2
Joined: 23 Aug 2018, 11:50

Python Scoreboard

Post by Maks123 » 26 Sep 2018, 11:27

This is my code and what I want to do is add a scoreboard to the simple game. I want the scoreboard to repeat along with the loop, however, I want it to keep the values every time it repeats. When I tried to set the score here it acts as if there is no code in that sector doing anything.

import random
import signal
while True :
random1 = [1,2,3,4]
user = input("Choose a number between 1-4 ")
print ("The number is",random.choice(random1))
print ("Your number is",user)
if int(random1) == int(user) :
score = 0
print (score)
1 x

Tags:

User avatar
Mr. MacKenty
Site Admin
Posts: 104
Joined: 28 Apr 2018, 17:06
Answers: 3

Re: Python Scoreboard

Post by Mr. MacKenty » 26 Sep 2018, 14:09

Hey Maks!

Code: Select all

import random
import signal
while True : 
    random1 = [1,2,3,4]
    user = input("Choose a number between 1-4 ")
    print ("The number is",random.choice(random1))
    print ("Your number is",user)
    if int(random1) == int(user) :
        score = 0
    print (score)
  • It looks like you repeatedly reset the variable SCORE to 0.
  • Also, each time the loop iterates it chooses a new random number
  • The variable name "user" should be re-named so it makes sense. Maybe user_choice?
  • The conditional is a bit off. It looks to me like if a user gets the right answer, the score stays at zero
0 x

Post Reply