Practpython
Practpython
The break statement in Python terminates the current loop and resumes execution at the next
statement, just like the traditional break found in C.
The most common use for break is when some external condition is triggered requiring a hasty
exit from a loop. The break statement can be used in both while and for loops.
Example:
Current Letter : P
Current Letter : y
Current Letter : t
Current variable value : 10
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Good bye!
The continue statement can be used in both while and for loops.
Example:
#!/usr/bin/python
Current Letter : P
Current Letter : y
Current Letter : t
Current Letter : o
Current Letter : n
Current variable value : 10
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Current variable value : 4
Current variable value : 3
Current variable value : 2
Current variable value : 1
Good bye!
6. Program using Functions.
def test_prime(n):
if (n==1):
return False
elif (n==2):
return True;
else:
for x in range(2,n):
if(n % x==0):
print("not a prime")
print("Given no is prime")
def fact(n):
if n == 0 or n ==1 :
return 1
else:
return (n * fact(n-1))