0

Using the code below:

print("Welcome to band name generator!!")
city,pet = input("What is the name of the city you grew up in?\t") + input ("\nWhat is the name of your first pet?\t")
print("\n\t Your band name can be " + city + " "+ pet + "!!")

I can input single variable (eg - a/b/c or 1/2/3) and the program works fine but it we input string values or words(eg- Canada,New_york), I get the following error - too many values to unpack (expected 2)

How can I resolve this while keeping input in one line?

1
  • 1
    You are assigning Canada,New_york to a single value city. Hence the error Commented May 29, 2021 at 6:40

2 Answers 2

1

You need to replace the + with a , since the + is going to concatenate your inputs into one string.

city, pet = input("What is the name of the city you grew up in?\t"), input ("\nWhat is the name of your first pet?\t")

Whenever you get the too many values to unpack Error, make sure that the number of variables on the left side matches the number of values on the right side.

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

Comments

1

Use the split function,it helps in getting a multiple inputs from user. It breaks the given input by the specified separator. If a separator is not provided then any white space is a separator.

print("Welcome to band name generator!!")
city,pet = input("Enter the city and pet name  ").split()
print("\n\t Your band name can be " + city + " "+ pet + "!!")

Comments

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.