Thursday, March 12, 2020

if and else in python language


x=50
y=50

if x>=0 and x<= 100 and y>=25 and y<=250 :
    print("player is inside the area.sound the alarm")
else:
    print("player is outside  the area. Do  nothing")

output:
player is inside the area.sound the alarm


example2:
israining=True
issunny=True
if israining and issunny:
    print("sun showers")

output:
sun showers

if in python

first=input("First string:")
second=input("second string")
if first>second:
    tup=(first,second)
else:
        tup=(first,second)
print("%s is greater than %s"%tup)

output:
First string:anil

second stringabhi
anil is greater than abhi

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




python class topic video