samedi 7 novembre 2020

How can I make if statement to affect the rest of the setting? [closed]

I'm trying to create a conditional statement:

a = 1
b = a + 1
c = b + 1
d = c + 1

test = input("'b = a + 2' instead? y/n\n")
if test == 'y':
    b += 1
    print(a, b, c, d)

I want 'print(a, b, c, d)' to bring out the result 1, 3, 4, 5; however, it does not affect c or d in this. I can get what I want using the code below, but it is redundant.

if test == 'y':
    b += 1
    c = b + 1
    d = c + 1
    print(a, b, c, d)

I appreciate your help!

Aucun commentaire:

Enregistrer un commentaire