There are a few issues with the code:

  1. The syntax for the for loop is incorrect. It should be for i in range(4): instead of for i in 4:.
  2. The variables 'lowest', 'second', and 'x' need to be declared as global variables inside the count() function if you want to modify their values.
  3. The variables 'lowest', 'second', and 'x' need to be passed as parameters to the count() function if you want to update their values and access them outside the function.
  4. The calculation at the end should be (x - lowest - second) / 2 instead of (x - lowest - second) / 2.

Here's the corrected code:

lowest = 100000000000000000000000000000000
second = 100000000000000000000000000000000
x = 0

def count():
    global lowest, second, x
    a = float(input('Enter the number: '))
    if lowest > a:
        second = lowest
        lowest = a
    elif second > a:
        second = a
    x = x + a

for i in range(4):
    count()

print((x - lowest - second) / 2)

Note: The i variable is not being used in the code, so it can be removed if not needed.

Python Code Optimization for Finding Average Excluding Minimum and Maximum Values

原文地址: https://www.cveoy.top/t/topic/qtAu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录