No error when comparing string to int?


#1

I am used to coding in C#, and am now trying to learn Python. If I tried (erroneously) to compare a string and an int in C# I would get an error message telling me that it is unable to compare the two types. I had the following code, and couldn't figure out why it was never going into the if statement (it was because I had forgotten to convert the "guess" input from a string to an int). Does Python not give warnings if an error of this type is made?

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
print "Guess the number from 1-10"
guesses_left = 3
# Start your game!
while guesses_left > 0:
    guess = raw_input("Your Guess:")
    if guess == random_number:
        print "You win!"
        break
    else:
        guesses_left -= 1
else:
    print "You lose"

#2
from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
# Start your game!

while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    guesses_left -= 1
    if guess == random_number:
        print "You win!"
        break
else:
    print "You lose."

Python is a different programming language to C# so it acts differently.


#3

Obviously. That doesn't answer the question. Maybe I should have been more explicit. The code I entered passed the exercise for which it was submitted, which in my opinion it shouldn't have, since it didn't work as intended, and did, in fact, have a bug. So I wondered if the fact that the line of code in question didn't give an error was a characteristic of Python in general or an error in the Codecademy interface