Thursday, March 12, 2020

How to display scores using python in pygame related


print("%s scored %d and completed %.2f of the quest"%("anil",15,50))

output:
anil scored 15 and completed 50.00 of the quest


example:
print("%20s scored %20d and completed"%("anil",15))

output:
                anil scored                   15 and completed

example3:
print("%-20s%20d"%("anil",15))
output:
anil                                  15

example 4:
print("%-10s%10s%10s\n%-10s%10d%10d\n%-10s%10d%10d"%('Team','Won','Lost','Leafs',1,1,'sabres',0,2))

output:
Team             Won      Lost
Leafs              1         1
sabres             0         2


example 5:
print("%-10s%10s%10s\n%-10s%10d%10d\n%-10s%10d%10d"%('Team','Won','Lost','india',1,1,'srilanka',0,2))

output:
Team             Won      Lost
india                1         1
srilanka           0         2


example 6:
player='abhi'
print(player)

output:
abhi

example7:
formatter="%-10s%10s%10s\n"
header =formatter%("Team","Won","Lost")
india= formatter%("india",1,1)
srikanth= formatter%("srikanth",0,2)

print("%s%s%s"%(header,india,srikanth))
Team             Won      Lost
india              1         1
srikanth           0         2

example 8:
formatter="%-10s%10s%10s\n"
header =formatter%("Team","Won","Lost")
india= formatter%("india",1,1)
srikanth= formatter%("srikanth",0,2)

#print("%s%s%s"%(header,india,srikanth))
table="%s%s%s"%(header,india,srikanth)
print(table)

output:
Team             Won      Lost
india              1         1
srikanth           0         2




No comments:

Post a Comment

python class topic video