PYTHON DICTIONARY
CommentsData typesVariablesIf ElseIf Elif ElseFunctionsFor loopWhile loopData structuresString slicingUser defined functionLocal/Global variableValidation and TryMethodsFile I/OPseudocodeModules |
What is a While Loop?Python challenge - While Loop with input() functionEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
Remember that "!=" means "does not equal", so in the code above, while answer does not equal N, then the questions "are we there yet" will be displayed. Code it and test it.
Python challenge - While loop using the NOT logical operatorEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
When you run this code, press enter to see what happens. What do you have to do to break out of the while loop? The program starts off with username set as an empty string and the second line states that there is no username, which is true and stays true until the user enters a username.
Python challenge - While loop using SYS module to quitEnter the following code in a Python code editor. Before running the code, what do you think it will do? Press "F5" then "Enter" to run
When you run this code, press enter to see what happens. Sys is a module that can be imported in.
Python challenge - While loop inside a....wait for it...while loopA while loop in a while loop. This is powerful. Ever been to a supermarket and used one of those self-checkout machines? They are always looping. A loop to handle every item scanned in as part of a transaction. Then the transaction ends and another customer uses the machine and it starts all over again.
The first loop is for each customer and inside each customer transaction there is another loop to handle scanning the items in...a loop in a loop! |