[Tutor] Python help
wclem2008 at gmail.com
Mon Aug 24 07:10:20 CEST 2015
<This is in response to a much earlier posting for which I don't have the email>
[Tutor] Python help
IDN3 iradn3777 at gmail.com
Thu Aug 13 03:01:12 CEST 2015
Previous message (by thread): [Tutor] revisiting a puzzle about -3**2 vs (-3)**2
Next message (by thread): [Tutor] Python help
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
*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)
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.
My attempt below. I used a while loop even though the question is saying
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. Thank you for your help.
a = 0
b = a + 1
c = a + b
while (c < 5):
c = c + 1
Yes, I agree the wording of the question is confusing. But I think the
following solution makes sense for it. My solution is close to yours,
with a few differences: .
1) the variable a will count the number of times the loop goes around.
2) variable a has to be incremented inside the while loop
3) both a and c have to be initialized to zero before the loop starts.
4) after the loop ends, print a string with the variable to tell how
many times the loop went
a = 0 #increments with each loop
c = 0
b = a+1
c = a+b
a += 1
print("Number of loops until c >= 5:", a)
I think that is all that is being asked here. HTH!
More information about the Tutor