I ned some help regarding min and max

Screen Link:
https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/12/frequency-tables-for-numerical-columns

My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

data_sizes=[]
for i in apps_data[1:]:
    size=float(i[2])
    data_sizes.append(size) 
# min_size=min(data_sizes)
# max_size=max(data_sizes)

for i in data_sizes: 
    base_value= data_sizes[0]
    if i<base_value: 
        base_value=i
    min_size=base_value
for i in data_sizes: 
    base_value_1= data_sizes[0]
    if i>base_value_1: 
        base_value_1=i
    max_size=base_value_1
print(min_size)
print(max_size)

What I expected to happen:
min_size = 589824.0
max_size = 4025969664.0

What actually happened:

51174400.0
389879808.0

I am just curious how is my code wrong, i’ll been on this for the past 30 mins, and i can’t understand why. Could someone aid me in finding the right answer?

You need to loop app_data[1:], then append size, which is in the third column to data_sizes.

This code is unnecessary :point_up: .

Comment out this code. :point_up:

This is how I solved.

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

data_sizes = []

for app_data in apps_data[1:]:
    size = float(app_data[2])
    data_sizes.append(size)

min_size = min(data_sizes)
print(min_size)

max_size = max(data_sizes)
print(max_size)

    
1 Like

Thank you! What if i just wanted to use the method whereby i could - Assign first element as a minimum, and find the min and max from there on?

How can i do so? I wanted to know if i can find max and min using such a method.

Thank you!

If I understand you, you want to assign the minimum and maximum values to different variables right?

From what @info.victoromondi has explained, you can take it a step further by simply assigning a variable to the min and max values.

data_sizes = []

for app_data in apps_data[1:]:
    size = float(app_data[2])
    data_sizes.append(size)

min_size = min(data_sizes)
max_size = max(data_sizes)

base_value = min(data_sizes)
base_value_1 = max(data_sizes)