The Student Room Group

Why has my code got an error? Please help

See pics0F052526-59CA-4072-B7AA-20146986F2EE.jpg.jpeg2B69B272-AC25-4885-9663-D34686067AF9.jpg.jpeg
I only get the error when it goes into a minus... help
Firstly, I can see a different, unrelated error here on line 56 unless you've got a variable somewhere called "min", but it doesn't seem that way from the colour of the text:
if totalpoints < 0:
totalpoints = min

min is a built-in function which takes the lowest of two numbers, so I'm guessing you were trying to do totalpoints = min(totalpoints, 0) -- although wait and think about that logic...

if totalpoints is less than 0 then it will be a negative number. The minimum between a negative number and zero is the negative number (so totalpoints would stay as the negative number).

It seems to me that it'd make more sense to use max() instead if you want to stop it turning into a negative number (and you won't need the if check either because it won't matter whether totalpoints is less than 0 or not, since max() will always prevent it). i.e.
totalpoints = max(totalpoints, 0)



Where else are you changing the variable called 'user2points' aside from line 61? line 61 itself is fine, but it looks like you have an error somewhere else which looks the same as the error on 56. e.g. you have done something like this elsewhere in your program:
# will cause an error since 'max' without rounded brackets is a built-in-function
user2points = max


If you find the line which looks a bit like this and change it to actually to use (rounded brackets) that function, then that'll set the variable user2points to an integer value properly. e.g.

# This will get the bigger number between 0 and user2points
user2points = max(0, user2points)


The error you're seeing about 'builtin_function_or_method' is because the variable has been set to some built-in function like min or max just by using its name without rounded brackets, rather than a number, which is probably what you meant to do.

(Remember that the names min and max on their own without curvy brackets will just store those functions in the variable, it won't call them -- that's why you need min() or max() with parameters instead)
(edited 4 years ago)
Original post by winterscoming
Firstly, I can see a different, unrelated error here on line 56 unless you've got a variable somewhere called "min", but it doesn't seem that way from the colour of the text:

if totalpoints < 0:
totalpoints = min

min is a built-in function which takes the lowest of two numbers, so I'm guessing you were trying to do totalpoints = min(totalpoints, 0) -- although stop and look at that logic for a second too.

-- if totalpoints is less than 0 then it will be a negative number. So if you choose the minimum between a negative number and zero, then totalpoints would be the negative number). It seems to me that it'd make more sense to use max instead if you want to stop it turning into a negative number (and you won't need the if check either. i.e.

totalpoints = max(totalpoints, 0)




Where else are you changing the variable called 'user2points' aside from line 61? line 61 itself is fine, but it looks like you have an error somewhere else which looks the same as the error on 56. e.g. you have done something like this elsewhere in your program:

user2points = max


If you find that line and change it to use max (maybe user2points = max(0, user2points ) ?? then that'll set the variable user2points to an integer. The error you're seeing about 'builtin_function_or_method' is because the variable has been set to some built-in function like min or max. rather than a number.

(Remember that the names min and max on their own without curvy brackets will just store those functions in the variable, it won't call them -- that's why you need min() or max() instead)

How do you type the pinkish code window?
Original post by Mehru1214
How do you type the pinkish code window?


Use tags like this (image below):


Here's some code


code tags.PNG

Quick Reply

Latest

Trending

Trending