0

The code I had wasn't executing whatsoever. So, I tried it with a basic code:

x=10, if x==10:, print ("Hello"),

This worked. But the moment I extended it to anything else, it wouldn't run eg.:

count=0, x=10, if x==10:, count=count+1, if count == 10:, print ("Hello"), 

(That had correct indents and exc. the commas.) The loop wouldn't loop. Anyone understand why? The other queries similar to this regard a different issue. It won't run through CMDLine either. I did uninstall and reinstall it but that changed nothing.

4
  • 1
    Also count is 11 when it hits the if statement, so it never prints. Commented Jul 28, 2016 at 14:27
  • 2
    Python != MATLAB. You can't separate lines with commas as far as I am aware. Semicolons are OK though. Commented Jul 28, 2016 at 14:31
  • @madphysicist I was using it as, for whatever reason, I could get the lines to separate on here Commented Jul 29, 2016 at 15:46
  • I was using the comma to separate the lines as I couldn't get them to go to the next line Commented Jul 29, 2016 at 15:52

1 Answer 1

1

The reason your loop won't run is because there isn't a loop. I think what you're trying to do is this.

for i in range(11):
    if i == 10:
        print('Hello')

With the current string of commands that you're running, count is simply being increment from 0 to 1, and since count != 10 at that point, you never see Hello.

Sign up to request clarification or add additional context in comments.

6 Comments

I think OP meant conditional rather than loop, but that's just based on assumption.
@Jerrybibo perhaps, but regardless...if he's expecting to see Hello printed, then his logic is completely off.
Let's hope OP clarifies his question.
Yes, a loop is what I meant. But the problem arises with imported code, that works at school with the same version, doesn't work at home. Even if I type up an exact copy, it fails to execute any part that would do so normally. As I said, I have in installed and reinstalled Python 3.5 but no luck. Thanks
@CalFord are you using the same version of python at school and at home? I know a lot of education institutions still use python2.7 because of stability.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.