[Tutor] Python help
cs at zip.com.au
Thu Aug 13 11:44:32 CEST 2015
On 13Aug2015 10:34, ALAN GAULD <alan.gauld at btinternet.com> wrote:
>On 13/08/15 02:01, IDN3 wrote:
>>Condition: If c is less than 5, then the loop will continue; else, it will
>>3. *Problem 2:*Print a string variable that states the number of loops
>>required to meet the condition for Problem 1.
>This is a simple bit of math.
>You don't need to run the loop to figure out the answer,
>just write an equation.
Maybe so, but for an arbitrarily weird condition running the loop may be the
way to go. Therefore I would imagine he is being asked to print how many times
that loop ran. So he should just print that value after the loop finishes (i.e
outside the loop).
>>My attempt below. I used a while loop even though the question is saying
>You obviously did not send the whole question.
>I don't see any mention of if/then/else?
Actually, the question's "Condition:" section is written in exactly those
>>To my knowledge loops in Python have to be while/for. Also,
>>it seems like the question is missing some direction, but I could be
The way I would read your "Cndition:" requirement is that it is describing what
kind of decision must be made every time the loop commences. It is not telling
you to use Pythons "if" statement. So just putting the correct condition at the
top of the "while" loop is what you want.
Cameron Simpson <cs at zip.com.au>
If you lie to the compiler, it will get its revenge. - Henry Spencer
More information about the Tutor