Why are the dcount and tcount 0 and 0 in the output?

```a = [1, 2, 3, 4]
dcount = 0
tcount = 0
def doubles():
dcount = 0
for i in a:
for j in a:
if (i+j)%3 == 0:
dcount += 1
print(i,j)

def triplets():
tcount = 0
for i in a:
for j in a:
for k in a:

if (i+j+k)%3 == 0:
tcount += 1
print(i,j,k)

doubles()
triplets()
print(dcount)
print(tcount)```
```4 1 4
4 2 3
4 3 2
4 4 1
4 4 4
0
0
[Finished in 0.1s]```
Nov 6, 2020 in Python 190 views

## 1 answer to this question.

Because the dcount and tcount variables you use inside the functions aren't the same as the one on outside.

```There's two ways:
1) you can just return the values and store it inside dcount instead of declaring it.

def doubles():
//blah blah
return dcount

dcount = doubles()

2) use global variables (not recommended)

def triplets():
global tcount
// blah blah

If the same names confuses you, you can use another name:

def doubles():
doubles_count = 0
//blah blah
return doubles_count

dcount = doubles()```
• 65,850 points

## What is the output of and explanation?

It will print concatenated lists. Output would ...READ MORE

+1 vote

## What is the difference between classes and labels in machine learning?

Classes and Labels both are almost same things ...READ MORE

+1 vote

## What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

## What is the use of Tkinter,Flask and Django? What is the main use of them? Can any of them help me in freelancing?

Hey, all the tools that you have ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE