Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help3403


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
 
Options:
RSS cloud
Jump to:

Why does changing one input break this code segment?

1 of 419 articles shown, currently no other people reading this forum.
photo
From: Haolin W.
Date: Fri 22nd May 2020, 10:06am
Actions: 
        Login-to-reply

 

Pretty sure the quiz= part needs .first() on the end or .all() depending on what you want to do. 
Whatever comes from the form will always be a string, so casting it into an integer is correct. 
It's throwing index out of bounds likely because you have literally nothing for quiz[i].answer in 
your loop, as the quiz= line will always return the SQL statement rather than an actual object 
list.

In the future, put print statements before things you're trying to debug, to make sure that 
you're getting exactly what you're expecting at each stage of the POST. I haven't actually run 
your code, but an index out of bounds error means it's something to do with your loop, and that's 
the most likely place for it to happen.

ANONYMOUS wrote:

> I'm trying to use a link to the quiz page and automatically display the chosen quiz by 
> using types and then "int(request.args.get('type'))"  however when I then go to use this 
> type to filter the quizes by quizCode, this breaks my code and gives me an index out of 
> bounds error. I tried converting the type to an int but it seems to somehow turn itself 
> back into a NoneType every-time the code tries to run and I'm not sure why. The code works 
> fine if I manually type quizCode='1' for example but when using selectedQuiz it breaks.

Related articles

Why does changing one input break this code segment? (all 5) RSS
├─ original   Fri 22nd May 2020, 3:34am, ANONYMOUS
├─ THIS   Fri 22nd May 2020, 10:06am, Haolin W.
├─ reply 2   Fri 22nd May 2020, 10:15am, ANONYMOUS  O.P.
├─ reply 3   Fri 22nd May 2020, 10:19am, Haolin W.
└─ reply 4   Fri 22nd May 2020, 11:22am, Takoyaki N.
This Page


Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020