When I run this, it returns an error that countgb is referenced before assignment, but haven’t I assigned it at the very top of the program?
import random
listOfWords = ["british", "suave", "integrity", "accent", "evil", "genius", "Downton"]
wordChosen = random.choice(listOfWords)
wordlength = len(wordChosen)
badGuess = []
countbg = 0
def guessMatch():
if guess.lower() not in wordChosen:
badGuess.append(guess.lower())
countbg += 1
totalguesses = 6
print(f"Nope! '{guess}' is not in the word. You have {totalguesses-countbg} remaining.")
else:
for i in wordChosen:
if i == guess:
print(f"{i} ",end="")
else:
print("_ ", end="")
print()
print("Good guess!")
print(f"Try to guess the word which has {wordlength} letters!")
print()
for letter in wordChosen:
print("_ ",end="")
print()
while True:
print()
guess = input("Guess a letter: ")
print()
print(f"Your guess is {guess}")
print()
guessMatch()
print()
if countbg < 6:
continue
else:
print("You lost! Sorry!")
break