'int' and 'str' mistake

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

Upvotes: 0

Views: 55

Answers (2)

Ilya Nekhay
Ilya Nekhay

Reputation: 111

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

highest = account

Looks like you wanted that line to say

highest = amount

Upvotes: 1

Alec Cureau
Alec Cureau

Reputation: 268

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.

Upvotes: 1

Related Questions