dimanche 3 novembre 2019

How can I check if an if statement inside a while loop has been satisfied?

I'm trying to make a program that, when given the terms of a sequence, prints an polynomial equation that can get those terms. I've added another feature to it, which mirrors the first part, in that it gives you the terms of the sequence after entering the equation.

So far, that has gone mostly well, but I've come across a problem when trying to implement another feature. If the user has already gotten the equation to a sequence, and they'd like to check perhaps some more terms of that sequence, I want them to be able to copy that equation if they'd like to, without doing it by hand, if that makes sense.

My attempt at this is as follows:

copyeq = 0

while 1:
    var = input("solve or check")

    if var == "solve":
        ...
        coefs = [a, b, c...]
        ...
        copyeq = 1

    elif var == "check":
        if copyeq == 1:
            if input("use coefficients as above?: ") == "yes":
                checklist = coefs

            else:
                return

        elif copyeq == 0:
            checklist = input("enter coefficients: ").split()
            ...

        # rest of the code uses checklist values
        ...

When I try to test this, it immediately jumps to the elif copyeq == 0: statement, meaning the value of 0 that I assigned to it in the if var == "solve": statement. Does anyone have any workarounds or solutions?

Aucun commentaire:

Enregistrer un commentaire