-
Notifications
You must be signed in to change notification settings - Fork 214
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
Comments
The below code is for python3. temperature=20 if I pass the argument in function it works. |
local variable is referenced before assignment, maybe something like this is a solution? temperature=20 |
It will work but, 'thermo' seems to be a global variable as it was defined
before function.
…On Tue, Feb 4, 2020 at 3:05 PM gr8cod3 ***@***.***> wrote:
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())
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2?email_source=notifications&email_token=AKQLUR5VU4KRPFAXRBGYQRTRBEZFZA5CNFSM4KPP6PG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKW6C2Q#issuecomment-581820778>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKQLURZSTSLULQ3SIID4K63RBEZFZANCNFSM4KPP6PGQ>
.
|
temperature=15 ok, I didn't drink coffee...now, I think this is it :) |
Yeah, that works too.
Is it that the global variable (Thermo), if once updated inside the
function, becomes a local variable?
…On Tue, Feb 4, 2020 at 3:51 PM gr8cod3 ***@***.***> wrote:
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 :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2?email_source=notifications&email_token=AKQLUR652EBHMYKWFBBCSQTRBE6UJA5CNFSM4KPP6PG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKXCWUY#issuecomment-581839699>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKQLUR7C55A5CVICW3LRHODRBE6UJANCNFSM4KPP6PGQ>
.
|
global variables can be used inside or outside of functions and stays
global
…On Tue, 4 Feb 2020, 15:58 vishalrao009, ***@***.***> wrote:
Yeah, that works too.
Is it that the global variable (Thermo), if once updated inside the
function, becomes a local variable?
On Tue, Feb 4, 2020 at 3:51 PM gr8cod3 ***@***.***> wrote:
> 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 :)
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <
#2?email_source=notifications&email_token=AKQLUR652EBHMYKWFBBCSQTRBE6UJA5CNFSM4KPP6PG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKXCWUY#issuecomment-581839699
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AKQLUR7C55A5CVICW3LRHODRBE6UJANCNFSM4KPP6PGQ
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2?email_source=notifications&email_token=AONAFJR5ISSUUAYH67BXQ73RBF673A5CNFSM4KPP6PG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKX5OOI#issuecomment-581949241>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AONAFJX6DU74KSMHCLO3E6LRBF673ANCNFSM4KPP6PGQ>
.
|
Once you change the value of a global variable inside a function, it's no longer a global variable but a local variable. |
No description provided.
The text was updated successfully, but these errors were encountered: