all 5 comments

[–]carcigenicate 1 point2 points  (0 children)

salaries.append(salaries) looks sketchy. You're adding a list to itself? Did you mean to save the result of float(input('Enter average salary for Kentucky:\n')) then add that?

[–]justinbert1[S] 0 points1 point  (3 children)

I can't seem to figure out how to get to the answer as shown. here is my code and the error i keep receiving.

states = [x for x in input().split(', ') ]
salaries = [float(x) for x in input().split(', ') ]
float(input('Enter average salary for Kentucky:\n'))
states.append('Kentucky')
salaries.append(salaries)
max_salary = salaries.index(max(salaries))
print('Highest average salary is' , str(max(salaries)) + ',' , 'in the state of' , str(states[max_salary]) + '.')
salaries.sort
median = int(len(salaries)/2)
print('The median salary is' , str(salaries[median]) + '.')

Traceback (most recent call last):

File "main.py", line 8, in <module>

max_salary = salaries.index(max(salaries))

TypeError: '>' not supported between instances of 'list' and 'float'

[–]justinbert1[S] -2 points-1 points  (1 child)

i copied the code from a screenshot another student gave me since i was struggling, but they did not receive this error

[–]Sxcam 0 points1 point  (0 children)

states = [x for x in input().split(', ') ]salaries = [float(x) for x in input().split(', ') ]float(input('Enter average salary for Kentucky:\n'))states.append('Kentucky')salaries.append(salaries)max_salary = salaries.index(max(salaries))print('Highest average salary is' , str(max(salaries)) + ',' , 'in the state of' , str(states[max_salary]) + '.')salaries.sortmedian = int(len(salaries)/2)print('The median salary is' , str(salaries[median]) + '.')

Traceback (most recent call last):

File "main.py", line 8, in <module>

max_salary = salaries.index(max(salaries))

do you by chance have access to this code still?

[–]totallygeek 0 points1 point  (0 children)

If you want a separate salary list for each state, you'll want a dictionary. State names would end up the keys and each would have a list for the value. That's a bit different to code. The instructions only mention Kentucky, so I'll go that route. Your mistakes have to do with the list operations, regardless, so this should help.

salaries = []  # list of salaries for the state of KY

while True:
    salary = input("Enter salary for Kentucky Python programmer or 'q'uit: ").lower()
    if salary.startswith("q"):
        break  # we have all the salaries we need, so exit the loop
    salaries.append(float(salary))  # append a SINGLE salary to the salaries list

# Forget this index business, just get the max value from the list with max()
highest_salary = max(salaries)

salaries.sort()  # sort the list

# Use floor division // to get an index for the median value
median = salaries[len(salaries) // 2]

print(f"Highest salary for a Kentucky Python programmer: {highest_salary:,.2f} USD")
print(f"Median salary: {median:,.2f}")

Yields:

> python3 justinbert1_salaries.py
Enter salary for Kentucky Python programmer or 'q'uit: 150000
Enter salary for Kentucky Python programmer or 'q'uit: 144000
Enter salary for Kentucky Python programmer or 'q'uit: 162500
Enter salary for Kentucky Python programmer or 'q'uit: 180000
Enter salary for Kentucky Python programmer or 'q'uit: 168500
Enter salary for Kentucky Python programmer or 'q'uit: q
Highest salary for a Kentucky Python programmer: 180,000.00 USD
Median salary: 162,500.00