Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Newbie Trouble

mrprchrmrprchr Posts: 6Member
Hey guys... im new to programming and I decided to try Python. So far so good, I've been reading and all making progress. I decided to write a stupid text game just to test how i was doing. Well, I get this error when i run it (not complete just testing it and doing it as i go):
Traceback (most recent call last):
File "C:WINDOWSDesktop esting.py", line 67, in -toplevel-
battle()
File "C:WINDOWSDesktop esting.py", line 32, in battle
monster()
TypeError: 'int' object is not callable
This is the code i have so far:
import random
life = ""
attack = ""
monster_life = ""
monster_attack = ""
first = ""
gold = ""
choice = ""
items = ""
def battle():
monster = random.randrange(3)
if monster == 0:
print "Oh no! It's Godzilla!"
monster_life = 40
monster_attack = 10
elif monster == 1:
print "Oh... the unholy Werewolf!"
monster_life = 50
monster_attack = 15
elif monster == 2:
print "The dead walketh: tis a Vampere!"
monster_life = 55
monster_attack = 17
elif monster == 3:
print "The childrens nightmare... the BOOGEY MAN!"
monster_life = 60
monster_attack = 22
first = random.randrange(2) #defines who attacks first
if first == 0:
hero()
elif first == 1:
monster()
while (life > 0) or (monster_life > 0):
hero()
monster()
gold += 100

def hero():
print
"""
To Attack hit a
To use a life potion hit l
"""
choice = raw_input("please choose what to do: ")
if choice == "a":
monster_life += -attack
elif choice == "l":
life += 50

def monster():
life += -monster_attack

print " Welcome to Monster"
name = raw_input("Please enter your characters's name: ")
print "Welcome", name,"!"
life = 100
attack = 25
items = ("sword",
"life potion",
"shield",
"poison")
gold = 200
print "To start with you have" , items,"in your inventory."
print "As you progress through the game you can earn money and buy items at the Shop."
print "Are you ready?"
raw_input("Hit 'Enter' to continue on your quest.")
battle()
I know that it's probably really shoddy coding, but im new and just trying to learn. If any one could help me find my problem, I would really appreciate it. Any suggestions are welcome.

