'If' Statement for Checking the Value of a String/Integer?

Asked by Dylan McCarthy

Hello All,
I'm looking to use an 'if' statement to check the value of a string/integer. I understand the basics of string => integer conversion, and integer => string conversion, and this is the code I have so far:
-----
variable = input("TYPE HERE")
variable = (int(variable))
if variable(1):
      popup("Hello, Mate!")
popup(variable)
-----
The previous script is supposed to convert the input (string) to an integer, and compare the integer to see if it equals '1'. If so, a dialog box will appear, displaying 'Hello, Mate!' I'm not sure if I need to convert the input (which is in string form), to an integer in order to compare it or not, but when I run this script, I receive the following:
-----
TypeError: 'str' object is not callable
-----
Any suggestions?

Any and all help is greatly appreciated.
-dwmcc

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

interesting "Meta-Code" ;-)

this should work:

while True:
    variable = input("TYPE HERE, but pls. a number")
    try: # we catch conversion errors
        variable = int(variable)
        break # now variable is an integer
    except:
        continue # pass would be sufficient, but this is clearer
# since the string must be convertible, we loop until it contains a number
if variable == 1: popup("Hello, Mate!")
popup(str(variable)) # numbers are not converted automatically

have fun with lucky numbers ;-)

Can you help with this problem?

Provide an answer of your own, or ask Dylan McCarthy for more information if necessary.

To post a message you must log in.