-2
\$\begingroup\$

So for my class, I have to design a game that will deal out one card to for each player. I also need to use functions to accomplish this one for the high card game, and another for the face value of the card.

import random
def high_card():
    print("\n High Card")
    print("-----------")

    # Read each player's name
    player1 = input("What is your name player one? ")
    player2 = input("What is your name player two? ")

    # Deal two cards

    print("Card for", player1, ": ", end=' ')
    card1 = face_value()
    print("Card for", player2, ": ", end=' ')
    card2 = face_value()



    # Determine who won and display a message
    if card1 > card2:
        print("Contratulations ", player1, ", YOU WON!", sep='')
    elif card2 > card1:
        print("Contratulations ", player2, ", YOU WON!", sep='')
    else:
        print("The game is a draw; both cards are the same")

def face_value():
    player_card = random.randint(1,13)

    # Display face value of card for player 
    if player_card == 1:
        print("Ace")
    elif player_card == 2:
        print("Two")
    elif player_card == 3:
        print("Three")
    elif player_card == 4:
        print("Four")
    elif player_card == 5:
        print("Five")
    elif player_card == 6:
        print("Six")
    elif player_card == 7:
        print("Seven")
    elif player_card == 8:
        print("Eight")
    elif player_card == 9:
        print("Nine")
    elif player_card == 10:
        print("Ten")
    elif player_card == 11:
        print("Jack")
    elif player_card == 12:
        print("Queen")
    elif player_card == 13:
        print("King")
    else:
        # This will catch any
        # invalid card value
        print("Invalid card")

high_card()
\$\endgroup\$

closed as off-topic by 1201ProgramAlarm, Heslacher, Toby Speight, Vogel612 Jul 8 at 14:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 1201ProgramAlarm, Heslacher, Toby Speight, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Does this code actually work as intended? \$\endgroup\$ – Josiah Jul 3 at 6:39
  • \$\begingroup\$ Your code does not work correctly because you did not return card value from face_value, you just print them. \$\endgroup\$ – Mr Alihoseiny Jul 3 at 14:40
  • \$\begingroup\$ What exactly are you looking for feedback on? The way you have phrased the question just sounds like you want people to improve your homework, could you point out specific bits of the code you aren't sure about or something you would like to change. \$\endgroup\$ – Justin Fay Jul 4 at 7:33
  • \$\begingroup\$ Well, my code crashes when I try the high card function, and I can't seem to figure out why. I'm looking at what I'm doing wrong, and possibly hoping someone can flip the switch in my head so I can understand how to perform it better. \$\endgroup\$ – SIth_Lord_85 Jul 5 at 0:49
  • \$\begingroup\$ Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information. \$\endgroup\$ – Vogel612 Jul 8 at 14:44
1
\$\begingroup\$

First of all: the code does not work, so this is not the appropiate place for your question (code review is to improve code which works). Having said that, I proceed to give you some help (next time, ask your question where appropiate).

card1 and card2 are taking values which are not numbers (look at what face_value() has as an output; it only prints strings which cannot be compared with '>' but does not return any comparable values).

The code can be improved by adding a 'return player_card' at the end of face_value(). That way you ensure card1 and card2 will take the value of the numbers generated by random and you will be able to compare them.

import random
def high_card():
    print("\n High Card")
    print("-----------")

    # Read each player's name
    player1 = input("What is your name player one? ")
    player2 = input("What is your name player two? ")

    # Deal two cards

    print("Card for", player1, ": ", end=' ')
    card1 = face_value()
    print("Card for", player2, ": ", end=' ')
    card2 = face_value()

    # Determine who won and display a message
    if card1 > card2:
        print("Contratulations ", player1, ", YOU WON!", sep='')
    elif card2 > card1:
        print("Contratulations ", player2, ", YOU WON!", sep='')
    else:
        print("The game is a draw; both cards are the same")

def face_value():
    player_card = random.randint(1,13)

    # Display face value of card for player 
    if player_card == 1:
        print("Ace")
    elif player_card == 2:
        print("Two")
    elif player_card == 3:
        print("Three")
    elif player_card == 4:
        print("Four")
    elif player_card == 5:
        print("Five")
    elif player_card == 6:
        print("Six")
    elif player_card == 7:
        print("Seven")
    elif player_card == 8:
        print("Eight")
    elif player_card == 9:
        print("Nine")
    elif player_card == 10:
        print("Ten")
    elif player_card == 11:
        print("Jack")
    elif player_card == 12:
        print("Queen")
    elif player_card == 13:
        print("King")
    else:
        print("Invalid card")
    return player_card

high_card()
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.