Найти - Пользователи
Полная версия: UnboundLocalError
Начало » Python для новичков » UnboundLocalError
1
Tom228
 import random
chips = int()
blind_s = input('Small Blind is:')
blind_b = input('Big Blind is:')
chips = input('Starter Chips:')
def IventPlayerChips():
    print('Your Chips:',chips)
IventPlayerChips()
def IventMoveChoice():
    first = random.randint(1, 2)
    if first == 1:
        print('You put' ,blind_s,' chips')
        chips-=blind_s
    if first == 2:
        print('You put',blind_b,'chips')
        chips-=blind_b
IventMoveChoice()
Выдаёт - UnboundLocalError: local variable ‘chips’ referenced before assignment
Хелппп, Python 3.6.1
scidam
Попробуйте так

 def IventMoveChoice():
    global chips
    first = random.randint(1, 2)

Когда вы используете +=, -= и т.п. Python ищет соответствующую переменную, chips, в локальном окружении, а там ее нет. Нужно явно указать ему где ее искать…
Tom228
Спасибо, разобрался
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB