Answer the question
In order to leave comments, you need to log in
Error: UnboundLocalError: local variable referenced before assignment. How to fix?
Good day! I had an error while writing the simplest code, I searched for a long time but could not solve my problem.
So, I'm trying to score a little game of dice. I started working with a global variable in a function, everything works fine when I win, but this error crashes when I lose.
Here is the part of the code where the error is thrown:
kubik = [1,2,3,4,5,6] * 9999
kubik2 = [1,2,3,4,5,6] * 9999
schet = 100
import random
random.shuffle(kubik)
random.shuffle(kubik2)
print('Поиграем в Под 7 Над?')
while True:
print('На вашем счету: ',schet)
stavka = input('Введите ставку: ')
if int(stavka) > int(schet):
print('На вашем счету недостаточно средств!')
else:
vopros = input('Выберите БОЛЬШЕ, 7 или МЕНЬШЕ: ')
if vopros == 'БОЛЬШЕ':
chislo = kubik.pop()
chislo2 = kubik2.pop()
print ('Вам выпало число: ', chislo + chislo2)
znachenie = int(chislo) + int(chislo2)
def bv():
global schet
if znachenie > 7:
print('Вы выйграли!')
vin = int(stavka) * 2
schet += vin
else:
print('Вы проиграли!')
sсhet -= stavka
bv()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question