Good afternoon everyone.
First of all I am a total beginer in coding and Python itself. To be honest I am not even sure is that a proper place to ask such a 'newbie' question.
But to the point.
During the online course I was asked to write a simple program to guess numbers. I did that and the code works quite ok: https://pastebin.com/XwZ2qcab
Although I wanted to improve the code to allow user to type a non int variable and not crash. I have used ' if type(userNumber) != int:' in the upgraded version of the code: https://pastebin.com/JQarjjSw but it does not work.
The issue I have is (I think) here:
for i in range(1, 7):
userNumber = input('Take a guess')
if type(userNumber) != int: #This line is my main issue, if I delete it code works like a charm.
break
elif int(userNumber) > int(number):
print('No! Your number is too high. Try again')
elif int(userNumber) < int(number):
print('No! Your number is too low. Try again')
else:
break
I have no idea why the line if type(userNumber) != int: break
is not executed and pyCharm goes directly to: elif int(userNumber) > int(number):
and crashes.
Funny thing is that on pythontutor.com code works as intended. Checks for userNumber and if it is not an int breakes the IF loop.
Hope that is somehow clear.