A_Worthy
A_Worthy

Reputation: 65

How to end code if "If" Condition is not met

In my code I have two weights that need to equal 1.0. If not I need a print statement saying the conditions are not met and it wont continue to run the rest of the code.

My issue is that if conditions are met, it runs the code forever and it is supposed to continue with the rest of the code. And if they are not met I just want to make sure that it will not run the rest of my code and stop altogether. Two issues that need to be addressed I guess.

No numpy allowed pls.

weight_1 = 0.5
weight_2 = 0.5

while True:
    if ((weight_1 + weight_2) == 1.0):
        print ("Weights are appropriate")
    else:
        print("Error! Weights limits not appropriate!")
        break;

Upvotes: 2

Views: 26314

Answers (1)

A_Worthy
A_Worthy

Reputation: 65

import sys 
 weight_1 = 0.5
 weight_2 = 0.2

if ((weight_1 + weight_2) == 1.0):
        print ("Weights are appropriate")

else:
        print("Error! Weights limits not appropriate!")
        sys.exit()

Upvotes: 3

Related Questions