Create tower with python program

In this simple example we are going to write a short python program which will create a tower by comparing the exchange rate between us dollar and another foreign currency. If that foreign currency value is larger than us dollar then the tower will go upside down or else it will stay upright. That exchange rate will first get converted to integer instead of float which means that the decimal point value will not be included when we build the tower. Below is the full source code, the code is not that difficult to understand.

def tower_builder(n_floors, upsidedown):

    floor_count = 0
    floor= 0
    tower = []
    floorlist = []

    while(floor_count < int(n_floors)):
        if(floor == 0):
            floor += 1
            floorlist.append(floor)
        else:
            floor += 2
            floorlist.append(floor)
        floor_count += 1

    draw_control = 0
    floor_count = 0
    drawfloor = ''

    while(floor_count < len(floorlist)):

        while(draw_control < floorlist[floor_count]):
            drawfloor += '$'
            draw_control += 1

        drawfloor =  drawfloor.center(floor, " ")  # pad the floor with space
        tower.append(drawfloor)
        drawfloor = ''
        floor_count += 1
        draw_control = 0

    if(upsidedown == True):
        tower.sort(key = None, reverse = True) # turn tower upside down if usd is smaller

    return tower

# start to build dollar tower
upsidedow = False
floor_count = 0

usd = 1 # every one usd equal x foreign currency 
other = 18.51

usd_other = 0

if(other > usd): # so usd is bigger than other
    usd_other = other/usd
else:
    usd_other = usd/other
    upsidedow = True

towerlist = tower_builder(usd_other,  upsidedow) # get the tower list

while(floor_count < len(towerlist)):
    floorstring = towerlist[floor_count]
    print(floorstring)  # print the floor level
    floor_count += 1

In the example above, when we use the exchange rate of 1 usd to 18.51 peso we get the below graph which clearly shows US Dollar is indeed very strong at the moment as compared to the world currencies, basically if you see the exchange rate between the us dollar and the other currency you will find out that there is no one nation in the world which will make the us dollar tower turns upside down, the closest we can get is 1 euro is equal to 1.23 usd which will only create a dot in the screen after we have omitted the decimal point.

The tower of us dollar vs peso
The tower of us dollar vs peso

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of