patternpythonMinor
Simple Card Game in Python
Viewed 0 times
pythongamesimplecard
Problem
After finishing up finals, I wasn't really working on coding for a while. I decided to write a card game to get back into the programming scene. I'm just wondering if there's anything that I missed or could be improved upon.
import random
suit_choices = ("Diamonds", "Hearts", "Clubs", "Spades")
suit_picked = random.choice(suit_choices)
number_picked = random.randint(2,9)
while True:
print suit_choices
user_card = raw_input('\nEnter a suit to pick from. Your choices are listed above. ').title()
if user_card == suit_picked:
print '\nYou guessed the suit type correct!'
user_number = input('\nNow pick a number card (2-9) ')
if user_number == number_picked:
print '\n You guessed the card number correct!'
break
else:
print '\nShucks. Try again.'
continue
else:
print '\nOH NO'
continueSolution
continueBoth your continue statements fall back to the end of the loop anyway, so they are redundant.
user_number = input('\nNow pick a number card (2-9) ')In the other place you correctly used
raw_input. The difference is that input executes the given string as an expression, which is seldom what you want (and usually unsafe).Nothing else really. The
\ns at the start of all your strings are a bit ugly, and some people prefer using empty print statements to indicate extra empty lines.Code Snippets
user_number = input('\nNow pick a number card (2-9) ')Context
StackExchange Code Review Q#52677, answer score: 5
Revisions (0)
No revisions yet.