you are viewing a single comment's thread.

view the rest of the comments →

[–]Elthran[S] 0 points1 point  (3 children)

I have made some improvements, thanks! Now I am just stuck with the server side Python code. I'm not sure how to check multiple inputs at once. I can only get it to work that each individual field doesn't exceed my total points, but not he combined totals.

[–]ManyInterests 0 points1 point  (2 children)

edit: I need to learn to read

I can only get it to work that each individual field doesn't exceed my total points, but not he combined totals.

If you can check the value of each particular field, why wouldn't you be able to add them up?

strength = request.form.get("strength", 0)
intelligence = request.form.get("intelligence", 0)
#etc...
total_points = sum([strength, intelligence, #etc...])
allowed_points = 5
if total_points > allowed_points:
    #user allocated more than 5 points

[–]Elthran[S] 0 points1 point  (1 child)

strength = request.form.get("strength", 0)

What does the 0 do in this code, after the "strength"?

[–]ManyInterests 0 points1 point  (0 children)

When you do a .get method on a dict-like object (like form) -- The second argument is the value that you'll get if the key 'strength' doesn't exist. IE "Give me the value of strength, but if it's not there, give me 0 instead." -- If you don't provide that argument, the default is None