Comparator, if else, for loop

 

If else syntax


# if statement for area

if area > 15:

    print("big place!")


# if-else construct for room

if room == "kit" :

    print("looking around in the kitchen.")

else :

    print("looking around elsewhere.")


# if-elif-else construct for area

if area > 15 :

    print("big place!")

elif area >10:

    print("medium size, nice!")

else :

    print("pretty small.")



# Definition of dictionary

europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin',

          'norway':'oslo', 'italy':'rome', 'poland':'warsaw', 'austria':'vienna' }

          

# Iterate over europe

for key, value in europe.items():

    print("the capital of "+key+" is "+value)





Comments

Popular posts from this blog

Useful links (updated: 2024-10-23)

Odd ratio - อัตราส่วนของความต่าง

Note: A Road to Real World Impact (new MU-President and Team) - update 12 Sep 2024