0

This is very basic, I'm sure, but I'm making a card game and it comes up with this error (I'm sure it's obvious but I don't know what's wrong):

Traceback (most recent call last):   
File "\\MONSRVNSS02\Student$\HG.McLellan\at school work\Computing\Python\not relevant\A[ Random Card Game].py", line 12, in <module>
 answer5 = input(str('Your card is ' + card1 + '. Higher or lower?   '))
 File "<string>", line 1, in <module> NameError: name 'lower' is not defined. 

My code is:

import random

def Random_Card ():
    card_number = ['Ace ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ' , '10 ', 'Jack ', 'Queen ', 'King ']
    card_suit = ['Hearts' , 'Diamonds' , 'Clubs' , 'Spades']
    number = random.choice (card_number)
    suit = random.choice (card_suit)
    return number + suit

card1 = Random_Card()

answer5 = input(str('Your card is ' + card1 + '. Higher or lower?   '))
card2 = Random_Card()

test = 1

while test == 1 :

    if card1 == 'Ace' :
        card1 ==14
    if card1 == 'Jack' :
        card1 == 11
    if card1 == 'Queen' :
        card1 == 12
    if card1 == 'King' :
        card1 == 13

    if card2 == 'Ace' :
        card2 == 14
    if card2 == 'Jack' :
        card2 == 11
    if card2 == 'Queen' :
        card2 == 12
    if card2 == 'King' :
        card2 == 13

    if answer5 == 'higher' :
        if card1 < card2 :
            test = test
    else:

        if card1 > card2:
            test = test + 12

    card1 = Random_Card()

    answer5 = input('Your card is ' + card1 + '. Higher or lower?')
    card2 = Random_Card()

print ("You lose!")
Matheus Lacerda
  • 5,983
  • 11
  • 29
  • 45
  • 3
    In Python 2, you need to use [`raw_input`](https://docs.python.org/2/library/functions.html#raw_input) instead of [`input`](https://docs.python.org/2/library/functions.html#input). – khelwood Mar 26 '18 at 09:58
  • 3
    Possible duplicate of [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – khelwood Mar 26 '18 at 09:59
  • That helped alot thank you – Harry Mclellan Mar 26 '18 at 10:09

0 Answers0