[Solved] Why else statement is not executing?


This will do what you’re trying to do, however you might run into the problem of integer divison. Since you dont specify what the parameters are I will assume you have tought about this and do indeed try to divide two integers

def calculatetiles(plot_width, plot_length, tile_width, tile_length):
    if plot_width == str or plot_length == str or tile_width == str or tile_length == str:
        print("hello")
    elif plot_width == 0 or plot_length == 0 or tile_width == 0 or tile_length == 0:
        print("zero")
    else:
        aP = int(plot_width) * int(plot_length)
        aT = int(tile_width) * int(tile_length)
        calculatetiles = aT / aP
        calculatetiles = int(calculatetiles)
        print("The no of tiles is:", (calculatetiles))

EDIT: since the question itself has been edited to a different Question…
First of all please provide code as formatted text, NOT as image, second in your edit, you do if type(...):
this will allways return true because the statement you put inside there is a boolean so type returns boolean which is not an empty value and therefore interpreted as true by the if statement. For your purpose, just remove the line. if you want to do it correctly you’d have to use isinstance

3

solved Why else statement is not executing?