Python Classroom Series – 25/May/2021

Break and continue in a loop

  • Skip Ahead with continue:
    • In certain scenarios, you want skip ahead to next iteration without executing the current iteration then continue
    • Refer Here for the example which skips printing multiples of 7
  • Cancel with break
    • Lets write a program which will tell whether the number is even or odd
    • This program should continue asking user for numbers till he asks the program to quit
    • Refer Here for the example which breaks from the loop depending on user input
  • Write a Program to check whether the number provided by user is prime or not
  • Check break use with else:
    • If the while loop ended normally without encountering break statement, control passes to optional else
    • Refer Here

Project Euler 3

Assignment Expressions

  • Operators
+=
-=
*=
/=
  • Examples:
a += 5  <==> a = a + 5
a -= 5  <==> a = a - 5
a *= 5  <==> a = a * 5
a /= 5  <==> a = a / 5
a //=5  <==> a = a // 5
a **= 5  <==> a = a ** 5
  • Refer Here for the usage of the above mentioned operators.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin