Найти - Пользователи
Полная версия: Помогите командой
Начало » Python для новичков » Помогите командой
1
Megiya
Добрый день! Я не буду ходить вокруг-да около. Я сделал крестики нолики, и нужно сделать так, чтобы игрок выбирал - продолжить или нет. Как называеться команда которая полностью перезапустит код? (И если нужна библиотека, то как она называеться).
Romissevd
Используй while
 game = 'ON'
while game == 'ON':
    start_game() # тут запуск твоей игры
    game = input('Повторить введите - ON')
AD0DE412
 while True:
    game = input("вокруг или около?")
    if game == "вокруг":
        print("выход")
        break
    elif game == "около":
        print("код моей игры")
    else:
        print("?!")
Megiya
Romissevd
start_game(
Есть способ легче? Просто снова пробелы ставить не очень охота. Если это поможет. вот код :
import random
print("------------------------------------")
print("-------Камінь, ножниці, папір-------")
print("Вітаю тебе в моїй грі!")
print("Гра складається з трьох раундів")
print("Виграє той, хто набере більше балів")
print("\t[r] - камінь\n\t[p] - папір\n\t[s] - ножниці")

player_score = 0
player_select = 0
comp_score = 0
comp_select = 0
print("-----------------------------")
print("-----------------------------")
for i in range (3) :
print("\t--------ROUND №" + str(i + 1) + "--")
comp_select = random.choice("rps")


while True:
player_select = input ("\tYour choice:")
if (player_select == "r") or (player_select == "s") or (player_select == "p"):
break
else:
print("\tError")
print("\tComputer:" + comp_select)

if player_select == comp_select:
print("\tНічія!")
elif player_select == "r" and comp_select == "s":
player_score = player_score + 1
print("\tТи виграв!")
elif player_select == "r" and comp_select == "p":
comp_score = comp_score + 1
print("\tКомп'ютер виграв!")
elif player_select == "p" and comp_select == "r":
player_score = player_score + 1
print("\tТи виграв!")
elif player_select == "p" and comp_select == "s":
comp_score = comp_score + 1
print("\tКомп'ютер виграв!")
elif player_select == "s" and comp_select == "p":
player_score = player_score + 1
print("\tТи виграв!")
elif player_select == "s" and comp_select == "r":
comp_score = comp_score + 1
print("\tКомп'ютер виграв!")

print("-----------------------------------")
print("------------Результат гри------------")
if player_score > comp_score:
print("Вітаємо! Ви виграли!")
elif player_score < comp_score:
print("Комп'ютер виграв, але нічого! Ви зможете!'")
else:
print("Нічія!")

a = input("Продолжить? y/n\n>>>").lower()
while True :
if a==("y"):
print(str(comp_score) + " в бота")
print(str(player_score) + " в игрока")
elif a==("n"):
print(str(comp_score) + " в бота")
print(str(player_score) + " в игрока")
break
input()
else :
print("ERROR!")
break
input()
AD0DE412
 def start_game():
    print("------------------------------------")
    print("-------Камінь, ножниці, папір-------")
    print("Вітаю тебе в моїй грі!")
    print("Гра складається з трьох раундів")
    print("Виграє той, хто набере більше балів")
    print("\t[r] - камінь\n\t[p] - папір\n\t[s] - ножниці")
    player_score = 0
    player_select = 0
    comp_score = 0
    comp_select = 0
    print("-----------------------------")
    print("-----------------------------")
    for i in range (3) :
       print("\t--------ROUND №" + str(i + 1) + "--")
       comp_select = random.choice("rps")
       while True:
           player_select = input ("\tYour choice:")
           if (player_select == "r") or (player_select == "s") or (player_select == "p"):
               break
           else:
               print("\tError")
       print("\tComputer:" + comp_select)
       if player_select == comp_select:
               print("\tНічія!")
       elif player_select == "r" and comp_select == "s":
            player_score = player_score + 1
            print("\tТи виграв!")
       elif player_select == "r" and comp_select == "p":
            comp_score = comp_score + 1
            print("\tКомп'ютер виграв!")
       elif player_select == "p" and comp_select == "r":
            player_score = player_score + 1
            print("\tТи виграв!")
       elif player_select == "p" and comp_select == "s":
            comp_score = comp_score + 1
            print("\tКомп'ютер виграв!")
       elif player_select == "s" and comp_select == "p":
            player_score = player_score + 1
            print("\tТи виграв!")
       elif player_select == "s" and comp_select == "r":
            comp_score = comp_score + 1
            print("\tКомп'ютер виграв!")
    print("-----------------------------------")
    print("------------Результат гри------------")
    if player_score > comp_score:
      print("Вітаємо! Ви виграли!")
    elif player_score < comp_score:
      print("Комп'ютер виграв, але нічого! Ви зможете!'")
    else:
      print("Нічія!")
    a = input("Продолжить? y/n\n>>>").lower()
    while True :
        if a==("y"):
             print(str(comp_score) + " в бота")
             print(str(player_score) + " в игрока")
        elif a==("n"):
             print(str(comp_score) + " в бота")
             print(str(player_score) + " в игрока")
             break
             input()
        else :
             print("ERROR!")
             break
             input()

ps
Есть способ легче?
создать 2 модуля один для запуска другой с кодом игры
 game = 'ON'
while game == 'ON':
    import start_game # тут запуск твоей игры
    game = input('Повторить введите - ON')
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