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

while True:
    print('Choice your hand, input character.')
    print('Rock    : g')
    print('Paper   : p')
    print('Scissors: s')
    print('Exit    : e')

    user_input = input()

    if user_input == 'e':
        break
    else:
        ai_hand = random.randrange(3)

        if user_input == 'g':
            user_hand = 0
            print('User hand: Rock')
        elif user_input == 'p':
            user_hand = 1
            print('User hand: Paper')
        elif user_input == 's':
            user_hand = 2
            print('User hand: Scissors')
        else:
            print('Invalid input')
            continue

        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 character.')
    print('Rock    : g')
    print('Paper   : p')
    print('Scissors: s')
    print('Exit    : e')

    user_input = input()

    if user_input == 'e':
        break
    else:
        ai_hand = random.randrange(3)

        if user_input == 'g':
            user_hand = 0
            print('User hand: Rock')
        elif user_input == 'p':
            user_hand = 1
            print('User hand: Paper')
        elif user_input == 's':
            user_hand = 2
            print('User hand: Scissors')
        else:
            print('Invalid input')
            continue

        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.
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら