My question is about IF function in WHILE












-3














I would like to ask you why while if loop doesn't work for me, I think the problem is with conditions but I tried to find out where it can be and I couldn't.



import time
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as keyboardController

mouse = Controller ()
keyboard = keyboardController ()
var = 0
a = 0
b = 3
c = 1

time.sleep(5)
while var == 0:
if a < b:
mouse.position = (1199, 924)
time.sleep(0.2)
mouse.click(Button.left, 1)
time.sleep(3)
keyboard.press('n')
keyboard.release('n')
time.sleep(0.7)
keyboard.press('b')
keyboard.release('b')
time.sleep(0.5)
a + c
else:
time.sleep(5)
mouse.position = (48, 445)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (819, 425)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char in "De Gea":
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
time.sleep(1)
mouse.position = (733, 533)
ntime.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (1109, 851)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char2 in "50000":
keyboard.press(char2)
keyboard.release(char2)
time.sleep(0.1)
mouse.position = (1187, 937)
mouse.click(Button.left, 1)
b = 0


I tried many different solutions, instead of a,b,c put there numbers and other things but still doesnt work.
Thanks for any hints and sorry I am just beginner.










share|improve this question


















  • 3




    What does "doesn't work" mean? Be more specific.
    – kindall
    Nov 12 '18 at 16:08










  • Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
    – Rony Kranitz
    Nov 12 '18 at 16:10






  • 1




    What exactly are you trying to achieve with your code?
    – Arnav Borborah
    Nov 12 '18 at 16:11










  • Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
    – Rony Kranitz
    Nov 12 '18 at 16:14










  • var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
    – John Gordon
    Nov 12 '18 at 16:19


















-3














I would like to ask you why while if loop doesn't work for me, I think the problem is with conditions but I tried to find out where it can be and I couldn't.



import time
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as keyboardController

mouse = Controller ()
keyboard = keyboardController ()
var = 0
a = 0
b = 3
c = 1

time.sleep(5)
while var == 0:
if a < b:
mouse.position = (1199, 924)
time.sleep(0.2)
mouse.click(Button.left, 1)
time.sleep(3)
keyboard.press('n')
keyboard.release('n')
time.sleep(0.7)
keyboard.press('b')
keyboard.release('b')
time.sleep(0.5)
a + c
else:
time.sleep(5)
mouse.position = (48, 445)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (819, 425)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char in "De Gea":
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
time.sleep(1)
mouse.position = (733, 533)
ntime.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (1109, 851)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char2 in "50000":
keyboard.press(char2)
keyboard.release(char2)
time.sleep(0.1)
mouse.position = (1187, 937)
mouse.click(Button.left, 1)
b = 0


I tried many different solutions, instead of a,b,c put there numbers and other things but still doesnt work.
Thanks for any hints and sorry I am just beginner.










share|improve this question


















  • 3




    What does "doesn't work" mean? Be more specific.
    – kindall
    Nov 12 '18 at 16:08










  • Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
    – Rony Kranitz
    Nov 12 '18 at 16:10






  • 1




    What exactly are you trying to achieve with your code?
    – Arnav Borborah
    Nov 12 '18 at 16:11










  • Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
    – Rony Kranitz
    Nov 12 '18 at 16:14










  • var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
    – John Gordon
    Nov 12 '18 at 16:19
















-3












-3








-3







I would like to ask you why while if loop doesn't work for me, I think the problem is with conditions but I tried to find out where it can be and I couldn't.



import time
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as keyboardController

mouse = Controller ()
keyboard = keyboardController ()
var = 0
a = 0
b = 3
c = 1

