[Python] Games such a flip a coin, rolling dice, and choosing cards

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    im trying to make a game board and i have taken some notes from my class and im just struggling to do this assignment. We never have done anything like this in class before. I need to do a coin flip, roll two dice a 6 sided one and a 20 sided one and i need to pick a card.

    import random

    def flip_coin():
    # TODO: implement this function
    # get a random int between 0 and 1
    # if the number is 0, return "Coin flip: Tails"
    # if the number is 1, return "Coin flip: Heads"
    # delete this next line:
    return 0

    def roll_d6():
    # TODO: implement this function
    # get a random int between 1 and 6
    # return "D6 roll: [that number]"

    # delete this next line:
    return 0

    def roll_d20():
    # TODO: implement this function
    # get a random int between 1 and 20
    # return "D20 roll: [that number]"

    # delete this next line:
    return 0

    def pick_card():
    # TODO: implement this function
    # get a random number between 0 and 3
    # [card suit]: 0=spades, 1=hearts, 2=diamonds, 3=clubs
    # then get a random number between 1 and 13
    # [card value]: 1=Ace, 11=Jack, 12=Queen, 13=King, 2-10 are normal (no translation)
    # return "Your card: [card value] of [card suit]"

    # delete this next line:
    return 0


    # TODO: put the following lines into a loop, to allow the user to repeat until they quit
    print('Welcome to the game center!\nHere are your options:')
    print('\t1) Flip a coin\n\t2) Pick a random playing card')
    print('\t3) Roll a 6-sided dice\n\t4) Roll a 20-sided dice')
    choice = input('What would you like to do? ')
    # TODO: based on what the user selects, call the appropriate function above (print the result)

    Continue reading...

Compartilhe esta Página