![]() 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: 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" ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |