Python Turtle: How to use the write function to join an integer and a string with the integer coming from a list

StackOverflow https://stackoverflow.com/questions/22577550

Question

So, I'm trying to get the grade to be able to print a percentage sign in the exact same line as to when I write the grade.

The aim is to have it print: 45% for the first example.

from turtle import *
  grades = [45, 42, 13, 98, 82]
  write(grades[0],'%')

When I run this code both the grade and percentage sign gets printed on top of each other. How do I get the grade and the percentage sign, side by side without the two overlapping?

Était-ce utile?

La solution

Try using string format method:

write("{0}%".format(grades[1]))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top