Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with simple LOGIN code
#1
[b][i][/b][/i]

Hello, the code is the following:
# -*- coding: latin-1 -*-

def login():
    user_incorreto = False
    while not user_incorreto:
        user_incorreto = ver_login()
        
    senha_incorreta = False
    while not senha_incorreta:
        senha_incorreta = ver_senha()
        
    sessoes()
    
    
def ver_login():
    print("\nLOGIN\n")  
    inf_user = input("\nType your user: ")
    if inf_user == "Pedro" or "pedro":
        return True
    else:
        print("\nInexistent or unallowed user.")
        return False
In def ver_login(),line 3:
if inf_user == "Pedro" or "pedro":
I wish to be possible to type in any of these options, "Pedro" and "pedro" to return True
I know that the sintax is wrong, but what could i do to achieve what i wish?
Reply
#2
That's not how the or operator works (see here for details). Handling case insensitive matches is usually done as if inf_user.lower() == 'pedro':. That is, lowercase the input before checking it for a match.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thanks a lot. How do I make that inf_user variable become global?
Reply
#4
(Jun-27-2019, 03:49 PM)pedrosa06 Wrote: Thanks a lot. How do I make that inf_user variable become global?

You don't. Global variables are a bad idea. They make your code confusing, and thus harder to debug and maintain. Parameters and return values make it clearer what is going on in your functions. See the function tutorial on how to do that.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 330 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 485 Nov-07-2023, 04:32 PM
Last Post: snippsat
  help me simple code result min and max number abrahimusmaximus 2 909 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,447 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,808 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Simple code question about lambda and tuples JasPyt 7 3,326 Oct-04-2021, 05:18 PM
Last Post: snippsat
  My simple code don't works !! Nabi666 1 1,607 Sep-06-2021, 12:10 PM
Last Post: jefsummers
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,834 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
  Plotting sum of data files using simple code Laplace12 3 3,055 Jun-16-2021, 02:06 PM
Last Post: BashBedlam
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,281 Feb-20-2021, 04:43 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020