Use inequality from user input string
Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:
import random
class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()
So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, =
exist.
I then have to save this as a string with the value of the equality sign.
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
Which I then use in another switch statement to manually check the difference.
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:
import operator
ops = "+": operator.add, "-": operator.sub
I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.
Thank you so much for the help! :)
python python-3.x
add a comment |
Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:
import random
class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()
So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, =
exist.
I then have to save this as a string with the value of the equality sign.
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
Which I then use in another switch statement to manually check the difference.
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:
import operator
ops = "+": operator.add, "-": operator.sub
I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.
Thank you so much for the help! :)
python python-3.x
1
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
1
Also, get out of the habit offor i in range(len(user_input)):
and learn to usefor char in user_input:
– Barmar
Nov 15 '18 at 20:22
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26
add a comment |
Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:
import random
class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()
So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, =
exist.
I then have to save this as a string with the value of the equality sign.
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
Which I then use in another switch statement to manually check the difference.
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:
import operator
ops = "+": operator.add, "-": operator.sub
I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.
Thank you so much for the help! :)
python python-3.x
Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:
import random
class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()
So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, =
exist.
I then have to save this as a string with the value of the equality sign.
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
Which I then use in another switch statement to manually check the difference.
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:
import operator
ops = "+": operator.add, "-": operator.sub
I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.
Thank you so much for the help! :)
python python-3.x
python python-3.x
edited Nov 15 '18 at 20:15
Mr Mc Epic
asked Nov 15 '18 at 20:07
Mr Mc EpicMr Mc Epic
185
185
1
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
1
Also, get out of the habit offor i in range(len(user_input)):
and learn to usefor char in user_input:
– Barmar
Nov 15 '18 at 20:22
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26
add a comment |
1
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
1
Also, get out of the habit offor i in range(len(user_input)):
and learn to usefor char in user_input:
– Barmar
Nov 15 '18 at 20:22
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26
1
1
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
1
1
Also, get out of the habit of
for i in range(len(user_input)):
and learn to use for char in user_input:
– Barmar
Nov 15 '18 at 20:22
Also, get out of the habit of
for i in range(len(user_input)):
and learn to use for char in user_input:
– Barmar
Nov 15 '18 at 20:22
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26
add a comment |
2 Answers
2
active
oldest
votes
You rarely need to use Boolean literals. Your switch first reduces to
if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0
which should make it obvious you can abstract out the comparison operators.
comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
add a comment |
Is there a reason for avoiding the builtin eval()
function? If not you could just do something like this in your checker class
import random
roll=random.randint(1,6)+random.randint(1,6)
print(roll)
test_in = input("please enter your statement")
try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')
Results
10
please enter your statement>? 4>
False
And for a true statement
3
please enter your statement4>
True
Edit: I should add that eval()
could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
"Is there a reason [to avoid]eval
" Almost always.
– chepner
Nov 15 '18 at 20:41
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not useeval()
on a public-facing program.
– krflol
Nov 15 '18 at 20:41
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327172%2fuse-inequality-from-user-input-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You rarely need to use Boolean literals. Your switch first reduces to
if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0
which should make it obvious you can abstract out the comparison operators.
comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
add a comment |
You rarely need to use Boolean literals. Your switch first reduces to
if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0
which should make it obvious you can abstract out the comparison operators.
comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
add a comment |
You rarely need to use Boolean literals. Your switch first reduces to
if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0
which should make it obvious you can abstract out the comparison operators.
comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)
You rarely need to use Boolean literals. Your switch first reduces to
if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0
which should make it obvious you can abstract out the comparison operators.
comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)
answered Nov 15 '18 at 20:20
chepnerchepner
259k34249343
259k34249343
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
add a comment |
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
Clever! I never thought of that. Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:30
add a comment |
Is there a reason for avoiding the builtin eval()
function? If not you could just do something like this in your checker class
import random
roll=random.randint(1,6)+random.randint(1,6)
print(roll)
test_in = input("please enter your statement")
try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')
Results
10
please enter your statement>? 4>
False
And for a true statement
3
please enter your statement4>
True
Edit: I should add that eval()
could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
"Is there a reason [to avoid]eval
" Almost always.
– chepner
Nov 15 '18 at 20:41
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not useeval()
on a public-facing program.
– krflol
Nov 15 '18 at 20:41
add a comment |
Is there a reason for avoiding the builtin eval()
function? If not you could just do something like this in your checker class
import random
roll=random.randint(1,6)+random.randint(1,6)
print(roll)
test_in = input("please enter your statement")
try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')
Results
10
please enter your statement>? 4>
False
And for a true statement
3
please enter your statement4>
True
Edit: I should add that eval()
could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
"Is there a reason [to avoid]eval
" Almost always.
– chepner
Nov 15 '18 at 20:41
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not useeval()
on a public-facing program.
– krflol
Nov 15 '18 at 20:41
add a comment |
Is there a reason for avoiding the builtin eval()
function? If not you could just do something like this in your checker class
import random
roll=random.randint(1,6)+random.randint(1,6)
print(roll)
test_in = input("please enter your statement")
try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')
Results
10
please enter your statement>? 4>
False
And for a true statement
3
please enter your statement4>
True
Edit: I should add that eval()
could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum
Is there a reason for avoiding the builtin eval()
function? If not you could just do something like this in your checker class
import random
roll=random.randint(1,6)+random.randint(1,6)
print(roll)
test_in = input("please enter your statement")
try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')
Results
10
please enter your statement>? 4>
False
And for a true statement
3
please enter your statement4>
True
Edit: I should add that eval()
could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum
edited Nov 15 '18 at 20:31
answered Nov 15 '18 at 20:25
krflolkrflol
55728
55728
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
"Is there a reason [to avoid]eval
" Almost always.
– chepner
Nov 15 '18 at 20:41
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not useeval()
on a public-facing program.
– krflol
Nov 15 '18 at 20:41
add a comment |
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
"Is there a reason [to avoid]eval
" Almost always.
– chepner
Nov 15 '18 at 20:41
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not useeval()
on a public-facing program.
– krflol
Nov 15 '18 at 20:41
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
It completely slipped my mind. That makes things so much easier! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:31
1
1
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
No problem. Please read my edit as I feel it is important to note.
– krflol
Nov 15 '18 at 20:32
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
Read. I assume eval() could open the program or computer up to vulnerabilities, yea?
– Mr Mc Epic
Nov 15 '18 at 20:39
1
1
"Is there a reason [to avoid]
eval
" Almost always.– chepner
Nov 15 '18 at 20:41
"Is there a reason [to avoid]
eval
" Almost always.– chepner
Nov 15 '18 at 20:41
1
1
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use
eval()
on a public-facing program.– krflol
Nov 15 '18 at 20:41
Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use
eval()
on a public-facing program.– krflol
Nov 15 '18 at 20:41
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327172%2fuse-inequality-from-user-input-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
if user_input[i] in "<>=": self.track_op = user_input[i]
– Barmar
Nov 15 '18 at 20:21
1
Also, get out of the habit of
for i in range(len(user_input)):
and learn to usefor char in user_input:
– Barmar
Nov 15 '18 at 20:22
Excellent advice @Barmar ! Thank you!
– Mr Mc Epic
Nov 15 '18 at 20:26