×
all 4 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20d%20%3D%200%0A%20%20%20%20c%20%3D%200%0A%20%20%20%20dmm%20%3D%20120%20%0A%20%20%20%20dm%20%3D%20100%0A%20%20%20%20%0A%20%20%20%20a%20%3D%20input(%22if%20you%20want%20to%20figth%20the%20monstar%20preas%201%22)%0A%20%20%20%20while%20True%3A%0A%20%20%20%20%20%20%20%20if%20a%20%3D%3D%20%221%22%20or%20a%20%3D%3D%20%22%D9%A1%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print%20(%221-fighting%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print%20(%222-Escape%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print%20(%223-speech%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print%20(%224-forgives%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20b%20%3D%20input%20(%22Write%20any%20of%20the%20numbers%20provided.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20b%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dmm%20-%3D%20random.randint(10%2C29)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dm%20-%3D%20random.randint(10%2C24)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20c%2B%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22youer%20health%20is%22%2C%20dm)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22monstar%20health%20is%22%2C%20dmm)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20dmm%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20win%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20dm%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20lose%20%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20b%20%3D%3D%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20c%20%3E%3D%203%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20wan%20and%20escep%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20c%20%3C%203%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20cant%20escep%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20b%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20talk%20to%20the%20monstar%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20d%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20b%3D%3D%224%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20d%20%3E%3D%203%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print%20(%22you%20wan%20and%20escap%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20d%20%3C%203%3A%20print%20(%22you%20cant%20escape%22)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Bro%2C%20there%20is%20no%20option%20for%20%22%2C%20a)%0A%20%20%20%20%20%20%20%20%20%20%20%20b%20%3D%20input%20(%22preas%202%20to%20reastr%22)%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20name()%0A%0A%0Aname()&timestep=.5&play) to see the program state change step by step.

[–]Tooladoo 2 points3 points  (0 children)

For the future, you never wanna use super generic non-descript variables like you have here. If anyone looks at your code, or even you yourself months down the line, it'll be very difficult to tell what's going on.

[–]PureWasian 1 point2 points  (0 children)

Good start for a beginner project.

Highly want to echo what the other comment said about variable names. You will have a hard time a week later remembering these. Especially after adding more complexity to it. Some suggestions: - d --> talk_count - c --> attack_count - dmm --> monster_health - dm --> player_health - b --> player_input - a --> player_input (same as above)

Not sure what's going on with all of the string typos, but I would also advise against doing a recursive call to name() where there is no need to create nested stack frames like that.

An alternative to this would be to have an initial, preliminary while loop that just does:

... a = None while a != "1": a = input("Fight? Press 1 and Enter") if a != "1": print(f"no option for {a} bro") ...

That way you only invoke name() once

More from r/PythonLearning

  Hide

Comments, continued...

[–]burnt-store-studio 0 points1 point  (0 children)

Good start!

(Sorry, I’m on mobile, so the following is not code-formatted.)

I can’t quite tell, but it looks like you might have a backslash in this line:

if a == “1” or a == “\”:

and if so, this will cause an error because it’s escaping the closing double quote. If you’re wanting to accept a double quote from the user, then you could do:

… or a == ‘“‘:

If you’re wanting to recognize when the user enters a backslash, then you’ll want to have two backslashes:

… or a == “\\”:

I hope that helps! If I’ve mis-read your code please excuse me.

Have fun! Write back when you have more questions! 🙂