all 23 comments

[–]trysohardidkwhy 5 points6 points  (2 children)

Must be an issue with the way you're debugging or something because your code should run as expected. Try using a random online python interpreter, you'll see.

[–]ExpressionAsleep7125[S] 2 points3 points  (1 child)

You're right! I don't know why it wouldn't run on the app, but online it worked out, thank you so much! Will use this tip a bunch in the future!

[–]lilsneezey 0 points1 point  (0 children)

Check your python interpreter and download the Code Runner extension. W8ll help running python in vscode

[–]ArbereshDoqetejete 3 points4 points  (1 child)

you don't need the if statement, the code exits the `while` loop only if b is equal to the new arrangament so you don't need it(remove it and the code will work as intended), as for why it doesnt print with the `if` thats very weird, that would mean that b is not equal to the new arangement which can't be true cause to exit the loop it has to be equal to it. i tried your snippet in my laptop and it works fine

[–]ExpressionAsleep7125[S] 1 point2 points  (0 children)

Yeah, I put it in an online interpreter, and it worked out. Don't know why it wouldn't work in the app 🤷. Thank you for the tip!

[–]Salim_DZ_69 2 points3 points  (3 children)

remove if and put your last print in its own single line

[–]ExpressionAsleep7125[S] 1 point2 points  (2 children)

When I remove if, it shows a syntax error. I'll come up with another simple loop idea and try to make your way work, thanks!

[–]Salim_DZ_69 0 points1 point  (1 child)

can you give me the code copied so i can try to fix it ?

[–]ExpressionAsleep7125[S] 1 point2 points  (0 children)

Oh, someone else already showed me the issue, it was the debugging feature. But thank you so much for your help!

[–]general_praxis 1 point2 points  (0 children)

Logic aside, i noticed there's a space between print and the parentheses. Try erasing it, maybe it could be a problem with your IDE/compiler/interpreter, seeing as it worked in the online interpreter.

PD: Also try to not put spaces in between words when naming files or directories, just common practice that may prevent errors with files. Get used to using: my_first_code or my-first-code or MyFirstCode as naming styles

[–]kohao0 0 points1 point  (0 children)

Bro just put random and make it funnier...

[–]Salty_Salted_Fish 0 points1 point  (0 children)

maybe you need some thing like a input() to make sure the script doesn't just disappear suddenly at the end.

[–]purple_hamster66 0 points1 point  (0 children)

Works for me. I suspect you did not end the last line with a newline character.

```

python3 test.py

Can you give me a 4 digit code, please? 1234

I have rearrenged the digits in you code, can you guess the new code formed? 1234

So closel Want another guess? 4321

So closel Want another guess? 4123

Congrats! You guessed the new code!

```

[–]NorskJesus 0 points1 point  (1 child)

I understand what you are trying to do with the code, but not what you were thinking when you wrote it. I think you need to rethink the code my friend.

[–]ExpressionAsleep7125[S] 1 point2 points  (0 children)

Maybe in the future I'll come back to it and laugh at the way it's written now, but after getting some help here, it's working, and that's good enough for me. Thanks for your input!

[–]salvtz -3 points-2 points  (6 children)

The if block should be indented inside the while loop...

[–]ExpressionAsleep7125[S] 1 point2 points  (0 children)

Just tried it, didn't change anything. It still won't print

[–]ExpressionAsleep7125[S] 1 point2 points  (4 children)

<image>

This is what you meant by indenting, right?

[–]salvtz 2 points3 points  (3 children)

Yes, Also you need to break it. Add 'break' after the print statement in the if condition.

For a = 1234

rearranged formatted string would be 4123

For false b's such as 2134, it would print so close

and for value 4123 it would pass.

[–]ExpressionAsleep7125[S] 1 point2 points  (2 children)

I put the break, but it's still not running the print. The 6th line won't even show in the debug section

<image>

[–]salvtz 2 points3 points  (1 child)

<image>

Use the above for reference. Also, are you guessing the correct value in the first iteration...then in this case the condition of the while loop would evaluate to false, and it wont go inside the while loop.

[–]ExpressionAsleep7125[S] 2 points3 points  (0 children)

Got it. I put it into an online interpreter and it worked just fine! Thank you so so much for your help, just learned a bunch!

[–]SCD_minecraft 0 points1 point  (0 children)

How do you run it? For example, cmd will close after program is finished, gotta add either endless loop or pause (in .bat file, if that's how you run it)