Ask coding questions

← Back to all posts
Repeating loop without explanation
xolyon

I am making a Monopoly game (code worked fine) then I added the final if statement (at the bottom of the move function) then after adding that and running the code (if you land at the property) it just repeats its name infinitely I know there is a while loop but this cannot be the problem as it worked earlier

I know I repeat the same code over and over but I had no choice, I used this code and it gave me an attribute error (don't worry I assigned the pN with prop so I don't think that was the error but still:

and finally, I am sorry for dumping you 600 lines of code but I am afraid that any of the code could lead to this problem

Voters
ElmaWikstrm
jascas03
xolyon
Comments
hotnewtop
[deleted]

The error is occurring in one of these lines of code: 225, 257, or 289. I suggest changing the text output (using the print function) immediately after the while loops to trace down which one it is.

Do you know how to write functions? Your code, though neatly laid out, uses nested while loops. This is not good as things can get complex quite quickly and the code is hard to debug. Splitting out the different parts of your program code into functions (some may have while loops) would be helpful. Done well the repeated parts of your code could be eliminated.

[deleted]

@malvoliothegood
I think my python is on some stuff, I ran it again it worked normally, then again to double-check and then it just skipped the code which processes the properties ...? (changed nothing)

[deleted]

@malvoliothegood Thanks for helping out, I checked the while loops it looks secure and yes I (think I) know how to make functions

if you are so helpful, would it be cool if I invited you to the project to help me debug

xolyon

@malvoliothegood sorry @girnusa17 is my second account

[deleted]

@xolyon
I would be glad to help you out, so go ahead and share the repl.

xolyon

@malvoliothegood Bruh I am so dumb it was the indents for some reason after the first print replit didn't do the indents that's why it is infinitely repeating the name

oh yeah, and have you helped with the code in any other way?

[deleted]

@xolyon
I have started my own version of the Monopoly game using the rules in your repl. I am finding it hard to do because the game has a lot of rules that interact with each other. It would be a major mission to code it well. I think it would be better to tackle an easier game, for example Blackjack where the rules are simpler.

xolyon

@malvoliothegood that's a bit dead

xolyon

@malvoliothegood no point in a challenge then

xolyon

@malvoliothegood
don't know if you're still interested but I ran into another error where After landing on 1-3 properties the code would process but not execute however I managed to fix that in the code below (buy is part of property class)

[deleted]

@xolyon Great to see that you are persisting with your game :-) Your code looks sound.

Have you have heard of returning early . It's using used when checking for erors. The decisions part of your function could be written thus:

The logic of your code is probably easier to follow though. Keep up the good work.

xolyon

@malvoliothegood yeah I see what you have done but I think print would be easier in my situation (if you haven't noticed Def buy is part of class)

And are you still working on Monopoly?

[deleted]

@xolyon Haven't looked at Monopoly lately. Have started making a Blackjack game using Python, for fun. Have made a HTML/CSS/JavaScript version in the past.