-3

I am making a pretty advanced Python program, but no matter how I do it, I cannot get the IF statements to work.

I ran the script all by itself and it still doesn't work.

TESTLETTER = input ("Input text here")

if TESTLETTER == 1:

    print ("Logging in...")

What is supposed to happen is (in the full program) when you press 1 it will go through a huge process, but here I can't even get it to print text.

martineau
  • 119,623
  • 25
  • 170
  • 301

3 Answers3

0

input() function returns a string, so it will never be equal to integer 1. Try

TESTLETTER = input("Input text here")
if TESTLETTER == "1":
    print ("Logging in...")
karlosss
  • 2,816
  • 7
  • 26
  • 42
-1

I'm guessing you want check if the user has given any input or not.

The correct way to do this on Python would be just to evaluate the string itself. If it's empty or None, it'll evaluate to False; otherwise, to True:

TESTLETTER = input("Input text here")
if TESTLETTER:
    print("Logging in...")
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
-2

I suppose you want just to type 1, without needing to press Enter.

To do that, use the following code if you are on Linux :

import getch

TESTLETTER = getch.getch()
if TESTLETTER == "1":
    print ("Logging in...")

If you are on windows, use the following code instead :

import msvcrt 

TESTLETTER = msvcrt.getch()
if TESTLETTER == "1":
    print ("Logging in...")
z4cco
  • 107
  • 4