حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود

بازی کلمات (دو نفره)

تمرین آسان 3794 visibility link download flag

برنامه بازی کلمات را بنویسید که:

دو بازیکن بتوانند در بازی شرکت کنند
به نوبت هر بازیکن کلمه ای دلخواه وارد کند
هر بازیکن باید کلمه ای وارد کند که با حرف آخر کلمه قبلی شروع شود
بازیکنان نمیتوانند کلمات تکراری وارد کنند
این تمرین یه پروژه ست! یعنی پتانسیل اینو داره که خیلی بیشتر روش کار بشه بنابراین ایده اصلی رو از اینجا بردار و خودت بیشتر روش کار کن تا به یه تمرین بزرگتر تبدیل یشه
👨‍💻 20 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

reply 16

visibility
name1 = input("Enter your name: ")
name2 = input("Enter your name: ")
name1_word = input(f'{name1} please Enter your word: ')

def name_2_turn() :
    global name2_word
    name2_word = input(f'{name2} Enter a word that "starts" with {name1_word[-1]}: ') # sheep ---> start with p
    if name2_word == 'exit':
        exit()
    if len(name2_word) < 2:
        print('your word must be greater than 2')
        name_2_turn()
    if name1_word[-1] == name2_word[0]:
        print('Good job')
        name_1_turn()
    else:
        print('False!!!')
        name_2_turn()
def name_1_turn() :
    global name1_word
    name1_word = input(f'{name1} Enter a word that "starts" with {name2_word[-1]}: ')
    if name1_word == 'exit':
        exit()
    if len(name1_word) < 2:
        print('your word must be greater than 2')
        name_1_turn()
    if name2_word[-1] == name1_word[0]:
        print('Good job')
        name_2_turn()
    else:
        print('False!!!')
        name_1_turn()
name_2_turn()
import time
# توی تمرین من زمان هم اضافه کردم اگه کسی بیشتر از 15 ثانیه طول بده میبازه

# گرفتن نام بازیکنان
player1 = input("Enter the name of Player 1: ")
player2 = input("Enter the name of Player 2: ")

# شروع بازی
current_player = player1
previous_name = None
used_names = set()

while True:
    start_time = time.time()
    name = input(f"{current_player}, enter a name: ")
    end_time = time.time()
    
    # بررسی زمان
    if end_time - start_time > 15:
        print(f"{current_player} took too long! Game over.")
        break
    
    # بررسی حرف آخر و اول
    if previous_name and name[0].lower() != previous_name[-1].lower():
        print(f"{current_player} entered a name that does not start with '{previous_name[-1]}'. Game over.")
        break
    
    # بررسی تکراری بودن نام
    if name in used_names:
        print(f"{current_player} entered a duplicate name. Game over.")
        break
    
    used_names.add(name)
    previous_name = name
    current_player = player2 if current_player == player1 else player1
def inaddition(m, n):
    result=1
    for _ in range(n):
        temp=0
        for _ in range(m):
            temp+=result
        result=temp
    return result
m=int(input("m:"))
result=inaddition(m, n)
print(f"{result}")
def word_game():

    # Play the first turn: 0, play the second turn: 1
    turn = 0
    round = 0
    repeated_words = []
    while True:
        if turn == 0 and round == 0:
            question0 = input().strip()
            turn = 1
            round +=1
            repeated_words.append(question0)

        elif turn == 1 and round != 0:
            question1 = input().strip()
            if question1[0] == question0[-1][-1] and question1 not in repeated_words:
                turn = 0
                round +=1
                repeated_words.append(question1)
            else:
                print("you lost :",round) 
                break
        elif turn == 0 and round != 0:
            question0 = input().strip()
            if question0[0] == question1[-1][-1] and question0 not in repeated_words:
                turn = 1
                round +=1
                repeated_words.append(question0)
            else:
                print("you lost :",round)
                break
word_game()
str1=input("Enter the word by B1:  ")
str2=input("Enter the word by B2:  ")
li=[str1,str2]
while str2[0]==str1[-1] :
    str1=input("Enter the word by B1:  ")
    if str1[0]==str2[-1] and str1 not in li:
        str2=input("Enter the word by B2:  ")
        if str2[0]==str1[-1] and str2 not in li:
            li.append(str1)
            li.append(str2)
            #print("Edame : ","\n")
        else:
            li.append(str1)
            li.append(str2)
            print("REfuse")
            break
    else:
        li.append(str1)
        print("tekrariiiiiiiiiiiiii")
        print("refuse")
        break
print(li)
#
import time
start_time = time.time()
tedad_word1 = 0
tedad_word2 = 0

while True:
    if time.time() - start_time > 60:
        print("time up")
        break
    player1 = str(input("enter your name(player1):"))
    if player1 == "0":
        print("player1 is out play")
        print("player2 is win")
        break
    x = player1[-1::]
    tedad_word1 += 1
    print(f"harf akhar kalame  player1:{x}")
    player2 = str(input("enter your name(player2):"))
    if player2 == "0":
        print("player 2 is out play")
        print("player1 is win")
        break
    y = player2[-1::]
    tedad_word2 += 1
    print(f"harf akhar kalame  player1:{y}")

    if player1 == player2:
        print("kalamat player1 and player 2 nabayad tekrari bashand")
    if player1 != y:
        print("in harf khata mizanad")
    if player2 != x:
        print("in harf khata mizanad")
   
    print(f"tedad kalamat player1:{tedad_word1}")
    print(x)
    print(f"tedadd kalamat player2:{tedad_word2}")
    print(y)
    print("natije bazi")

    if tedad_word1 > tedad_word2:
        print("player1 is win")
    if tedad_word2 > tedad_word1:
        print("player 2 is win")
    if tedad_word1 == tedad_word2:
        print("player is equal")
def check_correct(first_str , second_str):
    """checks if the last letter of first is matched with the first of the second"""
    return second_str[0] == first_str[-1]

while True:
    player_one = str(input("enter the word player one : "))
    player_two = str(input("enter the word player two : "))

    if check_correct(player_one , player_two) == True:
        print(f"\nnext round , start with {player_two[-1]}")
    else:
        print("WRONG!!! \n\n")
        break
words = []
player = input('start: ')
number = 0
words.append(player)
while 1:
    player = input('player2: ')
    if player[0] == words[number][-1] and player not in words:
        number += 1
        words.append(player)
    else:
        print('you lost')
        break
def main():
    print("Welcome to the Word Chain Game!")
    print("Two players will take turns entering words.")
    print("Each word must start with the last letter of the previous word.")
    print("No repeated words are allowed.")
    print("Let's start!\n")

    used_words = set()
    current_word = input("Player 1, enter the first word: ").strip().lower()
    used_words.add(current_word)

    Determine which player's turn it is: 1 or 2
    player_turn = 2

    while True:
        last_char = current_word[-1]
        if player_turn == 2:
            prompt = "Player 2, enter a word starting with '{}': ".format(last_char)
        else:
            prompt = "Player 1, enter a word starting with '{}': ".format(last_char)

        next_word = input(prompt).strip().lower()

        Check if the word has been used before
        if next_word in used_words:
            print("This word has already been used. Try again.")
            continue

        Check if the first letter matches the last letter of previous word
        if not next_word.startswith(last_char):
            print("Invalid start letter. The word should start with '{}'.".format(last_char))
            continue

        Valid move
        used_words.add(next_word)
        current_word = next_word
        Switch turns
        player_turn = 1 if player_turn == 2 else 2

if name == "main":
    main()
<< صفحه قبل 1 2 صفحه بعد >>

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن