我需要在此岩纸仪代码中做什么?

发布于 2025-02-13 22:42:41 字数 1118 浏览 1 评论 0原文

我陷入了此代码的最后位。我不知道下一步该怎么办。

我需要游戏从列出的选项中选择一个随机选项,以便他们可以与用户选择。

有人可以将我指向正确的方向吗?

 # Rock paper Scissors Game
     # Question 1
        print("Want to play Rock Paper Scissors??")
        question1=input("Y/N: ").lower()
        
        if question1=='y':
            print('Perfect but first')
        elif question1== 'n':
            print('Sorry but your here already')
        else: print('error')
        
    # Question 2
        print('Do you know how to play??')
        question2=input("Y/N: ").lower()
        
        if question2=='y':
            print('Ok lets get started!')
        elif question2=='n':
            print('Pick 1 of the 3 options to battle my option')
            print('Rock beats scissors')
            print("Paper beats rock")
            print('Scissors beats paper')
        else:
            print('error')
        
    # Display game options
        
        
        options = ['Rock', 'Paper', "Scissors"]
        def random_choose(options):
            pick = input('Take your pick:  ')
            return pick, random.choose(options)

I'm stuck on the last bit of this code. I don't know what to do next.

I need the game to pick a random option out of the listed options so they can battle the users pick.

Could someone point me in the right direction?

 # Rock paper Scissors Game
     # Question 1
        print("Want to play Rock Paper Scissors??")
        question1=input("Y/N: ").lower()
        
        if question1=='y':
            print('Perfect but first')
        elif question1== 'n':
            print('Sorry but your here already')
        else: print('error')
        
    # Question 2
        print('Do you know how to play??')
        question2=input("Y/N: ").lower()
        
        if question2=='y':
            print('Ok lets get started!')
        elif question2=='n':
            print('Pick 1 of the 3 options to battle my option')
            print('Rock beats scissors')
            print("Paper beats rock")
            print('Scissors beats paper')
        else:
            print('error')
        
    # Display game options
        
        
        options = ['Rock', 'Paper', "Scissors"]
        def random_choose(options):
            pick = input('Take your pick:  ')
            return pick, random.choose(options)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滿滿的愛 2025-02-20 22:42:41

好吧,对于这个问题,循环将有助于游戏更具动态性,使玩家能够直到玩家退出游戏为止。我还将您的代码的部分集成到了该修订后的部分中。希望这会有所帮助

import random as r
game = True
print("Want to play Rock Paper Scissors??")
question1=input("Y/N: ").lower()
options = ['Rock', 'Paper', "Scissors"]
if question1=='y':
    print('Perfect but first')
    print('Do you know how to play??')
    question2=input("Y/N: ").lower()
    if question2=='y':
                print('Ok lets get started!')
    elif question2=='n':
        print('Pick 1 of the 3 options to battle my option')
        print('Rock beats scissors')
        print("Paper beats rock")
        print('Scissors beats paper')   
    while game:
        pick = input('Take your pick(rock,paper or scissors):  ')
        if pick.capitalize() in options:
            Ai = r.choice(options)
            if (pick.lower()=="scissors"and Ai.lower()=="rock") or (pick.lower()=="paper" and Ai.lower()=="scissors") or (pick.lower()=="rock" and Ai.lower()=="paper"): #this is the rules for Ai vs user input(in this case Ai wins)
                print("you lose, "+ Ai +" beats "+ pick )
            elif (pick.lower()=="rock"and Ai.lower()=="scissors") or (pick.lower()=="scissors" and Ai.lower()=="paper") or (pick.lower()=="paper" and Ai.lower()=="rock"): #this is the rules for Ai vs user input(in this case player wins)
                print("you win, "+ pick +" beats "+ Ai )
            else: # in rare cases where both are the same 
                print("it's a tie, "+pick +" draws with " +Ai)
        elif pick.lower() not in options: #if the user input is not found
            print("option was not found")
        cont = input("do you want to continue [Y/N]: ")
        if cont.lower() =="n": #opting out(user quitting statement)
            game = False
        else:
            continue
            
elif question1== 'n':
    print('Alright good bye')

Well, for this question a while loop would help the game be more dynamic, allowing the player to until the player opt-out of the game. I also integrated parts of your code into this revised one. Hope this helps

import random as r
game = True
print("Want to play Rock Paper Scissors??")
question1=input("Y/N: ").lower()
options = ['Rock', 'Paper', "Scissors"]
if question1=='y':
    print('Perfect but first')
    print('Do you know how to play??')
    question2=input("Y/N: ").lower()
    if question2=='y':
                print('Ok lets get started!')
    elif question2=='n':
        print('Pick 1 of the 3 options to battle my option')
        print('Rock beats scissors')
        print("Paper beats rock")
        print('Scissors beats paper')   
    while game:
        pick = input('Take your pick(rock,paper or scissors):  ')
        if pick.capitalize() in options:
            Ai = r.choice(options)
            if (pick.lower()=="scissors"and Ai.lower()=="rock") or (pick.lower()=="paper" and Ai.lower()=="scissors") or (pick.lower()=="rock" and Ai.lower()=="paper"): #this is the rules for Ai vs user input(in this case Ai wins)
                print("you lose, "+ Ai +" beats "+ pick )
            elif (pick.lower()=="rock"and Ai.lower()=="scissors") or (pick.lower()=="scissors" and Ai.lower()=="paper") or (pick.lower()=="paper" and Ai.lower()=="rock"): #this is the rules for Ai vs user input(in this case player wins)
                print("you win, "+ pick +" beats "+ Ai )
            else: # in rare cases where both are the same 
                print("it's a tie, "+pick +" draws with " +Ai)
        elif pick.lower() not in options: #if the user input is not found
            print("option was not found")
        cont = input("do you want to continue [Y/N]: ")
        if cont.lower() =="n": #opting out(user quitting statement)
            game = False
        else:
            continue
            
elif question1== 'n':
    print('Alright good bye')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文