# A game that deals a high card to one of two players [closed]

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("-----------")

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()

• Does this code actually work as intended? – Josiah Jul 3 '19 at 6:39
• Your code does not work correctly because you did not return card value from face_value, you just print them. – Mr Alihoseiny Jul 3 '19 at 14:40
• 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. – Justin Fay Jul 4 '19 at 7:33
• 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. – SIth_Lord_85 Jul 5 '19 at 0:49
• 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. – Vogel612 Jul 8 '19 at 14:44

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("-----------")

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()