Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to submit an answer in LeetCode

Hi im just starting to practice programming and i did one of the easy problems of leetcode, which is the one called "Average Salary Excluding the Minimum and Maximum Salary", i code it on my local visual studio and the programm works, but when i try to put it in leetcode when i try to submit it, it says

"TypeError: int() argument must be a string or a number, not 'list'
    loop = int(input("How many salaries are you going to input : "))
Line 18 in <module> (Solution.py)"

I understand that the program doesnt take user input to try if the program works, but what things do i have to change in my code for it to work?

salary = [] 
i = 0
total = 0
average = 0

def max_min_salaries():
    for i in range(loop):
        min_salary = min(salary)
        max_salary = max(salary)
        average = total - min_salary - max_salary
        average = average / ( loop - 2 )    
    return average   

loop = int(input("How many salaries are you going to input : "))

for i in range(loop):
    salary.append(float(input("Input Salary : ")))
    total = total + salary[i]

average = max_min_salaries()

print("The average salary is : " , average)

What things i have to change in order to be able to submit my programm

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The error message suggests that the program is trying to convert a list to an integer using the int() function, which is not possible. This is likely caused by the line where you are getting the input for loop.

To make the program work with LeetCode, you need to modify it so that it takes input from LeetCode’s test cases instead of user input. You can do this by removing the input() function call and replacing it with a predefined value for loop.

Here’s the modified code that should work with LeetCode:

salary = [] 
i = 0
total = 0
average = 0

def max_min_salaries():
    for i in range(loop):
        min_salary = min(salary)
        max_salary = max(salary)
        average = total - min_salary - max_salary
        average = average / ( loop - 2 )    
    return average   

# define loop with a predefined value
loop = 5

# replace user input with predefined values
salary = [2500, 3500, 4500, 5500, 6500]
total = sum(salary)

average = max_min_salaries()

print("The average salary is : " , average)

In this modified code, I have replaced the input() function call with a predefined value for loop. I have also replaced the user input for salary with a predefined list of salaries. Finally, I have calculated the sum of the salaries using the sum() function instead of a loop.

You can adjust the values of loop and salary to match the test case provided by LeetCode.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading