anonymous No title
No License Python
2019年07月09日
Copy
import random

while True:
    print('Choice your hand, input number.')
    print('Rock    : 0')
    print('Paper   : 1')
    print('Scissors: 2')
    print('Exit    : 3')

    user_input = input()

    if not user_input.isdecimal():
        print('Invalid input')
    elif user_input == '3':
        break
    else:
        user_hand = int(user_input)
        ai_hand = random.randrange(3)

        if user_hand == 0:
            print('User hand: Rock')
        elif user_hand == 1:
            print('User hand: Paper')
        else:
            print('User hand: Scissors')

        if ai_hand == 0:
            print('AI hand  : Rock')
        elif ai_hand == 1:
            print('AI hand  : Paper')
        else:
            print('AI hand  : Scissors')

        if user_hand == (ai_hand + 1) % 3:
            print('Result   : Win')
        elif ai_hand == (user_hand + 1) % 3:
            print('Result   : Lose')
        else:
            print('Result   : Draw')

        print()
import random

while True:
    print('Choice your hand, input number.')
    print('Rock    : 0')
    print('Paper   : 1')
    print('Scissors: 2')
    print('Exit    : 3')

    user_input = input()

    if not user_input.isdecimal():
        print('Invalid input')
    elif user_input == '3':
        break
    else:
        user_hand = int(user_input)
        ai_hand = random.randrange(3)

        if user_hand == 0:
            print('User hand: Rock')
        elif user_hand == 1:
            print('User hand: Paper')
        else:
            print('User hand: Scissors')

        if ai_hand == 0:
            print('AI hand  : Rock')
        elif ai_hand == 1:
            print('AI hand  : Paper')
        else:
            print('AI hand  : Scissors')

        if user_hand == (ai_hand + 1) % 3:
            print('Result   : Win')
        elif ai_hand == (user_hand + 1) % 3:
            print('Result   : Lose')
        else:
            print('Result   : Draw')

        print()

Output

Run
年末年始は機械学習・深層学習を勉強しませんか?
No one still commented. Please first comment.
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら