Here is my code. I need to add a percent symbol at the end of the print
string. I can't get this figured 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'))
If you see utf-8 , then your system supports unicode characters. To print any character in the Python interpreter, use a \u to denote a unicode character and then follow with the character code. For instance, the code for β is 03B2, so to print β the command is print('\u03B2') .
How do you show special characters in Python? Use repr() to print special characters Call repr(string) to return string with special characters escaped.
The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand.
Decorators. The main use case of the symbol @ in Python are decorators. In Python, a decorator extends the functionality of an existing function or class.
The probably best way would be to just use the percent format type:
format(average, '.1%')
# or using string formatting:
'{:.1%}'.format(average)
This already multiplies the 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%
print('The average is: ' + format(average, ',.3f') + '%')
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With