Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How to call a variable in an input prompt?

Tags:

python-3.x

I want to ask the following questions:

What is the team name?

How many points did (team_name) score?

I've tried the this and have gotten back an error:

team_name = input("What is the team name? ")

points = input("How many points did", team_name, "score? ")

please help!

like image 419
Kevin Dangamanova Avatar asked Jan 16 '26 22:01

Kevin Dangamanova


2 Answers

Here's a python3.6 way of doing this:

points = input(f"How many points did {team_name} score?")
like image 153
Antony Hatchkins Avatar answered Jan 19 '26 10:01

Antony Hatchkins


What error are you getting?

I'm fairly confident your problem is that you are passing three parameters to input on the second line, instead of concatenating the strings which I think you're trying to do here.

Try:

points = input("How many points did " + str(team_name) + " score?")
like image 43
igoldthwaite Avatar answered Jan 19 '26 11:01

igoldthwaite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!