Oct-14-2019, 12:46 AM
Got an assignment in my programming class that I'm having a hard time figuring out.
My teacher has created a .pyc file and it provides to me a variable. My task is to take the variable and determine if it is an integer or not.
I'm not allowed to use any "string" methods or try..except statements.
His one hint was that you will want a while loop that goes through each character of the "variable" and checks to see if it is legal. After that, it gets a little more complicated.
Also he says that it can be written in about 15 lines of code.
His pyc file goes through about 75 tests and I'm still failing on over half of them because all I can think of is nesting several If statements to check ordValues, but of course my code gets longer than 15 lines.
Some examples I'm having to evaluate are:
1.0 = True
-1 = True
1 = True (space in first position)
1.000013 = False
2341 134115 = False
+123 = True
Is anyone willing to give me some ideas on how I would do this as not being able to use string methods is really confusing me.
Thanks
My teacher has created a .pyc file and it provides to me a variable. My task is to take the variable and determine if it is an integer or not.
I'm not allowed to use any "string" methods or try..except statements.
His one hint was that you will want a while loop that goes through each character of the "variable" and checks to see if it is legal. After that, it gets a little more complicated.
Also he says that it can be written in about 15 lines of code.
His pyc file goes through about 75 tests and I'm still failing on over half of them because all I can think of is nesting several If statements to check ordValues, but of course my code gets longer than 15 lines.
Some examples I'm having to evaluate are:
1.0 = True
-1 = True
1 = True (space in first position)
1.000013 = False
2341 134115 = False
+123 = True
Is anyone willing to give me some ideas on how I would do this as not being able to use string methods is really confusing me.
Thanks