Help: Python simple user control

Bambarbiakirgudu

Regular Member
Joined
Nov 9, 2016
Messages
358
Reaction score
63
Guys, i m shy to say that, but i couldn' get this simple python code working although everything looks fine.

code
# -*- coding: utf-8 -*-
print("E-mail service:")
user_name = input("User name:")
pw = input("Your password:")

if user name == "asdf" and pw == "123456":
print("Welcome!")

else:
print("Wrong user name or password!")

code




Where m i doing wrong? it seems if block doesn't work, but directly goas twoards "else" case after i fill user name and password regardless to what i input.

How will i correct this?
 
Probably not the best forum for programming stuff if I'm honest, so results may vary.

instead of using "and" try using a nested if statement, so...

Code:
if user_name == "asdf":
   if pw == "123456":
       print("Welcome")
   else:
       print("Wrong user name or password!")
else:
   print("Wrong user name or password!")

Either that, or check the spacing, as python needs certain spacing to work, ie 4 spaces when something is nested etc
 
Probably not the best forum for programming stuff if I'm honest, so results may vary.

instead of using "and" try using a nested if statement, so...

Code:
if user_name == "asdf":
   if pw == "123456":
       print("Welcome")
   else:i m highly surprised why it diedn't work with and oper
       print("Wrong user name or password!")
else:
   print("Wrong user name or password!")

Either that, or check the spacing, as python needs certain spacing to work, ie 4 spaces when something is nested etc
Probably not the best forum for programming stuff if I'm honest, so results may vary.

instead of using "and" try using a nested if statement, so...

Code:
if user_name == "asdf":
   if pw == "123456":
       print("Welcome")
   else:
       print("Wrong user name or password!")
else:
   print("Wrong user name or password!")

Either that, or check the spacing, as python needs certain spacing to work, ie 4 spaces when something is nested etc



i m highly surprised why and operator didn't work, cuz i saw a simillar example on a python book.
 
Guys, i m shy to say that, but i couldn' get this simple python code working although everything looks fine.

code
# -*- coding: utf-8 -*-
print("E-mail service:")
user_name = input("User name:")
pw = input("Your password:")

if user name == "asdf" and pw == "123456":
print("Welcome!")

else:
print("Wrong user name or password!")

code




Where m i doing wrong? it seems if block doesn't work, but directly goas twoards "else" case after i fill user name and password regardless to what i input.

How will i correct this?


what error do you get? There was a small mistake on line 4, you've typed "user name" instead of "user_name" but everything else works fine for me: http://prntscr.com/l92ama

Code:
# -*- coding: utf-8 -*-
print("E-mail service:")
user_name = input("User name:")
pw = input("Your password:")

if user_name == "asdf" and pw == "123456":
    print("Welcome!")

else:
    print("Wrong user name or password!")
 
what error do you get? There was a small mistake on line 4, you've typed "user name" instead of "user_name" but everything else works fine for me: http://prntscr.com/l92ama

Code:
# -*- coding: utf-8 -*-
print("E-mail service:")
user_name = input("User name:")
pw = input("Your password:")

if user_name == "asdf" and pw == "123456":
    print("Welcome!")

else:
    print("Wrong user name or password!")


it works now, i m thankfull :)
 
Back
Top