samedi 3 février 2018

Python if-then-else loop, am I doing something wrong in my code?

The assignment is: Write a program that will calculate the problem and stop after the condition has been met. This is an IF/THEN/ELSE problem. a=1 b=a+1 c=a+b Condition: If c is less than 5, then the loop will continue; else, it will end. a will increase by one after every completed loop

My program works, but this doesn't seem like a loop, just individual lines of code, right?

a=1
b=a+1
c=a+b
if c == 5:
    print("first ending")
elif c < 5: c=a+b+1
print ("c does not = 5")
if c == 5:
    print ("second ending")
elif c < 5: c=a+b+2
print ("c still does not = 5")
if c == 5:
    print ("third ending")
print("c now = 5")
print(c)

The excess print commands were for me to see if it was adding or not. Not required. Thanks in advance for any/all help!

Aucun commentaire:

Enregistrer un commentaire