How Do I use logical operators [duplicate]
This question already has an answer here:
Why does checking a variable against multiple values with `OR` only check the first value? [duplicate]
4 answers
How to test multiple variables against a value?
19 answers
I have tried everything and if you don't choose "ST" it constantly loops round the while loop. I am not sure what to do, and it would be super helpful if anyone could tell me. I added the code at the top for some context; I only need help with the while loop. I am using the while
loop so if they do not choose a given position, they have to re-choose.
Here is my code:
pos = input("What Is Your Choice")
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and
"Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
python python-3.x logical-operators
marked as duplicate by Patrick Artner, Charles Duffy, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 19:09
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why does checking a variable against multiple values with `OR` only check the first value? [duplicate]
4 answers
How to test multiple variables against a value?
19 answers
I have tried everything and if you don't choose "ST" it constantly loops round the while loop. I am not sure what to do, and it would be super helpful if anyone could tell me. I added the code at the top for some context; I only need help with the while loop. I am using the while
loop so if they do not choose a given position, they have to re-choose.
Here is my code:
pos = input("What Is Your Choice")
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and
"Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
python python-3.x logical-operators
marked as duplicate by Patrick Artner, Charles Duffy, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 19:09
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
and
operator compares logical statements not the values themself. Trywhile pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
1
You can also usein
operator:while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44
add a comment |
This question already has an answer here:
Why does checking a variable against multiple values with `OR` only check the first value? [duplicate]
4 answers
How to test multiple variables against a value?
19 answers
I have tried everything and if you don't choose "ST" it constantly loops round the while loop. I am not sure what to do, and it would be super helpful if anyone could tell me. I added the code at the top for some context; I only need help with the while loop. I am using the while
loop so if they do not choose a given position, they have to re-choose.
Here is my code:
pos = input("What Is Your Choice")
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and
"Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
python python-3.x logical-operators
This question already has an answer here:
Why does checking a variable against multiple values with `OR` only check the first value? [duplicate]
4 answers
How to test multiple variables against a value?
19 answers
I have tried everything and if you don't choose "ST" it constantly loops round the while loop. I am not sure what to do, and it would be super helpful if anyone could tell me. I added the code at the top for some context; I only need help with the while loop. I am using the while
loop so if they do not choose a given position, they have to re-choose.
Here is my code:
pos = input("What Is Your Choice")
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and
"Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
This question already has an answer here:
Why does checking a variable against multiple values with `OR` only check the first value? [duplicate]
4 answers
How to test multiple variables against a value?
19 answers
python python-3.x logical-operators
python python-3.x logical-operators
edited Nov 13 '18 at 18:44
Joel
1,5726719
1,5726719
asked Nov 13 '18 at 17:40
Dan SDan S
82
82
marked as duplicate by Patrick Artner, Charles Duffy, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 19:09
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Patrick Artner, Charles Duffy, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 19:09
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
and
operator compares logical statements not the values themself. Trywhile pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
1
You can also usein
operator:while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44
add a comment |
and
operator compares logical statements not the values themself. Trywhile pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
1
You can also usein
operator:while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44
and
operator compares logical statements not the values themself. Try while pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
and
operator compares logical statements not the values themself. Try while pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
1
1
You can also use
in
operator: while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44
You can also use
in
operator: while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44
add a comment |
3 Answers
3
active
oldest
votes
!= only applies to the item listed directly before after it (without getting into operations with parens and whatnot). So in your example, your while loop is saying "while position is not equal to ST, and MID is true and DEF is true and DK is true and Mid is true and Def is true and Gk is true, do your statements.
To tell your program to do your while loop while the position is not equal to ST, nor MID, nor DEF, etc, you would have to explicitly spell that out-
while pos != "ST" and pos != "MID" and ... and post != "Gk"
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
add a comment |
This part is wrong:
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
pos != "ST"
is evaluated, and the rest of the strings are not compared to anything. In fact, that part is evaluated like:
while (pos != "ST") and ("MID") and ("DEF") and ("GK") and ("St") and ("Mid") and ("Def") and ("Gk"):
Non-empty strings are always True
, thus as long as pos != "ST"
is True
, it'll never get out of the loop. What you probably meant to do was:
while pos != "ST" and pos != "MID" and pos != "DEF" and pos != "GK" and pos != "St" and pos != "Mid" and pos != "Def" and pos != "Gk":
But, as one of the comments already pointed out, you could just use in
:
while pos not in {"ST", "MID", "DEF", "GK", "St", "Mid", "Def", "Gk"}:
Note that I used a set here since they provide much more efficient membership tests. Might not matter much in this small example, but nevertheless it's a better choice.
add a comment |
The while loop never finishes because your input is outside. So here is the working code:
import time
pos = ""
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
break
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
and you have to choose with "", because its a string
Yourwhile
statement equal towhile pos != "ST"
.
– vishes_shell
Nov 13 '18 at 17:50
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
!= only applies to the item listed directly before after it (without getting into operations with parens and whatnot). So in your example, your while loop is saying "while position is not equal to ST, and MID is true and DEF is true and DK is true and Mid is true and Def is true and Gk is true, do your statements.
To tell your program to do your while loop while the position is not equal to ST, nor MID, nor DEF, etc, you would have to explicitly spell that out-
while pos != "ST" and pos != "MID" and ... and post != "Gk"
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
add a comment |
!= only applies to the item listed directly before after it (without getting into operations with parens and whatnot). So in your example, your while loop is saying "while position is not equal to ST, and MID is true and DEF is true and DK is true and Mid is true and Def is true and Gk is true, do your statements.
To tell your program to do your while loop while the position is not equal to ST, nor MID, nor DEF, etc, you would have to explicitly spell that out-
while pos != "ST" and pos != "MID" and ... and post != "Gk"
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
add a comment |
!= only applies to the item listed directly before after it (without getting into operations with parens and whatnot). So in your example, your while loop is saying "while position is not equal to ST, and MID is true and DEF is true and DK is true and Mid is true and Def is true and Gk is true, do your statements.
To tell your program to do your while loop while the position is not equal to ST, nor MID, nor DEF, etc, you would have to explicitly spell that out-
while pos != "ST" and pos != "MID" and ... and post != "Gk"
!= only applies to the item listed directly before after it (without getting into operations with parens and whatnot). So in your example, your while loop is saying "while position is not equal to ST, and MID is true and DEF is true and DK is true and Mid is true and Def is true and Gk is true, do your statements.
To tell your program to do your while loop while the position is not equal to ST, nor MID, nor DEF, etc, you would have to explicitly spell that out-
while pos != "ST" and pos != "MID" and ... and post != "Gk"
answered Nov 13 '18 at 17:46
HollywoodHollywood
9211
9211
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
add a comment |
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
Thank you, hopefully i will remember this for next time
– Dan S
Nov 13 '18 at 21:09
add a comment |
This part is wrong:
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
pos != "ST"
is evaluated, and the rest of the strings are not compared to anything. In fact, that part is evaluated like:
while (pos != "ST") and ("MID") and ("DEF") and ("GK") and ("St") and ("Mid") and ("Def") and ("Gk"):
Non-empty strings are always True
, thus as long as pos != "ST"
is True
, it'll never get out of the loop. What you probably meant to do was:
while pos != "ST" and pos != "MID" and pos != "DEF" and pos != "GK" and pos != "St" and pos != "Mid" and pos != "Def" and pos != "Gk":
But, as one of the comments already pointed out, you could just use in
:
while pos not in {"ST", "MID", "DEF", "GK", "St", "Mid", "Def", "Gk"}:
Note that I used a set here since they provide much more efficient membership tests. Might not matter much in this small example, but nevertheless it's a better choice.
add a comment |
This part is wrong:
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
pos != "ST"
is evaluated, and the rest of the strings are not compared to anything. In fact, that part is evaluated like:
while (pos != "ST") and ("MID") and ("DEF") and ("GK") and ("St") and ("Mid") and ("Def") and ("Gk"):
Non-empty strings are always True
, thus as long as pos != "ST"
is True
, it'll never get out of the loop. What you probably meant to do was:
while pos != "ST" and pos != "MID" and pos != "DEF" and pos != "GK" and pos != "St" and pos != "Mid" and pos != "Def" and pos != "Gk":
But, as one of the comments already pointed out, you could just use in
:
while pos not in {"ST", "MID", "DEF", "GK", "St", "Mid", "Def", "Gk"}:
Note that I used a set here since they provide much more efficient membership tests. Might not matter much in this small example, but nevertheless it's a better choice.
add a comment |
This part is wrong:
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
pos != "ST"
is evaluated, and the rest of the strings are not compared to anything. In fact, that part is evaluated like:
while (pos != "ST") and ("MID") and ("DEF") and ("GK") and ("St") and ("Mid") and ("Def") and ("Gk"):
Non-empty strings are always True
, thus as long as pos != "ST"
is True
, it'll never get out of the loop. What you probably meant to do was:
while pos != "ST" and pos != "MID" and pos != "DEF" and pos != "GK" and pos != "St" and pos != "Mid" and pos != "Def" and pos != "Gk":
But, as one of the comments already pointed out, you could just use in
:
while pos not in {"ST", "MID", "DEF", "GK", "St", "Mid", "Def", "Gk"}:
Note that I used a set here since they provide much more efficient membership tests. Might not matter much in this small example, but nevertheless it's a better choice.
This part is wrong:
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
pos != "ST"
is evaluated, and the rest of the strings are not compared to anything. In fact, that part is evaluated like:
while (pos != "ST") and ("MID") and ("DEF") and ("GK") and ("St") and ("Mid") and ("Def") and ("Gk"):
Non-empty strings are always True
, thus as long as pos != "ST"
is True
, it'll never get out of the loop. What you probably meant to do was:
while pos != "ST" and pos != "MID" and pos != "DEF" and pos != "GK" and pos != "St" and pos != "Mid" and pos != "Def" and pos != "Gk":
But, as one of the comments already pointed out, you could just use in
:
while pos not in {"ST", "MID", "DEF", "GK", "St", "Mid", "Def", "Gk"}:
Note that I used a set here since they provide much more efficient membership tests. Might not matter much in this small example, but nevertheless it's a better choice.
edited Nov 13 '18 at 18:01
answered Nov 13 '18 at 17:44
AyxanAyxan
1,573115
1,573115
add a comment |
add a comment |
The while loop never finishes because your input is outside. So here is the working code:
import time
pos = ""
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
break
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
and you have to choose with "", because its a string
Yourwhile
statement equal towhile pos != "ST"
.
– vishes_shell
Nov 13 '18 at 17:50
add a comment |
The while loop never finishes because your input is outside. So here is the working code:
import time
pos = ""
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
break
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
and you have to choose with "", because its a string
Yourwhile
statement equal towhile pos != "ST"
.
– vishes_shell
Nov 13 '18 at 17:50
add a comment |
The while loop never finishes because your input is outside. So here is the working code:
import time
pos = ""
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
break
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
and you have to choose with "", because its a string
The while loop never finishes because your input is outside. So here is the working code:
import time
pos = ""
while pos != "ST" and "MID" and "DEF" and "GK" and "St" and "Mid" and "Def" and "Gk":
print("What Position Do You Want To Play?")
time.sleep(1)
print("The Options Are..")
time.sleep(1)
print("ST (Striker)")
time.sleep(1)
print("MID (Midfielder)")
time.sleep(1)
print("DEF (Defender)")
time.sleep(1)
print("GK (Goalkeeper)")
time.sleep(1)
pos = input("What Is Your Choice")
break
if pos == "ST":
shot = 8
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 2
print("Defending Is",defending)
if pos == "MID":
shot = 6
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 6
print("Pace Is",pace)
defending = 4
print("Defending Is",defending)
if pos == "DEF":
shot = 2
print("Shot Is",shot)
passing = 6
print("Passing Is",passing)
pace = 4
print("Pace Is",pace)
defending = 8
print("Defending Is",defending)
if pos == "GK":
dive = 7
dist = 8
catch = 7
print(pos)
and you have to choose with "", because its a string
answered Nov 13 '18 at 17:49
nerd100nerd100
875
875
Yourwhile
statement equal towhile pos != "ST"
.
– vishes_shell
Nov 13 '18 at 17:50
add a comment |
Yourwhile
statement equal towhile pos != "ST"
.
– vishes_shell
Nov 13 '18 at 17:50
Your
while
statement equal to while pos != "ST"
.– vishes_shell
Nov 13 '18 at 17:50
Your
while
statement equal to while pos != "ST"
.– vishes_shell
Nov 13 '18 at 17:50
add a comment |
and
operator compares logical statements not the values themself. Trywhile pos != "ST" and pos != "MID" ...:
– RafazZ
Nov 13 '18 at 17:43
while pos not in {"ST" , "MID", "DEF" ,"GK" ,"St","Mid","Def" , "Gk"}:
– Patrick Artner
Nov 13 '18 at 17:43
1
You can also use
in
operator:while pos not in ["ST", "MID", ...]
– RafazZ
Nov 13 '18 at 17:44