Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the code is not running : #2

Open
vishalrao009 opened this issue Feb 4, 2020 · 7 comments
Open

Why the code is not running : #2

vishalrao009 opened this issue Feb 4, 2020 · 7 comments

Comments

@vishalrao009
Copy link

No description provided.

@vishalrao009
Copy link
Author

vishalrao009 commented Feb 4, 2020

The below code is for python3.

temperature=20
thermo=15
def increase_temp():
if temperature>=15:
thermo+=5
print(thermo)
return thermo
print(increase_temp())

if I pass the argument in function it works.

@babulasi
Copy link

babulasi commented Feb 4, 2020

local variable is referenced before assignment, maybe something like this is a solution?

temperature=20
thermo=15
def increase_temp():
if temperature >= 15:
global thermo
thermo = temperature + 5
return thermo
print(thermo)
print(increase_temp())

@vishalrao009
Copy link
Author

vishalrao009 commented Feb 4, 2020 via email

@babulasi
Copy link

babulasi commented Feb 4, 2020

temperature=15
thermo=15
def increase_temp():
if temperature >= 15:
thermo = temperature + 5
return thermo
print(thermo)
else:
message = "Everything is OK"
return message
print(increase_temp())

ok, I didn't drink coffee...now, I think this is it :)

@vishalrao009
Copy link
Author

vishalrao009 commented Feb 4, 2020 via email

@babulasi
Copy link

babulasi commented Feb 4, 2020 via email

@ghost
Copy link

ghost commented Oct 5, 2020

Once you change the value of a global variable inside a function, it's no longer a global variable but a local variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants