vendredi 31 janvier 2020

How to exclude empty line and number less than zero in python when using while loop

I am writing a simple program that executes if-else condition. my program receives from the user as input the weight of an object in kg. , a floating number, and print out the price for shipment. by using while I want to Expand the program to function and calculate the total price for multiple packages. The program should load packet weight until the user enters a blank line or a number that is 0 or less. The program will then print the total price for all the packages

the code looks like this:

def packagePrice():
    weightInKg = float(input(" Enter the value of weight:"))
    totalPrise = 0

while weightInKg != "" or weight <= 0:
    if weightInKg <= 10:
        price = 149
    elif 10 < weightInKg <= 100:
        price = 500

    elif weightInKg  > 100:
        print ("Not allowed")

    totalPrise+= price
    print(totalPrise)

    weightInKg = float(input(" Enter the value of weight:"))

packagePrice()

but it does not properly run anyone help

Aucun commentaire:

Enregistrer un commentaire