pythonm
pythonm
2022
Computer science
Python provides two types of loops=the for loop and the while
loop
For loop -The for loop is used to iterate over a numeric range or
over a collection of items.
For loop over a numeric range. The range function is used to set
up for a loop has a following format;
The general format for the for loop with a numeric range is:
You can use a for loop with a string a list , a tuple or a dictionary
the general format for this usage :for item in collection statement
(s);
Let us write the python program to display the list even numbers
from one to 10 using a for loop.
While loop
Jump statement = sometimes you may want to get out of the loop
or manipulate the loop variable even before the termination
condition becomes true. jump statements allow you to do
that .python offers three jump statement-break, continue and
pass.
Continue statement
Pass statement :
Syntax error
Logical error
Runtime error
For example:
Logical error
This error occurs only when a program executes but does not
produce the required result this is because of the wrong logic
used in the program the python interpreter will not show any
error on the screen you have to find the error by executing the
program yourself using pen and paper(called a dry run) and
correct it.
#from 1to 10
Print(num , “x”,I,)
Flag=0;
A=int(sqrt(num))
If num%i==0;
Flag=1;
Break;
If flag==0;
Else
Graphics in python
You can draw in python using its graphics module the module
does not come with the python program by default .you have to
install the file graphics.py manually
Drawing a point
Syntax error : syntax s=error occur only when rules for writing a
statement is not allowed :for example:
Syntax error : syntax s=error occur only when rules for writing a
statement is not allowed :for example:
Syntax error : syntax s=error occur only when rules for writing a
statement is not allowed :for example:
Drawing a line:
Drawing a circle