0

Say an input was defined as this within one defined script:

def Login():
    log = input ('\nLogin (Case sensitive): ')

There is more code after this within Login(), nevertheless the above is where log is initially defined. Is there any way I can use this defined input within another defined script? For example, what I want to do is allow log to be used within another defined script:

def LoggedInStudent():
    print ('Hello, student. Would you like to: \n1: Attempt this weeks spelling test \n2:  Log out')
    studentchoiceinput = input ('')
    if studentchoiceinput == ('1'):
        if log in y3list:
            Y3SpellingTest()
        if log in y4list:
            Y4SpellingTest()
        if log in y5list:
            Y5Spellingtest()
        if log in y6list:
            Y6SpellingTest()

Is there any way to have 'log' defined within the latter script without having the user have to input their 'username' again or without moving the latter script into where 'log' is initially defined? I want to do this because I do not want to have the user of my program have to 'log out' of it whenever they need to be returned to the 'menu'.

Thanks in advance for the help.

1 Answer 1

1

Pass log to LoggedInStudent as an argument:

def Login():
    log = input ('\nLogin (Case sensitive): ')
    LoggedInStudent(log)


def LoggedInStudent(log):
    ...

It does not matter that LoggedInStudent is defined after Login. It only matters that LoggedInStudent is defined by the time Login is called.

Sign up to request clarification or add additional context in comments.

2 Comments

Can I pass more than one argument at a time to the same script? How would I do this?
Yes, you just name the arguments, separated by commas. (Warning: I'm talking about passing arguments to functions, not scripts.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.