On 13/08/15 02:01, IDN3 wrote:
To whom it may concern, I am having a problem solving the below question. I have used every resource that I could find to help me, but I'm seeing nothing. Can someone out there please help me understand the below question and learn how to accomplish this task in Python? I would really appreciate any help that someone could afford.
OK, We won;t give you the solution but we can certainly help you understand the question and point you in the right direction.
*Problem 1:* Write a program that will calculate the problem and stop after the condition has been met. a=number of loops (start with zero) b=a+1 c=a+b
Notice that a is the thing that counts the number of loops. So you need to increment a inside your loop. b and c are based on a.
Condition: If c is less than 5, then the loop will continue; else, it will end.
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.
My attempt below. I used a while loop even though the question is saying IF/THEN/ELSE.
You obviously did not send the whole question. I don't see any mention of if/then/else?
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 wrong.
The two questions are both OK, but i think you missed the bit that said a was the variable that counted the number of times round the loop. This is a little bit unusual since normally your while loop test uses the counting variable (ie. a) but in this case it uses c which is based on a. But it does demonstrate that the while condition can be more complex that the basic form.
a = 0 b = a + 1 c = a + b while (c < 5): print(c) c = c + 1
You need to make a the counter and not c. You need to recalculate c after changing a. You need to print the number of loops (a) not c. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor