Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Break, Continue, and Pass Statements with Examples

Rohit Kumar Thakur
Python in Plain English
4 min readOct 28, 2021

--

break, continue, and pass statements in python
while True:
num = input("Enter the number: ")
if num == "":
break
number = int(num)
print("The square of the number ",number," is: ", number*number)
print("User entered a null string")
>>> Enter the number: 5
The square of the number 5 is: 25
Enter the number: 6
The square of the number 6 is: 36
Enter the number: 7
The square of the number 7 is: 49
Enter the number:
User entered a null string
def main():
check = input("Are you a new student(yes/no): ")
if check == "yes":
pass
elif check == "no":
totalMarks = 0
numOfSub = 0
while True:
marks = input( 'Marks for subject ' + str(numOfSub +1) + ": ")
if marks == '':
break
marks = float(marks)
if marks < 0 or marks >100:
print("Invalid marks")
continue
numOfSub = numOfSub+1
totalMarks = totalMarks + marks
percentage = totalMarks/numOfSub
print("Total marks: ", totalMarks)
print("Number of Subject is: ", numOfSub)
print("Percentage: ", round(percentage,2))
else:
print("enter a valid response")
main()
>>> Are you a new student(yes/no): no
Marks for subject 1: 56
Marks for subject 2: 68
Marks for subject 3: 98
Marks for subject 4: 88
Marks for subject 5: 94
Marks for subject 6:
Total marks: 404.0
Number of Subject is: 5
Percentage: 80.8
>>> Are you a new student(yes/no): yes
>>> Are you a new student(yes/no): sdgfs
enter a valid response
>>> Are you a new student(yes/no): no
Marks for subject 1: 45
Marks for subject 2: 566
Invalid marks
Marks for subject 2: 56
Marks for subject 3: 65
Marks for subject 4:
Total marks: 166.0
Number of Subject is: 3
Percentage: 55.33

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

No responses yet

Write a response