Python Forum
I'm not sure why this code isn't printing... Can someone tell me?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm not sure why this code isn't printing... Can someone tell me?
#1
Can someone tell me what's wrong with the code down below? It isn't printing and I've tried removing the int() and all that but it just won't print? I have my complete code below

print "You do " + int(hero_att) + " with your " + hero_weapon + "!"

Get to the error by
-Enter Name
-Choose weapon
-say Stay
-say Yes
-choose Attack
________________________________________________________________________________________________________________


hero_hp = 50

bow_stats = "Bow Stats: Attack - 7   Defense - 2   Range - 5"
bow_att = 7
bow_def = 2
bow_ran = 5

sword_stats = "Sword Stats: Attack - 10   Defense - 2   Range - 1"
sword_att = 10
sword_def = 2
sword_ran = 1

spear_stats = "Spear Stats: Attack - 6   Defense - 4   Range - 2"
spear_att = 6
spear_def = 4
spear_ran = 2

monster_1_hp = 10
monster_1_att = 7
monster_1_def = 0
monster_1_ran = 1

print "WARNING!"
print "THIS GAME IS CASE SENSITIVE WHEN ANSWERING!"
print "ALWAYS ANSWER WITH THE FIRST LETTER CAPITAL!"
print "THIS IS STILL A WORK IN PROGRESS!!!"
print ""
print ""
print ""
hero_name = input("Enter Your Hero's Name: ")
print ""
print "Hello Sir " + hero_name + ", my name is Grima."
print "I will be your guide on this journey!"
print "But first, you must choose your weapon!"
print "What will it be?" 
print "If you wish to know the weapons stats, type 'Info'"
print "Bow, Sword, Spear, or Info?"
hero_weapon = input("What do you choose: ")

if hero_weapon == "Info":
    print bow_stats
    print sword_stats
    print spear_stats
    hero_weapon = input("Bow, Sword, or Spear: ")

if hero_weapon == "Bow":
    print "You have chosen the Bow!"
    hero_att = bow_att
    hero_def = bow_def
    hero_ran = bow_ran

if hero_weapon == "Sword":
    print "You have chosen the Sword!"
    hero_att = sword_att
    hero_def = sword_def
    hero_ran = sword_ran

if hero_weapon == "Spear":
    print "You have chosen the Spear!"
    hero_att = spear_att
    hero_def = spear_def
    hero_ran = spear_ran

print ""
print "You arrive at the door to the dungeon!"
choice_1 = input("Do you 'Leave' or 'Stay'?")

if choice_1 == "Leave":
    print ""
    print "You decide to leave and go live a plain old..."
    print "boring life in the city."
    print "You live to see the dragon that was..."
    print "at the end of the dungeon slay everyone..."
    print "and conquer the world!!!"
    print ""
    print "THE BAD ENDING"
    
if choice_1 == "Stay":
    print "You decide to stay!"
    print "When you open the door to the dungeon..."
    print "You see a descending staircase down into the dungeon..."

if choice_1 == "Stay":  
    decision = input("Do you still wish to continue?(Yes/No) ")
    print ""

if decision == "No":
    print ""
    print "You decide to leave and go live a plain old..."
    print "boring life in the city."
    print "You live to see the dragon that was..."
    print "at the end of the dungeon slay everyone..."
    print "and conquer the world!!!"
    print ""
    print "THE BAD ENDING"
    
if decision == "Yes":
    print "You decide to continue on with your journey!"
    print "You descend into the first room..."
    print "But there is a monster blocking your path!"
    print "Do you 'Attack' or 'Defend'?"
    ad = input("Attack or Defend? ")
    
if ad == "Attack":
    print "You decide to attack the monster!"
    print "You do " + int(hero_att) + " with your " + hero_weapon + "!"
    ca = hero_att - monster_1_def
    monster_1_hp = monster_1_hp - ca
    print "Monster's Current Health: " + monster_1_hp
    if monster_1_hp > 0:
        print "The monster attacks you!"
        da = monster_1_att - hero_def
        hero_hp = hero_hp - da
        print hero_name + "'s Current Health: " + hero_hp + "!"
        jump(101)
    else:
        print "Congratulations!!!"
        print "You've slayed your very first monster!"
        print "You received 500 gold!"
        print ""
        print "Grima: You have done very well for now..."
        print "But can you beat the next one?"
        print ""
        print ""
        print ""
        print "END!!! (for now...)"
Reply
#2
What do you get if you add a print statement before the if ad == "Attack":

if decision == "Yes":
    print "You decide to continue on with your journey!"
    print "You descend into the first room..."
    print "But there is a monster blocking your path!"
    print "Do you 'Attack' or 'Defend'?"
    ad = input("Attack or Defend? ")

print("ad = " + ad)

if ad == "Attack":
    print "You decide to attack the monster!"
    print "You do " + int(hero_att) + " with your " + hero_weapon + "!"
(Also, unless you have a really good reason for using Python 2, you should really work with Python 3.)
Reply
#3
Oh okay, I'll try that and sorry about using Python 2, I made this at a website called codehs.com because we use it in class. I'm ahead of other people, so I decided to mess around. Thanks for the info I'll try it.

I tried what you said and it didnt't work...
Reply
#4
(Mar-01-2018, 06:42 PM)Wilminer4 Wrote: I tried what you said and it didnt't work...
didn't work is not very useful
Post your code in python tags and full traceback in error tags
Reply
#5
(Mar-01-2018, 06:42 PM)Wilminer4 Wrote: Oh okay, I'll try that and sorry about using Python 2, I made this at a website called codehs.com because we use it in class. I'm ahead of other people, so I decided to mess around. Thanks for the info I'll try it.

I tried what you said and it didnt't work...

I see what's going on. Try using the raw_input() function instead of input().

From the 2.7 docs:
Quote:input([prompt])
Equivalent to eval(raw_input(prompt)).

This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.

Consider using the raw_input() function for general input from users.
Reply
#6
(Mar-01-2018, 06:54 PM)buran Wrote:
(Mar-01-2018, 06:42 PM)Wilminer4 Wrote: I tried what you said and it didnt't work...
didn't work is not very useful
Post your code in python tags and full traceback in error tags

Sorry I'm new to this and don't understand what you mean. Let me look at other peoples and re-read the link you sent me for tags... Sad
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code printing twice hypersdevelopment 3 6,255 Sep-09-2018, 12:06 AM
Last Post: hypersdevelopment

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020