0

I'm new to python, I've only been using it for about 5 months but I'm ambitious and am currently working on a project to help me in the long run in terms of GCSEs.

print PercentComplete, "% complete"

I want to remove the space so instead of it printing "6.66 % complete", it would print "6.66% complete"

Many thanks Miles

Mooles
  • 23
  • 5
  • 2
    Possible duplicate of [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) – Aran-Fey Jan 31 '18 at 20:15

3 Answers3

2

Use string formatting - it's much more flexible and robust. In this case:

print "{}% complete".format(PercentComplete)
Nathan Vērzemnieks
  • 5,495
  • 1
  • 11
  • 23
0

do print str(PercentComplete)+"% complete"

In your answer, you were printing two different things. Here you combine it into one item and print it

usernamenotfound
  • 1,540
  • 2
  • 11
  • 18
  • Thanks. It works like a charm! I'll mark this as the best answer because it was the one that made the most sense to me! :D – Mooles Jan 31 '18 at 20:21
0

A common way to do it is using string format.

print('%.2f %% complete' % PercentComplete)

This way you always will have the number correctly formatted.

The output will be

6.66% complete
juanmhidalgo
  • 1,478
  • 16
  • 18