-2
def guessinggame ():
    d = input("Enter a random word: ")
    e = input("How many letters does the word has?: ")
    f = len(d)
    if( "e" == len(d)):
       print("You are right!")
guessinggame()

if I try to run this code, it will work, but it will skip the "if" function... Help please. thanks!

  • you need `if (int(e) == len(d)):` – Jens Munk Apr 03 '16 at 08:47
  • 3
    Suppose `len(d)` was 5, what is the result of `"e" == 5`? – Jeff Mercado Apr 03 '16 at 08:47
  • 2
    Read your code *carefully*. What do you think `"e"` is in that test? How does it differ from where you reference `d`? Also, if this is Python 3, the variable `e` will contain a string, not an integer, see [How can I read inputs as integers in Python?](http://stackoverflow.com/q/20449427) – Martijn Pieters Apr 03 '16 at 08:47
  • 2
    it doesn't skip the if statement (which is not a function). You've just written your condition very very incorrectly, so it's always evaluating to false. – ApproachingDarknessFish Apr 03 '16 at 08:48
  • Welcome to SO! Remember that your questions should be phrased in a format that makes them useful to other people too, should they encounter a similar problem. Reading your question as-is it's not formatted that way. Try to include the error that the interpreter prints, and explain what you have tried, and what prior research you have done to try to understand the error. – Ulf Aslak Apr 03 '16 at 08:49
  • Typo close reason. Resolved in a manner unlikely to benefit future readers. – Drew Apr 05 '16 at 17:14

2 Answers2

1

You are working only with strings and never converting anything to integers, and (more importantly) you are confusing a string with a reference name. For integers, use int() to cast:

e = int(input("How many letters does the word has?: "))

For the strings vs reference names, 'e' is just the letter "e." Omit the quotes and you will then be using a reference e.

if e == len(d):
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
0

e needs to be an int.

def guessinggame(): 
    d = input("Enter a random word: ")
    e = input("How many letters does the word has?: ") 
    f = len(d) 
    if int(e) == len(d): 
        print("You are right!")
guessinggame()
Oisin
  • 770
  • 8
  • 22