Python

Moderators: None (Apply to moderate this forum)
Number of threads: 474
Number of posts: 1166

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Newbie Trouble Posted by mrprchr on 19 Feb 2005 at 9:33 PM
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:\WINDOWS\Desktop\testing.py", line 67, in -toplevel-
battle()
File "C:\WINDOWS\Desktop\testing.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 "\t\tWelcome 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.
Report
Re: Newbie Trouble Posted by Drost on 21 Feb 2005 at 1:29 PM
This message was edited by Drost at 2005-2-21 13:30:16

: 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:\WINDOWS\Desktop\testing.py", line 67, in -toplevel-
: battle()
: File "C:\WINDOWS\Desktop\testing.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 "\t\tWelcome 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.
:

Hi!

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

Drost


Report
Re: Newbie Trouble Posted by mrprchr on 25 Feb 2005 at 10:58 PM
: This message was edited by Drost at 2005-2-21 13:30:16

: : 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:\WINDOWS\Desktop\testing.py", line 67, in -toplevel-
: : battle()
: : File "C:\WINDOWS\Desktop\testing.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 "\t\tWelcome 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.
: :
:
: 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.