## Card game Guerra(aka War)

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

### Card game Guerra(aka War)

Card Game Guerra. Save program as guerra.py. Write a program that generates a random number, between 1 and 13, representing the rank of a playing card (1 represents the Ace, 11 represents the Jack, 12 represents the Queen, and 13 represents the King --we shall call 11, 12, and 13, the face cards). The program asks the user to enter a number between 1 and 13, representing his/her card, and displays a message indicating whether the user or the computer wins, loses or draws, based on the following rules:

The card with the highest rank wins,
However, Ace beats any of the face cards.
If both players have the same card, there is a tie.

Note: Your program must show an error message and quit if the user enters a number that is not between 1 and 13.

Here are some sample executions:

Guerra!
Enter the rank of your card (a number between 1 and 13): 7
The computer has 9
Computer Wins!

Guerra!
Enter the rank of your card (a number between 1 and 13): 12
Computer has 5
You Win!

Guerra!
Enter the rank of your card (a number between 1 and 13): 13
Computer has Ace
Computer Wins!

So here is what I have so far

Code: Select all
`import randomprint("Guerra!")you = input("Enter a number between 1 and 13:",)computer = print("The computer has a:",random.randint(1, 13))if computer == you and you == computer:    print("This is a Tie!")elif computer == 1 and you >= 11:    print("Computer Wins!")elif you == 1 and computer >= 11:    print("You Win!")elif you == 1 and computer <= 10:    print("Computer Wins!")elif you == 2 and computer > 2:    print("Computer Wins!")elif you == 3 and computer > 3:    print("Computer Wins!")elif you == 4 and computer > 4:    print("Computer Wins!")elif you == 5 and computer > 5:    print("Computer Wins!")elif you == 6 and computer > 6:    print("Computer Wins!")elif you == 7 and computer > 7:    print("Computer Wins!")elif you == 8 and computer > 8:    print("Computer Wins!")elif you == 9 and computer > 9:    print("Computer Wins!")elif you == 10 and computer > 10:    print("Computer Wins!")elif computer == 1 and you <= 10:    print("You Win!")elif computer == 1 and you <= 10:       print("You Win!")elif computer == 2 and you > 2:    print("You Win!")elif computer == 3 and you > 3:    print("You Win!")elif computer == 4 and you > 4:    print("You Win!")elif computer == 5 and you > 5:    print("You Win!")elif computer == 6 and you > 6:    print("You Win!")elif computer == 7 and you > 7:    print("You Win!")elif computer == 8 and you > 8:    print("You Win!")elif computer == 9 and you > 9:    print("You Win!")elif computer == 10 and you > 10:    print("You Win!")else:    print("This is not a number between 1 and 13 try again.")   `

Guerra!
Enter a number between 1 and 13:1
The computer has a: 7
This is not a number between 1 and 13 try again.

The only output I get is from the ELSE. I have tried several numbers but keep coming up with the same output each time.

Any Help would be appreciated
nzieno

Posts: 16
Joined: Fri Jul 29, 2016 12:38 am

### Re: Card game Guerra(aka War)

Are you running this in Python 3? If so, input will return a string. A string is not a number between 1 and 13.

If that's the problem, calling int() on the input will fix it.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801

Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

### Re: Card game Guerra(aka War)

Figured it out had to computer its own variable with random.randint(1, 13) and then i just made a print statement for what the computer has with the variable computer attached to it. Here is my final code

Code: Select all
`    import randomprint("Guerra!")you = int(input("Enter a number between 1 and 13:" ))computer = random.randint(1, 13)computer1 = print("The computer has a:",computer)if computer == you and you == computer:    print("This is a Tie!")elif computer == 1 and you >= 11:    print("Computer Wins!")elif you == 1 and computer >= 11:    print("You Win!")elif you == 1 and computer <= 10:    print("Computer Wins!")elif you == 2 and computer > 2:    print("Computer Wins!")elif you == 3 and computer > 3:    print("Computer Wins!")elif you == 4 and computer > 4:    print("Computer Wins!")elif you == 5 and computer > 5:    print("Computer Wins!")elif you == 6 and computer > 6:    print("Computer Wins!")elif you == 7 and computer > 7:    print("Computer Wins!")elif you == 8 and computer > 8:    print("Computer Wins!")elif you == 9 and computer > 9:    print("Computer Wins!")elif you == 10 and computer > 10:    print("Computer Wins!")elif computer == 1 and you <= 10:    print("You Win!")elif computer == 1 and you <= 10:       print("You Win!")elif computer == 2 and you > 2:    print("You Win!")elif computer == 3 and you > 3:    print("You Win!")elif computer == 4 and you > 4:    print("You Win!")elif computer == 5 and you > 5:    print("You Win!")elif computer == 6 and you > 6:    print("You Win!")elif computer == 7 and you > 7:    print("You Win!")elif computer == 8 and you > 8:    print("You Win!")elif computer == 9 and you > 9:    print("You Win!")elif computer == 10 and you > 10:    print("You Win!")else:    print("This is not a number between 1 and 13 try again.")        `
nzieno

Posts: 16
Joined: Fri Jul 29, 2016 12:38 am