Форум сайта python.su
Мне надо помочь с игрой в 21(очко)
Я хочу сделать чтобы в конце игры был вопрос “Еще раз? да или нет: ” и если игрок писал слово “да” то программа начиналась с цикла начала игры
Вот код
#------------Вступление------------ print("Hi, player!") print("") print("You entered the game 21(cards)") print("") print("There are such cards here:6, 7, 8, 9, 10, 2(валет), 3(дама), 4(король), 11(туз)!") print("The account is written first your account, and then the bot") print("") #------------Конец Вступления------------ koloda = [6, 7, 8, 9, 10, 2, 3, 4, 11] #колода import random random.shuffle(koloda) #------------Изначальный банк------------ cashplayer = 0 cashbot = 0 #------------Конечный банк------------ play = True #------------Начало цикла игры------------ while play: what = input("Play? yes or no: ") if what == "yes": player = koloda.pop() bot = koloda.pop() print("You got a card %d" %player) cashplayer += player cashbot += bot score = "Score: %d" %cashplayer + " : %d" %cashbot if 21 < cashbot: print("You win =)") print(score) break elif 21 < cashplayer: print("You lose -_-") print(score) break elif 21 < cashplayer < cashbot: print("Draw") print(score) break elif 21 < cashplayer > cashbot > 21: print("Draw") print(score) break elif 21 < cashbot < cashplayer: print("Draw") print(score) break elif 21 < cashbot > cashplayer > 21: print("Draw") print(score) break elif cashbot == 21: print("You lose -_-") print(score) break elif cashplayer == 21: print("You win =)") print(score) break elif cashbot == cashplayer: print("Draw") print(score) break else: print("You have only %d point" %cashplayer) print("") elif what == "no": if cashplayer > 21 > cashbot: print("You lose -_-") elif cashbot > 21 > cashplayer: print("You win =)") elif 21 < cashbot < cashplayer: print("Draw") elif 21 > cashbot > cashplayer: print("You lose -_-") elif 21 > cashplayer > cashbot: print("You win =)") elif 21 < cashplayer < cashbot: print("Draw") elif 21 > cashplayer < cashbot < 21: print("You lose -_-") elif 21 > cashbot < cashplayer < 21: print("You win =)") elif cashbot == 21 == cashplayer: print("Draw") elif cashbot == cashplayer: print("Draw") #ВОТ ЗДЕСЬ НАДО СДЕЛАТЬ ТО ЧТО Я ПРОШУ print(score) what = input("Another game? yes or no: ") if what == "yes": for play in range(1): play elif what == "no": break else: input("Press Enter to Exit") break
Отредактировано Morrisons (Янв. 17, 2020 22:03:03)
Офлайн
break в конце убери и добавь вопрос. Если ответ нет, то переменная play = False, следовательно выход из цикла, для ответа “да” можно ничего не добавлять, тут и так цикл.
Офлайн