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.

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}"  

Leave a Reply