Beginner question: is "if x == y and z == i:" possible?

Hello,

may I ask what is incorrect in this code?

Also, can I use any of these below?
if X == Y or Z:
if X == Y and Z == I:
if X == Y or Z == Y:

Thank you in advance

choice = input("Do you want to exit this programme (y/Y): ")
if choice == "y" or "Y":
    print("Thank you for using this software. ")
elif choice == "n":
    username = print("Please give a name: ")
    password = print ("Please give a password: ")
        if username == John and password == password:
            print("The user is accepted.")     
        else:
            print("The name you input was ", len(password), " ", "character long", "", ",", " ", "but that or the  username was not correct.")
else:
    print("Something went wrong")

choice == "y" or "Y" means (choice == "y") or "Y", which will always be true.

username = print("Please give a name: ") and password = print ("Please give a password: ") will print a message and then assign None to the variable.

username == John and password == password will fail because there’s no variable called John, and you’re also comparing password to itself.

1 Like

Thank you.

May I fix this by

username = input ("Please insert username: ")
passcode = imput ("Please insert password: ")
?

or “username” and “password” become variables x and y:

x = input ("Please input username: ")
y = input ("Please input password: ")
       if x == John and y == password:
              print("The user is accepted.")

The correct username to pass is “John” and the correct password is actually “password” in this exercise.

Am I correct in that:
-a text variable can contain numbers,
-a text variable cannot contain text
-a, b, c, d, … x, y, z can contain text and numbers?

Thank you again

This is fine:

That is much better than using x and y as the variables.

But this is wrong:

if username == John

That tries to find the variable John which does not exist. You need to use a string "John". Notice the quotation marks.

(Also, you can’t just randomly indent lines of code. Python requires correct indentation. If you don’t know the indentation rules, please ask.)

There is no such thing as “text variables” in Python, and there is nothing special about variables x, y, z etc except that they are one letter and don’t have a meaningful name.

Every variable in Python can hold anything you like: text, numbers, lists, sets, dicts, or any other sort of object you want. You can even lie if you want.

name = 99
age = "Steven"

The interpreter won’t stop you.

1 Like

Yes, you should be using ‘input’ to accept input. Check the spelling, though! :slight_smile:

The second point is that John is a variable name, not a string. You forget the quotes: "John". And the same with ‘password’: password is a variable name, "password" is a string.