D
D
Droplex2152021-08-24 00:12:25
Python
Droplex215, 2021-08-24 00:12:25

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()

Ps Do not pay attention to other shortcomings until I figure out the performance, I do not fix them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-08-24
@Droplex215

sсhet -= stavkahere is the Russian "s" in the variable "schet"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question