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

문제

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?

도움이 되었습니까?

해결책

Try using string format method:

write("{0}%".format(grades[1]))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top