Home > Mobile >  TypeError: '<' not supported between instances of 'float' and 'tuple
TypeError: '<' not supported between instances of 'float' and 'tuple

Time:01-30

This is my code :

if __name__ == '__main__':
    sco=int(10011)
    na=""
    for i in range(int(input())):
        name = input()
        score = float(input())
        sco=(sco,score)
        na=na,name
    s = min(sco)

But when I am running this code then this comes

TypeError: '<' not supported between instances of 'float' and 'tuple'

I have tried multiple ways like converting variable sco into a list etc... Please help me out.

CodePudding user response:

this is because the sco variable is assigned to a tuple, you can't determine the minimum of a float value and a tuple:

if you print the value of sco, the output would get a nested tuple:

((10011, somefloat), otherfloat) #if we input 2 as the range

CodePudding user response:

What you have currently just generates a nested tuple, whereas, since you want to collect all the scores, you should simply add them to a list:

if __name__ == '__main__':
    scores = []      # empty list
    sco = int(10011)
    na=""
    for i in range(int(input())):
        name = input()
        score = float(input())
        scores.append(score)
        sco=(sco,score)
        na=na,name
    s = min(scores)
    print(sco)   # I'm sure you don't want this
    print(s) # I'm sure you want to get the minimum score entered
  •  Tags:  
  • Related