-1

In class im meant to write a program that arranges coordinates for you. I wrote this:

x = input("")
y = input("")
z = input("")

print("(",x,",",y,",",z,")\n)

and the output is: (␣0␣,␣-7831␣,␣2323␣)⤶ how do I stop the extra spaces from appearing so I get this?: (0,␣-7831,␣2323)⤶

khelwood
  • 55,782
  • 14
  • 81
  • 108
mfodor
  • 3
  • 1

1 Answers1

2

In modern Python, the nicest way is to use an f-string:

print(f"({x},{y},{z})")

Note how the string is prefixed with f. Everything between the curly braces {} then gets interpreted as a Python expression which is subsequently converted to a string and inserted at that point.

Note that print already follows up with a newline, so unless you want an extra one (that is, a blank line), you don't need to add \n yourself.

Thomas
  • 174,939
  • 50
  • 355
  • 478