PYTHON DICTIONARY
CommentsData typesVariablesIf ElseIf Elif ElseFunctionsFor loopWhile loopData structuresString slicing/indexingUser defined functionLocal/Global variableValidation and TryMethodsFile I/OPseudocodeModules |
What is validation?
Enter 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
Most cars only have 4 tyres. This means that the range of tyres that can be changed on a car is 1 to 4. What happens if you want to change 0 tyres or more than 4 tyres?
Validation - Lookup check
What happens if you choose something not in the list called "allTitles"?
Python challenge - TryEnter 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
In this code, the third line specifies that a user enters an INT. Run the code and enter some letters instead. Will the code crash? Depending if the data entered by the user, the code will branch accordingly and ultimately prevent your code from crashing.
Python challenge - Try - Zero division errorEnter 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
In this code you are handling an exemption. The exemption is a user attempting to divide by zero. Can you add additional code that occurs after the exception that redirects a user to to perform a division again?
Python challenge - email validationEnter 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
This is a basic form of validation to see if a particular character exists in a users input. For instance, if a user is asked to enter their email address and they type in some gibberish, you can create some code that validates and rejects it.
|