Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: Get userinput and print if not empty

I want my code to ask the user for his first and last name and print it out. If the input should be empty, a different message should be printed.

    def printName(first="", last=""):
        print( "{} {}".format(first, last) )
first = input(("Please type your first name: "))
last = input(("Please type your last name: "))
printName( )

This is my current code but it doesnt print out anything I input.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have forgotten to pass the parameters to the function:

def printName(first="", last=""):
    print( "{} {}".format(first, last) )
first = input(("Please type your first name: "))
last = input(("Please type your last name: "))
printName(first, last)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading