Python Forum
While loop and If Statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop and If Statement
#4
Based on the expected values from the screenshots, the loop is expected to stop once "z" has been found. The first test expects "['c',...'r']" and 'r' is the last value prior to "z". Likewise, the second test expects "['zoo...azz']" and the only string in the list ending in "azz" is "pizzazz" which is immediately before "z".

Skipping "z" and appending the remaining the values would cause those first two tests to fail. Plus, the conditional is true if a "z" is in the string, but that is not true based on test 1. You want to test equality to "z" instead.

Also, there's a problem with your index too. If "z" is found, your function increments index by 2 - once under the conditional and once again after the conditional.
Reply


Messages In This Thread
While loop and If Statement - by farzankh - Jan-27-2019, 05:43 PM
RE: While loop and If Statement - by j.crater - Jan-27-2019, 08:18 PM
RE: While loop and If Statement - by farzankh - Jan-27-2019, 09:36 PM
RE: While loop and If Statement - by stullis - Jan-27-2019, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help converting int to str value in loop statement Jrvelandia 2 2,573 Feb-12-2018, 08:57 AM
Last Post: Jrvelandia
  if statement in for loop Danielk121 3 3,715 Nov-13-2017, 01:52 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020