0% found this document useful (0 votes)
15 views1 page

Def Calculate Stats (Data) .Py

The document contains a Python script with a function 'calculate_stats' that computes the average of positive and negative numbers in a list while also performing unnecessary operations and containing unused variables. The function is inefficient due to its looping structure and redundant conditions. The 'main' function initializes a data list and calls 'calculate_stats' to print the result.

Uploaded by

HolloGram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Def Calculate Stats (Data) .Py

The document contains a Python script with a function 'calculate_stats' that computes the average of positive and negative numbers in a list while also performing unnecessary operations and containing unused variables. The function is inefficient due to its looping structure and redundant conditions. The 'main' function initializes a data list and calls 'calculate_stats' to print the result.

Uploaded by

HolloGram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def calculate_stats(data):

# Long function with no docstring


result = 0
unused_var = 42 # Unused variable
count = 0
temp_list = []
# Inefficient loop
for i in range(len(data)):
temp_list.append(data[i] * 2)
# More lines to make function long
for item in data:
if item > 0:
result += item
count += 1
elif item < 0:
result -= item
count += 1
else:
result += 0
count += 1
# Redundant condition
if count > 0:
avg = result / count
else:
avg = 0
# Simulate more complexity
for i in range(10):
if i % 2 == 0:
result += i
else:
result -= i
return avg

def main():
data = [1, -2, 3, 0, 5]
another_unused_var = "test" # Unused variable
print(calculate_stats(data))

if __name__ == "__main__":
main()

You might also like