http://learnpythonth.../book/ex43.html
Good afternoon everyone. Im new to this site and looking for a little help. I have been working with zed shaws book learnpython thehardway and have come along pretty good. He gives extra credit but no answers to the extra credit and I am really stuck. I posted a link above so you guys can check out what Im talking about. Extra credit 2 is how to put a cheat into the little game code written. I have figured out a way for certain parts but Zed says you should be able to do it in 2 lines. The other main question I have is how do you use doc comments inside a class? I try saying functionname.__doc__ but it says the function doesnt exist. If i put quotes around it it gives me the definition of a string. Any help would be greatly appreciated. Thanks for your time.
Help with classes and doc comments
Page 1 of 15 Replies - 1032 Views - Last Post: 12 July 2012 - 05:08 PM
Replies To: Help with classes and doc comments
#2
Re: Help with classes and doc comments
Posted 12 July 2012 - 03:50 PM
lol, after line 81 add:
print code
#3
Re: Help with classes and doc comments
Posted 12 July 2012 - 03:57 PM
@jared.deckard Umm, what?
Question 2) How are you tackling it now? There is loads of solutions for a single problem. It say HE can do it in two lines, doing it in 2 lines or 20 lines doesn't make for a less valid solution.
A docstring inside a class? Maybe you are not instantiating the class and calling the class method, does this help?
If this isn't what you mean.. show us some code! I'm sure we can clear it up
Question 2) How are you tackling it now? There is loads of solutions for a single problem. It say HE can do it in two lines, doing it in 2 lines or 20 lines doesn't make for a less valid solution.
A docstring inside a class? Maybe you are not instantiating the class and calling the class method, does this help?
class MyClass:
def myfunction(self):
""" This is the doc string for this method! """
pass
...
# X is now an instance of "MyClass" object
>> X = MyClass()
>> print(X.myfunction.__doc__)
...
This is the doc string for this method!
If this isn't what you mean.. show us some code! I'm sure we can clear it up
This post has been edited by Simown: 12 July 2012 - 04:11 PM
#4
Re: Help with classes and doc comments
Posted 12 July 2012 - 04:13 PM
Simown, on 12 July 2012 - 03:57 PM, said:
@jared.deckard Umm, what?
I wasn't answering the main question.
The trick to adding cheats in one line with 2 words it to simply print the random number you are supposed to guess.
I think the author means 2 words on one line for each hard room.
That game is funny.
#5
Re: Help with classes and doc comments
Posted 12 July 2012 - 04:15 PM
Ah, I completely skipped the actual code and read the questions. Completely out of context answer for me. My bad.
Yeah, that'd do nicely. Done it before I'm guessing?
Yeah, that'd do nicely. Done it before I'm guessing?
This post has been edited by Simown: 12 July 2012 - 04:15 PM
#6
Re: Help with classes and doc comments
Posted 12 July 2012 - 05:08 PM
Thanks for the help. Setting the class to a variable in this case X worked.
This is how i did it before.
That didnt work said function wasnt a function. But got it cleared up now.
As far as the cheat goes just putting print code is kind of cheesy. I thought of it more as like a real cheat in a video game. I set a value to be an auto correct for the code. Like if you typed 1000 it would automatically allow you into the next room. I had to use an elif and a couple other things but i like it a little more then just saying print.
This is how i did it before.
class Myclass(object):
def function(self):
pass
print function.__doc__
That didnt work said function wasnt a function. But got it cleared up now.
As far as the cheat goes just putting print code is kind of cheesy. I thought of it more as like a real cheat in a video game. I set a value to be an auto correct for the code. Like if you typed 1000 it would automatically allow you into the next room. I had to use an elif and a couple other things but i like it a little more then just saying print.
This post has been edited by Simown: 12 July 2012 - 05:20 PM
Reason for edit:: Fixed code tags
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|