0

How to make a variable which is available in an if statement be available in an else statement in python?

if(1 == 2): ... a = 1 ... b = 1 ... c = a - b ... else: ... print(c + 1) ... #whenever it executes the else statement I get c is not defined

12th Oct 2017, 6:15 PM
suryapoojary
suryapoojary - avatar
2 Antworten
0
It runs fine when I run it.
12th Oct 2017, 6:23 PM
Joshua
Joshua - avatar
0
you have to define c before the if/else statement c= 0 if ... : #something with c else: # something with c
12th Oct 2017, 9:39 PM
Chrizzhigh
Chrizzhigh - avatar