We studied range command which generates a range of numbers in ascending or descending order (also supportS gaps, i.e. jumping by 2). we saw how to use a for loop over a range of numbers, i.e. print the numbers between 1-100, or 100-1000 etc. we created a list out of a range using the list keyword combined with the range keyword. for example: list(range(1, 100, 3)). we learned while loop and do-while loop. these types of loops are used whenever we want to make a loop with an exit condition. for example: read numbers from the user until the user enters a negative number… the main difference between while loop and do-while loop is that the while loop will NOT execute even once if the exit condition occurs, in oppose to do-while loop which will always be executed once before checking the exit condition. break will terminate the loop and “jump” out of the loop. continue will skip the current iteration and “jump” to the next iteration. we practiced the while loop by writing a calculator which performs mathematical operations depending on the user input, until the user enters ‘Q’ . finally, we learned about the debugger in PyCharm. the debugger helps us to run our program line-by-line to inspect the flow. it also shows us the value of the memory cells used by our program (variables).
More topics covered:
- Better doing String comparison using upper( )
- Boolean variables
- Boolean names: isAbove10, didUserAgreed, etc.
- Reverse range = range (5, 1, -1)
- ”.join (list) will turn a list into one long string
- Finding max number in a list (without max command )
- Finding min number in a list (without min command)
- Python do-while is implemented using while True and break
- Debugger Step-Into and Step-Over
Links:
