Python Forum
While loop and If Statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop and If Statement
#1
Hello friends,
This is our assignment:
Write a function called stop_at_z that iterates through a list of strings. Using a while loop, append each string to a new list until the string that appears is ā€œzā€. The function should return the new list.

I have came up with this:

def stop_at_z(testlist):
    index = 0
    result = []
    while index < len(testlist):
        if "z" in testlist[index]:
            index += 1
            continue
        result.append(testlist[index])
        index += 1
    return result
But I receive error!
https://pasteboard.co/HYpOEuJ.png

Can somebody help?

Thank you
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,594 Feb-12-2018, 08:57 AM
Last Post: Jrvelandia
  if statement in for loop Danielk121 3 3,740 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