Save state

This commit is contained in:
Виталий Туров 2025-02-06 19:00:53 +03:00
parent a52c52be9e
commit 0c05e7a809

View File

@ -1,84 +1,11 @@
import random from fastapi import FastAPI
word_dict = { app = FastAPI()
"питон": "интерпритируемый язык программирования",
"голанг": "компилируемый язык программирования",
}
@app.get("/")
async def root():
return {"message" : "Hello World"}
def game(): @app.delete("/user")
word_number = random.randint(0, len(word_dict) - 1) async def root():
word = list(word_dict.keys())[word_number] return {"message" : "User delete"}
describe = word_dict[word]
guess = ['_' for _ in word]
value_guess = len(word)
print(describe)
print(" ".join(guess))
while value_guess > 0:
character = input("Введите букву: ")
if word.count(character) >= 1:
for index, value in enumerate(word):
if character == value:
guess[index] = value
else:
value_guess -= 1
print(f"У вас осталось {value_guess} попыток")
if guess.count('_') == 0:
print(" ".join(guess))
break
print(" ".join(guess))
else:
print(f"GAME OVER =(")
def run_game():
game()
def save_game():
pass
def load_game():
pass
def exit_game():
exit(0)
def menu():
print(
"""
1. Начать игру
2. Сохранить
3. Загрузить
4. Выход
"""
)
def read_selector():
key = int(input(":"))
match key:
case 1:
run_game()
case 2:
save_game()
case 3:
load_game()
case 4:
exit_game()
def main():
menu()
read_selector()
if __name__ == "__main__":
main()