Skip to content
Sign upLog in
← Back to Community
Error in code: Str instead of int
Profile icon

This file cannot be displayed:

I tried to execute this code, and I got an error for line 6, str instead of int. I don't know where to make the correction.

Profile icon
Profile icon
Profile icon

You can use the int function (actually a class) to change the type. The input returns a string, not integer. Therefore, you must change the string to an integer. For example: int(boundLow) For more information on the difference between strings and integers, look at Stack Overflow
Please mark this as the correct answer if this was helpful thanks! Or if you cant please upvote

Profile icon

When you take an input, it returns a string. When you add two strings together, they join so if boundUp was 5 then boundUp + 1 is '51'. The range() function only takes a number, so it doesn't know what to do with a string like that. To fix this you could change this

boundLow = input('blah blah blah')

to this

boundLow = (input('blah blah blah'))

Note: This only works on whole numbers, not decimals. If you want to take a decimal input use float instead of int but this will not work with range.

I am a helper. Please mark my comment as the answer and/or upvote if it helped you.