followed by at least one alphanumeric character.it must start with at least one alphanumeric character.For the purpose of this task the requirements are: The program below will check if an email meets the right format requirements. The Regular Expressions library allows you to set a pattern and then check to see if the data follows that pattern.īelow are some examples of Regular Expressions patterns as well as what they mean: If you want to perform a format check in Python you will need to make use of a library. This is what happens when the program is run: To perform a range check you can simply use an if and then use and to connect two conditions together. Number = int ( input ( "Please enter a number between 1 and 100: " )) if number > 0 and number <= 100 : print ( "You entered a valid number" ) else : print ( "You must enter a number between 1 and 100" ) In Python you can easily do a type check to check whether a value is a number or not a number, see the example below: Format Check - checking that data follows a set format.Range Check - checking that data is between two boundaries set.Presence Check - checking that data is entered before continuing.Type Check - checking the data is of a particular type before continuing.
There are some simple ways in which you can validate programs, these are: The user could enter 01234567891, this meets the requirements set, but does not mean it is a valid telephone number. For example if you had to enter a telephone number, you could validate it and say it needs to be 11 digits starting with a 0. Validation is the process of checking to see if data that is entered meets a set of requirements, this does mean it will always stop incorrect data being entered. #two inputs asking for the distance and passengers km = float ( input ( "Enter the distance of the taxi ride in kilometres (KM): " )) passengers = int ( input ( "Enter the number of passengers: " )) #calculation to work out the cost cost = 3 + (( km - 1 ) * 2 ) #checks to see if the number of passengers is more than 5 so that the additional 50% cost can be added if passengers > 5 : #calculates the extra cost if the condition is true cost = cost * 1.5 #displays the total cost of the journey print ( "The total cost of the journey for", passengers, "passengers is £".format(variable)
if-elseįor a computer to make decisions based on a condition, you must use an IF statement, it has the following structure:
When you run multibeast what files get updated full#
Life is full of decisions that you will make depending on certain conditions, computers are no different. IF the day is a Saturday AND the alarm clock goes off THEN you might turn it off and stay in bed OTHERWISE you might get up. IF you wake up in the morning and it is raining THEN you will take a coat to school OTHERWISE you wont. Sometimes you will change what do you depending on the conditions. #three variables that store the two inputs and also the value of pie radius = float ( input ( "Enter the cylinder radius: " )) height = float ( input ( "Enter the cylinder height: " )) pie = 3.14159 #calculations to work out the volume and surface area volume = pie * ( radius * radius ) * height surface = ( 2 * ( pie * ( radius * radius ))) + ( 2 * ( pie * radius * height )) #outputs the volume and surface area of the cylinder print ( "The volume of your cylinder is", round ( volume, 2 ), "to 2 decimal places" ) print ( "The surface area of your cylinder is", round ( surface, 2 ), "to 2 decimal places" )