How to add% symbol to my Python script

Here is my code. I need to add a percent symbol at the end of the print line. I can’t figure it out.

 total = 0 counter = 0 while True: score = int(input('Enter test score: ')) if score == 0: break total += score counter += 1 average = total / counter print('The average is:', format(average, ',.3f')) 
+5
source share
2 answers
 print('The average is: ' + format(average, ',.3f') + '%') 

?

+4
source

Probably the best way would be to simply use the percentage format format:

 format(average, '.1%') # or using string formatting: '{:.1%}'.format(average) 

This already multiplies average by 100 and will also show a percent sign at the end.

 >>> average = .123 >>> print('The average is: {:.1%}'.format(average)) The average is: 12.3% 
+6
source

Source: https://habr.com/ru/post/1235441/


All Articles