Thursday, February 2, 2017

Python Loops: String Values

Using an editor, like Notepad++ or VIM open a file called:
 
loop1.py
 
In the editor enter the code shown below. Do NOT omit the indentation--in Python, indentation is required to indicate what code is inside a loop:



Save the file and run in a Cygwin terminal.


python3 loop1.py
As you can see below, the code loops through all the listed computer brands
.



Python Loops: Numerical Values

Using an editor, like Notepad++ or VIM open a file called:

loop2.py
In the editor enter the code shown below. Do NOT omit the indentation--in Python, indentation is required to indicate what code is inside a loop:

Save the file and Execute this command to run the script:

python3 loop2.py
As you can see, the code loops through all the numbers and evaluated the summing equation all 10 in the range from 0 to 9

:

Using an editor, like Notepad++ or VIM open a file called:

loop3.py
In the editor enter the code shown below. Do NOT omit the indentation--in Python, indentation is required to indicate what code is inside a loop:



Save the file and Execute this command to run the script:

python3 loop3.py
As you can see, the code loops through all the numbers and evaluated the summing equation all 6 number [1,10,20,30,40,50]:


No comments:

Post a Comment