Comments

  • DrostDrost Posts: 24Member
    [b][red]This message was edited by Drost at 2005-2-21 13:30:16[/red][/b][hr]
    : Hey guys... im new to programming and I decided to try Python. So far so good, I've been reading and all making progress. I decided to write a stupid text game just to test how i was doing. Well, I get this error when i run it (not complete just testing it and doing it as i go):
    : Traceback (most recent call last):
    : File "C:WINDOWSDesktop esting.py", line 67, in -toplevel-
    : battle()
    : File "C:WINDOWSDesktop esting.py", line 32, in battle
    : monster()
    : TypeError: 'int' object is not callable
    : This is the code i have so far:
    [code]
    : import random
    : life = ""
    : attack = ""
    : monster_life = ""
    : monster_attack = ""
    : first = ""
    : gold = ""
    : choice = ""
    : items = ""
    : def battle():
    : [red]monster[/red] = random.randrange(3)
    : if monster == 0:
    : print "Oh no! It's Godzilla!"
    : monster_life = 40
    : monster_attack = 10
    : elif monster == 1:
    : print "Oh... the unholy Werewolf!"
    : monster_life = 50
    : monster_attack = 15
    : elif monster == 2:
    : print "The dead walketh: tis a Vampere!"
    : monster_life = 55
    : monster_attack = 17
    : elif monster == 3:
    : print "The childrens nightmare... the BOOGEY MAN!"
    : monster_life = 60
    : monster_attack = 22
    : first = random.randrange(2) #defines who attacks first
    : if first == 0:
    : hero()
    : elif first == 1:
    : [red]monster()[/red]
    : while (life > 0) or (monster_life > 0):
    : hero()
    : monster()
    : gold += 100
    :
    : def hero():
    : print
    : """
    : To Attack hit a
    : To use a life potion hit l
    : """
    : choice = raw_input("please choose what to do: ")
    : if choice == "a":
    : monster_life += -attack
    : elif choice == "l":
    : life += 50
    :
    : def monster():
    : life += -monster_attack
    :
    : print " Welcome to Monster"
    : name = raw_input("Please enter your characters's name: ")
    : print "Welcome", name,"!"
    : life = 100
    : attack = 25
    : items = ("sword",
    : "life potion",
    : "shield",
    : "poison")
    : gold = 200
    : print "To start with you have" , items,"in your inventory."
    : print "As you progress through the game you can earn money and buy items at the Shop."
    : print "Are you ready?"
    : raw_input("Hit 'Enter' to continue on your quest.")
    : battle()
    [/code]

    : I know that it's probably really shoddy coding, but im new and just trying to learn. If any one could help me find my problem, I would really appreciate it. Any suggestions are welcome.
    :

    Hi!

    You have a numerical variable and a function both named monster.

    Drost


  • mrprchrmrprchr Posts: 6Member
    : [b][red]This message was edited by Drost at 2005-2-21 13:30:16[/red][/b][hr]
    : : Hey guys... im new to programming and I decided to try Python. So far so good, I've been reading and all making progress. I decided to write a stupid text game just to test how i was doing. Well, I get this error when i run it (not complete just testing it and doing it as i go):
    : : Traceback (most recent call last):
    : : File "C:WINDOWSDesktop esting.py", line 67, in -toplevel-
    : : battle()
    : : File "C:WINDOWSDesktop esting.py", line 32, in battle
    : : monster()
    : : TypeError: 'int' object is not callable
    : : This is the code i have so far:
    : [code]
    : : import random
    : : life = ""
    : : attack = ""
    : : monster_life = ""
    : : monster_attack = ""
    : : first = ""
    : : gold = ""
    : : choice = ""
    : : items = ""
    : : def battle():
    : : [red]monster[/red] = random.randrange(3)
    : : if monster == 0:
    : : print "Oh no! It's Godzilla!"
    : : monster_life = 40
    : : monster_attack = 10
    : : elif monster == 1:
    : : print "Oh... the unholy Werewolf!"
    : : monster_life = 50
    : : monster_attack = 15
    : : elif monster == 2:
    : : print "The dead walketh: tis a Vampere!"
    : : monster_life = 55
    : : monster_attack = 17
    : : elif monster == 3:
    : : print "The childrens nightmare... the BOOGEY MAN!"
    : : monster_life = 60
    : : monster_attack = 22
    : : first = random.randrange(2) #defines who attacks first
    : : if first == 0:
    : : hero()
    : : elif first == 1:
    : : [red]monster()[/red]
    : : while (life > 0) or (monster_life > 0):
    : : hero()
    : : monster()
    : : gold += 100
    : :
    : : def hero():
    : : print
    : : """
    : : To Attack hit a
    : : To use a life potion hit l
    : : """
    : : choice = raw_input("please choose what to do: ")
    : : if choice == "a":
    : : monster_life += -attack
    : : elif choice == "l":
    : : life += 50
    : :
    : : def monster():
    : : life += -monster_attack
    : :
    : : print " Welcome to Monster"
    : : name = raw_input("Please enter your characters's name: ")
    : : print "Welcome", name,"!"
    : : life = 100
    : : attack = 25
    : : items = ("sword",
    : : "life potion",
    : : "shield",
    : : "poison")
    : : gold = 200
    : : print "To start with you have" , items,"in your inventory."
    : : print "As you progress through the game you can earn money and buy items at the Shop."
    : : print "Are you ready?"
    : : raw_input("Hit 'Enter' to continue on your quest.")
    : : battle()
    : [/code]
    :
    : : I know that it's probably really shoddy coding, but im new and just trying to learn. If any one could help me find my problem, I would really appreciate it. Any suggestions are welcome.
    : :
    :
    : Hi!
    :
    : You have a numerical variable and a function both named monster.
    :
    : Drost
    :
    :
    :



    Oh... so simple but I missed it. Thank you for taking the time to reply and I really appreciate it.
Sign In or Register to comment.