# Automatic Petrol Pump Algorithm In this challenge we will implement an algorithm to be used in an Automatic Petrol Pump to interact with the customer and calculate the total cost of filling up their vehicle.

The fuel options and tariffs at this petrol station are as follows:

• Super Unleaded: £1.27 per litre,
• Diesel: £1.21 per litre,
• Diesel Premium: £1.34 per litre,

The petrol pump will interact with the customer by asking the following questions:

• What fuel do you require?
• Do you want to fill up (full tank capacity) and if not how many litres of fuel do you require?

The petrol pump will use this information provided by the customer as well as the tariffs provided above to calculate the total cost of this order.

To simulate a real life situation, we will assume that the customer’s vehicle has a tank capacity of 55 litres.
We will also assume that when the customer reaches the petrol station, the vehicle still has some fuel left. To simulate this we will generate a random number between 0 and 55. This number will represent the number of litres left in the tank before filling up.

If the customer requires a full tank, the algorithm will calculate the quantity needed as follows:

Quantity Needed = Full Tank Capacity – Current Fuel Level

If the customer specifies a desired quantity (in litres), the algorithm will fill up the tank with the required quantity. However, if the required quantity combined with the current level of fuel in the tank exceeds the full tank capacity, the required quantity will be replaced to just the quantity that is needed using the same formula as mentioned above.

#### Petrol Pump Algorithm: Pseudocode

The suggested pseudocode for our Automatic Petrol Pump is as follows:

Your task is to use this pseudocode to implement this algorithm using Python.

Add some input validation to ensure that, if the user does not provide a valid answer, the same question is being asked again.

You should use:

• A Lookup Check to check that the user is answering either A, B, C or D when being asked about their fuel choice?
• A Lookup Check to check that the user is answering either Yes or No to the question: Would you like to fill up to a full tank?
• A Type Check to ensure that the user is entering a valid positive number when asked about the number of litres they do require.

Pseudocode for Lookup validation Tagged with: ,
{"ft_lang_label":"__label__en","ft_lang_prob":0.8445545,"math_prob":0.8120647,"size":3871,"snap":"2021-43-2021-49","text_gpt3_token_len":990,"char_repetition_ratio":0.11430049,"word_repetition_ratio":0.08381503,"special_character_ratio":0.25807285,"punctuation_ratio":0.076246336,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97790074,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-19T02:40:50Z\",\"WARC-Record-ID\":\"<urn:uuid:1e728054-09fb-428e-9333-54122b3cfa80>\",\"Content-Length\":\"73029\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0f852ce7-1f27-4bc2-9684-1bdcead2cfba>\",\"WARC-Concurrent-To\":\"<urn:uuid:4189f395-2e77-48d1-ab20-0753cb42fe5c>\",\"WARC-IP-Address\":\"109.203.118.7\",\"WARC-Target-URI\":\"https://www.101computing.net/automatic-petrol-pump-algorithm/\",\"WARC-Payload-Digest\":\"sha1:AERVD3PMUEKIWA5ANDKKSCMCU7NHGDB5\",\"WARC-Block-Digest\":\"sha1:N57FPCUGJD4KH7RUYU57KXAIMPFBOBLS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585231.62_warc_CC-MAIN-20211019012407-20211019042407-00209.warc.gz\"}"}