time.sleep(5)
while var == 0:
if a < b:
mouse.position = (1199, 924)
time.sleep(0.2)
mouse.click(Button.left, 1)
time.sleep(3)
keyboard.press('n')
keyboard.release('n')
time.sleep(0.7)
keyboard.press('b')
keyboard.release('b')
time.sleep(0.5)
a + c
else:
time.sleep(5)
mouse.position = (48, 445)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (819, 425)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char in "De Gea":
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
time.sleep(1)
mouse.position = (733, 533)
ntime.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (1109, 851)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char2 in "50000":
keyboard.press(char2)
keyboard.release(char2)
time.sleep(0.1)
mouse.position = (1187, 937)
mouse.click(Button.left, 1)
b = 0


I tried many different solutions, instead of a,b,c put there numbers and other things but still doesnt work.
Thanks for any hints and sorry I am just beginner.










share|improve this question













I would like to ask you why while if loop doesn't work for me, I think the problem is with conditions but I tried to find out where it can be and I couldn't.



import time
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as keyboardController

mouse = Controller ()
keyboard = keyboardController ()
var = 0
a = 0
b = 3
c = 1

time.sleep(5)
while var == 0:
if a < b:
mouse.position = (1199, 924)
time.sleep(0.2)
mouse.click(Button.left, 1)
time.sleep(3)
keyboard.press('n')
keyboard.release('n')
time.sleep(0.7)
keyboard.press('b')
keyboard.release('b')
time.sleep(0.5)
a + c
else:
time.sleep(5)
mouse.position = (48, 445)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (819, 425)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char in "De Gea":
keyboard.press(char)
keyboard.release(char)
time.sleep(0.1)
time.sleep(1)
mouse.position = (733, 533)
ntime.sleep(1)
mouse.click(Button.left, 1)
time.sleep(0.5)
mouse.position = (1109, 851)
time.sleep(0.5)
mouse.click(Button.left, 1)
time.sleep(0.5)
for char2 in "50000":
keyboard.press(char2)
keyboard.release(char2)
time.sleep(0.1)
mouse.position = (1187, 937)
mouse.click(Button.left, 1)
b = 0


I tried many different solutions, instead of a,b,c put there numbers and other things but still doesnt work.
Thanks for any hints and sorry I am just beginner.







python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 16:06









Rony Kranitz

1




1








  • 3




    What does "doesn't work" mean? Be more specific.
    – kindall
    Nov 12 '18 at 16:08










  • Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
    – Rony Kranitz
    Nov 12 '18 at 16:10






  • 1




    What exactly are you trying to achieve with your code?
    – Arnav Borborah
    Nov 12 '18 at 16:11










  • Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
    – Rony Kranitz
    Nov 12 '18 at 16:14










  • var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
    – John Gordon
    Nov 12 '18 at 16:19
















  • 3




    What does "doesn't work" mean? Be more specific.
    – kindall
    Nov 12 '18 at 16:08










  • Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
    – Rony Kranitz
    Nov 12 '18 at 16:10






  • 1




    What exactly are you trying to achieve with your code?
    – Arnav Borborah
    Nov 12 '18 at 16:11










  • Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
    – Rony Kranitz
    Nov 12 '18 at 16:14










  • var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
    – John Gordon
    Nov 12 '18 at 16:19










3




3




What does "doesn't work" mean? Be more specific.
– kindall
Nov 12 '18 at 16:08




What does "doesn't work" mean? Be more specific.
– kindall
Nov 12 '18 at 16:08












Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
– Rony Kranitz
Nov 12 '18 at 16:10




Separately program works fine, in IF and in ELSE, but after 4rd repeat it doesn't switch
– Rony Kranitz
Nov 12 '18 at 16:10




1




1




What exactly are you trying to achieve with your code?
– Arnav Borborah
Nov 12 '18 at 16:11




What exactly are you trying to achieve with your code?
– Arnav Borborah
Nov 12 '18 at 16:11












Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
– Rony Kranitz
Nov 12 '18 at 16:14




Basicly this is 2 sections, 1st is in IF and 2nd is in ELSE, i would like to repeat "program" in IF function 150 times, and after it i need to do comands after ELSE and again with 150 times if..
– Rony Kranitz
Nov 12 '18 at 16:14












