Linked Questions

22 questions linked to/from Function not changing global variable
2 votes
2 answers
7k views

counter = 0 def addCounter(): counter = counter + 1 return counter UnboundLocalError: local variable 'counter' referenced before assignment. I'm trying to make a counter count every time ...
-2 votes
2 answers
2k views

I am making some kind of basic image filter app. I have a function to open and initialize image but variables stay just in function and I can't get them from another function, so I need to define ...
AWRDev.'s user avatar
  • 45
1 vote
1 answer
3k views

from random import randrange on = '' max_number = 0 random_number = 0 def start(): max_number = int(input('Enter max generated number: ')) random_number = randrange(max_number) print(...
Aidan's user avatar
  • 13
-1 votes
3 answers
2k views

I could not reference the original dataframe in the other function, i.e. print_df_in_a_function(). Could anyone please advise the mistake I made here? It displays None upon calling ...
Roy's user avatar
  • 537
0 votes
1 answer
705 views

d = {'a':'1', 'b':'2', 'c':'3'} def change_d(d): dd = {} d = dd print(d) change_d(d) print(d) I suppose both print() should print out an empty dict, but they are different: {} {'a': '1',...
marlon's user avatar
  • 7,929
0 votes
3 answers
88 views

From the following code, I wish for the output of names to contain an array of names taken from a column in a csv file. When the function is run, the array remains empty. Why? def cp_identifier(): ...
user avatar
-1 votes
1 answer
96 views

hi = 1 result = 0 def hello(x): x = x + 10 result = x helli(hi) print(result) Why does my code Output "0" and not 11?
Jibril's user avatar
  • 23
1 vote
1 answer
106 views

I've recently being self teaching python and I'm making my first attempt at a game. The idea is the user must guess what the answer is (integer) My code is not yet complete but the first half won't ...
-4 votes
2 answers
86 views

How does the code below give the output as None? def funct(x): x=7 x=11 x=test(x) print(x) Here is another code snippet:- def func(): print (x) x = 90 x = 1 func() The output for this ...
YoDO's user avatar
  • 105
-1 votes
2 answers
64 views

I have been trying to use the tkinter module for creating a user interface for a project I've been working on. For some reason, the command doesn't do what i'm asking from it and the price stays as 0 ...
-1 votes
1 answer
51 views

I'm making a program that uses a variable called "lev" that must be used in all my functions, but it doesn't need to be an argument of the function. I mean, the function makes some things and then ...
0 votes
0 answers
27 views

am trying to make a simple calculator using python but for some reason he keep giving me the same result everytime here is the code def inputing(num2, op) : op = input("operator") ...
0 votes
0 answers
28 views

I am making a basic tic tac toe game as this is the first time I am coding but I am running into an issue where I define a variable outside the function and try to change it inside but I am unable to ...
0 votes
0 answers
26 views

I am changing the value of a global variable inside a function, but as soon as I get out of that function it is changing back to its previous value. I have created a game in which a rabbit(represented ...
62 votes
12 answers
60k views

I was reading a question about the Python global statement ( "Python scope" ) and I was remembering about how often I used this statement when I was a Python beginner (I used global a lot) and how, ...

15 30 50 per page
1
2