Home > Software design >  'int' and 'str' mistake
'int' and 'str' mistake

Time:12-04

enter image description here

bank_account = None
highest = 0

for account, amount in accounts.items():
    
    if amount > highest:           -------------< 
        bank_account = account
        highest = account 
        
print(bank_acount, highest)
TypeError: '>' not supported between instances of 'int' and 'str'

how can I alter my code to make it works

CodePudding user response:

Either 'account' or 'highest' is a string, you need to determine which one and adjust your code.

If the string is the string form of a number, i.e. "1", you can use int("1") to get the int form.

CodePudding user response:

I believe you have a typo in the line that says:

highest = account

Looks like you wanted that line to say

highest = amount

  • Related