Python Forum

Full Version: How can I get values inside of function?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wrote these codes but there is a problem.

userid=(" ")
userpw=(" ")

def register():
a=input("Username: ")
b=input("Password: ")

How can I get these values from the function instead of userid and pw.
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

userid, userpw = register()
userid=""
userpw=""

def register():
    userid=input("Username: ")
    userpw=input("Password: ")
    print("%s%s%s%s" %("Username = ", userid, "\nPassword = ", userpw))

register()
or use getpass

import getpass 
  
try: 
    user = getpass.getuser()
    p = getpass.getpass() 
except Exception as error: 
    print('ERROR', error) 
else: 
    print('User:', user, 'Password entered:', p) 
(Dec-31-2018, 02:21 PM)metulburr Wrote: [ -> ]
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

userid, userpw = register()

When I start the program, always does same thing. I can't move to the next step.
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

c = register()
userid = c[0]
userpw = c[1]
print ("userid:", userid, "userpw:", userpw)

You should not use input for a password (it is visible then)

better use getpass