简体   繁体   中英

Passing On Values Between Functions

Hi i'm working on a program where a user selects an image, then it gets turned into an ASCII version of the picture, which displays in both the console and then gets saved to a notepad .txt file. The code below currently does this but I think the way I am using my returns in the functions is messing up the code. Instead of asking for the image and background colour once, it asks for it 3 times before actually drawing out the ASCII image. Then after it has drawn it, it again asks for a 4th time for the image and background colour, before finally asking for the name to give the .txt file then creating the text file.

How do I change this so that it only asks each question once without repeating itself(and what exactly is this happening?). Thanks

def inputs():
    image = input('What image file?')

    return (image)

def pictureConvert():

    a = inputs()
    # codefollows

Call the inputs function only once, and store that everywhere. This ensures that the user will be asked for input only once:

def inputs():
    image = input('What image file?')

    return (image)

def pictureConvert():

    a = inputs()
    # codefollows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM