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

How to put information from input into a variable?

Lets say I have two input statements and want to input the information into another variable, and I want to put a "-" in between the two inputs.

first_name = input("FIRST NAME: ")
last_name = input("LAST NAME: ")

URL = "http://www.name.com/firstandlast/"

I want to put the information from first_name and last_name into the URL variable

I tried this but it didn’t work and I’m not sure what I am doing wrong.

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

first_name = input("FIRST NAME: ")
last_name = input("LAST NAME: ")

URL = "http://www.name.com/firstandlast/" + first_name + "-" + last_name

>Solution :

I tried your code and it works fine:

first_name = input("FIRST NAME: ")
last_name = input("LAST NAME: ")

URL = "http://www.name.com/firstandlast/" + first_name + "-" + last_name

Output:

FIRST NAME:  jhon
LAST NAME:  foo
URL: 'http://www.name.com/firstandlast/jhon-foo'

If you want to do different you can do using f-strings:

URL = f"http://www.name.com/firstandlast/{first_name}-{last_name}"  
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