Python 2.7.10: Adding 1 to global variables between functions -
so code this:
global i_like_dem_apples i_like_dem_apples = 0 global i_dont_like_dem_apples i_dont_like_dem_apples = 0 def how_do_you_like_them_applez(steve_jobs): if steve_jobs == "empire" or steve_jobs == "gala": return i_like_dem_apples == i_like_dem_apples + 1 if steve_jobs == "rome" or steve_jobs == "york": return i_dont_like_dem_apples == i_dont_like_dem_apples + 1 else: return i_dont_like_dem_apples == i_dont_like_dem_apples + 1 def good_day (the_good_stuff): apple in the_good_stuff: how_do_you_like_them_applez(apple) if i_dont_like_dem_apples > i_like_dem_apples or i_dont_like_dem_apples == i_like_dem_apples: return "false" if i_like_dem_apples > i_dont_like_dem_apples: return "true" good_day(["gala", "york", "rome"]) print i_like_dem_apples print i_dont_like_dem_apples
when run this, no error messages, instead this:
0 0 [finished in 0.0s]
what hoping is:
1 2
i've tried changing code around adding 1 bit,
def how_do_you_like_them_applez(steve_jobs): if steve_jobs == "empire" or steve_jobs == "gala": return i_like_dem_apples =+ 1 if steve_jobs == "rome" or steve_jobs == "york": return i_dont_like_dem_apples =+ 1 else: return i_dont_like_dem_apples =+ 1
and this
def how_do_you_like_them_applez(steve_jobs): if steve_jobs == "empire" or steve_jobs == "gala": return i_like_dem_apples = i_like_dem_apples + 1 if steve_jobs == "rome" or steve_jobs == "york": return i_dont_like_dem_apples = i_dont_like_dem_apples + 1 else: return i_dont_like_dem_apples = i_dont_like_dem_apples + 1
but invalid syntax error message. i'm pretty sure things wrong global variables, wouldn't because that's how thought global variables worked.
- get rid of
global
things, use them incorrectly. - edit add
global i_like_dem_apples,i_dont_like_dem_apples
involved functions. - replace
return i_like_dem_apples == i_like_dem_apples + 1
, similar statementsi_like_dem_apples += 1
. - fix variable names,
i_like_dem_apples
horrible name. - do not return
"false"
,"true"
, returnfalse
,true
.
Comments
Post a Comment