-1

I'm doing one of my first assignments and I can't find out how to put parentheses around a variable when I go to print it.

I've tried (xs) {xs} [xs} But none get parentheses around it

(print)("Hello user! Welcome to the program!")
 name = input("What is your name?")
(print)("Hello", name)
x = input("What is your favorite number?")
y = int(x) // 2
xs = str(x)
ys = str(y)
z = ("Did you know that half of your favorite number" + ' ' + xs + ' ' + 'is' + ' ' + ys + '?')

print(z)

For the 2nd to last line of code I want it to say Did you know that half of your number (5) is 2?

5 is just an example number but I want it in parentheses!

Community
  • 1
  • 1
Jonathan
  • 39
  • 1
  • 7
  • Put second last line as `z = "Did you know that half of your favorite number" + ' (' + xs + ') ' + 'is' + ' ' + ys + '?'` – Amit Darji Jan 25 '19 at 22:15
  • Do yourself a favor and follow a good tutorial to learn the language.Your code has far too much parenthesis in it. Read about string formating here: https://pyformat.info/ and google python f-string if you are indeed on python 3.6+ - if you simply googled "how to print a number in a string python" you would have gotten thousands of solution to this problem. Tutorial: https://docs.python.org/3/tutorial/ .. printing starts where strings are explained: https://docs.python.org/3/tutorial/introduction.html#strings and https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting – Patrick Artner Jan 25 '19 at 22:23

3 Answers3

0

Do it like so:

z = ("Did you know that half of your favorite number" + ' (' + xs + ') ' + 'is' + ' ' + ys + '?')
Anwarvic
  • 12,156
  • 4
  • 49
  • 69
-1

you just need to add the pharentesis in the right place, something like this:

z = ("Did you know that half of your favorite number" + ' (' + xs + ') ' + 'is' + ' ' + ys + '?')

mchaparro
  • 24
  • 2
-1

I am not exactly sure if that is what you need but you just have to concat "(" and ")" around your variable.

>>> y = "number"
>>> print ( "(" + y + ")" )
(number)
xan-a-alex
  • 36
  • 5