var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
– John Gordon
Nov 12 '18 at 16:19






var never changes, so while var == 0 is an infinite loop. Is this intended? Also, a + c does not alter the value of a. It adds a and c together, but it does not assign that result anywhere, so this statement effectively does nothing. Perhaps you meant a = a + c?
– John Gordon
Nov 12 '18 at 16:19














1 Answer
1






active

oldest

votes


















0














I think your problem is that the else branch is never taken, because a and b never change. You have the line



a + c


but what you need to understand is this doesn't do anything. At the start of the program, a + c == 0 + 1 == 1. What does this do for you? Nothing, because that 1 isn't going anywhere. If you want a to change (and thus for the else block to eventually be taken when a < b is no longer true), you have to assign the result of that to a:



a = a + c


Alternatively, you could use the operator +=:



a += c




Also, you're never changing the value of var, so your loop will never end, but I'm assuming that's intentional for the time being






share|improve this answer





















  • Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
    – Rony Kranitz
    Nov 12 '18 at 16:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265936%2fmy-question-is-about-if-function-in-while%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think your problem is that the else branch is never taken, because a and b never change. You have the line



a + c


but what you need to understand is this doesn't do anything. At the start of the program, a + c == 0 + 1 == 1. What does this do for you? Nothing, because that 1 isn't going anywhere. If you want a to change (and thus for the else block to eventually be taken when a < b is no longer true), you have to assign the result of that to a:



a = a + c


Alternatively, you could use the operator +=:



a += c




Also, you're never changing the value of var, so your loop will never end, but I'm assuming that's intentional for the time being






share|improve this answer





















  • Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
    – Rony Kranitz
    Nov 12 '18 at 16:26
















0














I think your problem is that the else branch is never taken, because a and b never change. You have the line



a + c


but what you need to understand is this doesn't do anything. At the start of the program, a + c == 0 + 1 == 1. What does this do for you? Nothing, because that 1 isn't going anywhere. If you want a to change (and thus for the else block to eventually be taken when a < b is no longer true), you have to assign the result of that to a:



a = a + c


Alternatively, you could use the operator +=:



a += c




Also, you're never changing the value of var, so your loop will never end, but I'm assuming that's intentional for the time being






share|improve this answer





















  • Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
    – Rony Kranitz
    Nov 12 '18 at 16:26














0












0








0






I think your problem is that the else branch is never taken, because a and b never change. You have the line



a + c


but what you need to understand is this doesn't do anything. At the start of the program, a + c == 0 + 1 == 1. What does this do for you? Nothing, because that 1 isn't going anywhere. If you want a to change (and thus for the else block to eventually be taken when a < b is no longer true), you have to assign the result of that to a:



a = a + c


Alternatively, you could use the operator +=:



a += c




Also, you're never changing the value of var, so your loop will never end, but I'm assuming that's intentional for the time being






share|improve this answer












I think your problem is that the else branch is never taken, because a and b never change. You have the line



a + c


but what you need to understand is this doesn't do anything. At the start of the program, a + c == 0 + 1 == 1. What does this do for you? Nothing, because that 1 isn't going anywhere. If you want a to change (and thus for the else block to eventually be taken when a < b is no longer true), you have to assign the result of that to a:



a = a + c


Alternatively, you could use the operator +=:



a += c




Also, you're never changing the value of var, so your loop will never end, but I'm assuming that's intentional for the time being







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 16:21









Green Cloak Guy

2,4831720




2,4831720












  • Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
    – Rony Kranitz
    Nov 12 '18 at 16:26


















  • Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
    – Rony Kranitz
    Nov 12 '18 at 16:26
















Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
– Rony Kranitz
Nov 12 '18 at 16:26




Yes, that was the answer, sorry guys, as I said I am just beginner and I think in C+ it worked like this. Thanks for your responses.
– Rony Kranitz
Nov 12 '18 at 16:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265936%2fmy-question-is-about-if-function-in-while%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values