Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 874a70d

Browse filesBrowse files
author
irsol
committed
Updated functions.
1 parent 6044f49 commit 874a70d
Copy full SHA for 874a70d

File tree

Expand file treeCollapse file tree

1 file changed

+8
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-8
lines changed

‎boolean_practice/break_continue.py

Copy file name to clipboardExpand all lines: boolean_practice/break_continue.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
file = open("data.txt", "r")
55
for line in file:
66
line = line.strip()
7-
if line == "Earth":
7+
if "Earth" in line:
8+
print(f"Earth is at line {text_line}")
89
break
910
text_line = text_line + 1
10-
print(f"Earth is at line {text_line}")
1111

1212

1313
# Finds which line in a txt file contains string "Earth".
1414
# This function uses continue statement to include all lines and skip comment lines.
1515

16-
entry_num = 1
16+
entry_num = 0
1717
file = open("data.txt", "r")
1818
for line in file:
1919
line = line.strip()
20-
if line.startswith("#"):
21-
continue
22-
if line == "Earth":
23-
break
2420
entry_num = entry_num + 1
25-
print(f"Number: {entry_num}")
2621

22+
if line.startswith("#"):
23+
continue
2724

25+
if "Earth" in line:
26+
print(f"Number: {entry_num}")
27+
break

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.