Python Forum
if conditions in the for indentation doesnt work ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if conditions in the for indentation doesnt work ?
#7
block1 = """This is a bit
of text but
should pass completely
"""

block2 = """This bit of
text will be found
to be a real test of your patience
"""

for text_input in (block1, block2):
    line_count = 0
    for line_count, line in enumerate(text_input.splitlines(), start=1):
        if "test" in line:
            print(f"There were {line_count-1} lines before finding 'test'")
            break
    else:
        print(f"test not found")
Output:
test not found There were 2 lines before finding 'test'
Reply


Messages In This Thread
RE: if conditions in the for indentation doesnt work ? - by bowlofred - Jun-15-2021, 11:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 290 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Pydoc documentation doesnt work Cosmosso 5 4,361 Nov-25-2023, 11:17 PM
Last Post: vidito
  pip install requests doesnt work misodca 8 6,068 Jul-07-2023, 08:04 AM
Last Post: zyple
  Ldap3 Python print(conn.entries) doesnt work ilknurg 15 5,713 Dec-28-2022, 11:22 AM
Last Post: shad
  pip install pystyle doesnt work person_probably 2 2,096 Sep-23-2022, 02:59 PM
Last Post: person_probably
  Why doesnt chunk generation work? LotosProgramer 1 1,941 Apr-02-2022, 08:25 AM
Last Post: deanhystad
  I have two Same Code but One of them Doesnt Work beginner721 6 3,085 Jan-22-2021, 10:56 PM
Last Post: beginner721
  code doesnt return anything ofrihemo 3 2,032 Jun-30-2020, 05:14 PM
Last Post: ofrihemo
  BEGINNER: My calculator doesnt work iskov 5 3,185 Oct-09-2019, 07:45 AM
Last Post: buran
  Why this simple function doesnt work? blackknite 8 3,993 Jan-05-2019, 12:32 PM
Last Post: buran

Forum Jump:

User Panel Messages

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