Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:33:59+00:00 2026-06-18T15:33:59+00:00

so I’m learning Python with ‘Learn Python The Hard Way’, I am currently writing

  • 0

so I’m learning Python with ‘Learn Python The Hard Way’,
I am currently writing a simple text adventure.

my problem is in the ‘combat’ part of the code (provided below). only the numbers 1 and 2 are meant to be pressed by the user. if a different int is pressed, it correctly throws up ‘sorry don’t understand’, but if a letter is pressed, it freaks out and exits saying, (quite rightly) that it was expecting an int. obviously my question is, how do I set it to expect both, and throw up the error when a letter is pressed?

Thanks in advance 🙂

        while True:
            player_dmg = randint(1, 10)
            enemy_dmg = randint(1, 10)

            if enemy_hp < 0:
                os.system('clear')
                print "[ENEMY NUTRALISED]"
                print
                print hit_e
                raw_input()
                return 'forth_area'
            elif player_hp < 0:
                return 'death'

            else:
                print "[COMBAT OPTIONS]"
                print "1. Attack"
                print "2. Defend"
                print
                choice = raw_input("*>>*")
                choice = int(choice)
                print
            if choice == 1:
                enemy_hp = enemy_hp - player_dmg
                print "[ENEMY STATUS: %d]" % enemy_hp
                print "[DAMAGE DONE: %d]" % player_dmg
                print
                player_hp = player_hp - enemy_dmg
                print "[DAMAGE RECIVED: %d]" % enemy_dmg
                print "[CURRENT STATUS: %d]" % player_hp
            elif choice  == 2:
                enemy_hp = enemy_hp - player_dmg / 2
                print "[ENEMY STATUS %d]" % enemy_hp
                print "[DAMAGE DONE %d]" % player_dmg
                print
                player_hp = player_hp - enemy_dmg
                player_hp = player_hp + 3
                print "[DAMAGE RECIVED: %d]" % enemy_dmg
                print "[CURRENT STATUS: %d]" % player_hp
                print
            else:
                print no_understand
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:34:00+00:00Added an answer on June 18, 2026 at 3:34 pm

    You have:

    choice = raw_input("*>>*")
    choice = int(choice)
    # . . .
    if choice == 1:
    # . . .
    elif choice == 2:
    

    The simplest fix is to use:

    choice = raw_input("*>>*")
    # . . .
    if choice == '1':
    # . . .
    elif choice == '2':
    

    raw_input returns a string. Why convert it to a number? Just test for text '1' and '2', etc. It also makes it easier to add character commands (like 'q' for quit).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.