8au
8au

Reputation: 25

Python - Adding one to variable after each call

count = 0

def lol(count):
    x = count + 1
    print(x)

Currently i am calling this function within another file in my python program, and count is = 1 everytime it is ran, im unsure why, im trying to make it +1 after every time it is ran.

Any help would be greatly appriciated.

Upvotes: 0

Views: 470

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191691

You are never modifying count, and only printing the result of x = 0 + 1

This would do what you want, however, you should re-consider your need for global variables

count = 0

def lol():
    global count
    count += 1
    print(count)

Upvotes: 1

Related Questions