0
While loop
Can we add two conditions in a single while loop using and operator.
5 odpowiedzi
+ 2
Yes, absolutely.
Example:
while 1==1 and 2==2:
print("Hello World!")
+ 2
Well what if we take counter as condition.
Like
While i<=100 and i %2 == 0
+ 2
Debashish Das your example makes maybe less sence. Yes, you can do that. But this loop will only run for even numbers. And maybe only once. It depends on what you are doing with i inside the loop.
Maybe it would be better to put a if statement inside the while loop:
while i <= 100:
if i % 2 == 0:
.... some code
else:
.... some code
+ 1
no = [ "n","no"]
yes =["y","yes"]
con =""
while (cont not in no) and (cont in yes):
con = input("Do you want to continue:")
0
It can work but why do you want the second condition?