This document discusses Python loops and conditionals. It provides examples of using break and continue in for loops. It also covers operators like == and !=, calculating remainders with the % operator, using range() to iterate over a range of numbers, appending to lists, taking user input, nested loops, and arithmetic operations.
2. break & continue :
Break : its job to go out from
the actually condition or loop only
Ex
x=[0,1,2,3,4,5]
for i in x :
print ("*")
if i == 2:
break
Output : ***
>>>NOT ******
for ( ) :
If ( ) :
--------
--------
--------
break
-------
-------
-----
break
-----
3. o Continue : its job to repeat
o the actually condition or loop only
o Ex
o x=[0,1,2,3,4,5]
o for i in x :
o print ("*")
o if i == 2:
o continue
o print("$")
Output : ******
>>> there is no “$”
While
if
______
______
continue
______
______
_____
continue
_____
4. I. for & while & if >>> should end with ( : )
II. X=X+1 >>>X+=1 && X-1 >>> X=X-1
III. X=Y “take the value in y and put it in x”
IV. X==Y “is the value in x as the same in y ? ”
V. X != Y “ X not equal Y ”
VI. (while True:)testing the code without doing Run every time
VII. When I use many loops ; first I finish the last loop
for (1)
for(2)
for(3)
Third loop
second loop
First loop
5. % :: 10%3=1 , 53%10=3 , 115%100=15 “calculate the remainder”
// :: 11//3=3 , 30//9=3 , 100//40=2 “set the integer num. only”
To test if the number is negative >>> if x < 0
To test if the number is odd >>> if x!= 0
To write a comment >>> #...
To calculate x power y >>> x**y
x=[1,2,3,4,5,6,7,8,9,10]
for i in x:
print(i)
Output : 12345678910
So “for loop” start
automaticlly from index[0]
and it additions 1 every time
until the end of the loop
range ( 5 , 100 , 2 )
First num
Last num
Rate of change
6.
7.
8.
9. x=str(input('enter numbers only :'))
for i in x:
if i=='0' or i=='1'or i=='2'or i=='3'or i=='4'or i=='5'or i=='6'or i=='7'or i=='8'or i=='9':
z=True
else:
z=False
break
print(z)
1)Enter a string which have numbers or letters or twice ,but if and only if this string
includes numbers only: print true , else: print false?