Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Discover a wealth of knowledge from experts across different disciplines on our comprehensive Q&A platform. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly platform.

Write the code (from to )using for loop andif elseif statementto accept themobile phone numbersof200 residents of Dubaiasstringand check if thelength of eachmobile number is10. Depending on the first 3 characters of the mobile number,display the messagefrom the table below:First 3 charactersMessage“050”, “054”, “056”Etisalat number“052”,“055”, “058”DunumberFor anyother input(if the phone number is not a ten digit number or if it does not start with any of the above digits)Not a valid mobile number

Sagot :

Answer:

In Python:

nos = int(input("How many phone number: "))

for i in range(1,nos+1):

   phn = input("Phone Number: ")

   if not len(phn) == 10:

       print("Invalid")

   else:

       charactersMessage = phn[0:3]

       if charactersMessage in ['050', '054', '056']:

           print("Etisalat Number")

       elif charactersMessage in ['052', '055', '058']:

           print("Du Number")

       else:

           print("Invalid")

Explanation:

Prompts the user for the frequency of phone numbers to check

nos = int(input("How many phone number: "))

This iterates through the phone numbers

for i in range(1,nos+1):

This prompts the user for phone number

phn = input("Phone Number: ")

Prints invalid id number length is not 10

if not len(phn) == 10:

   print("Invalid")

If otherwise

else:

This gets the first 3 characters

   charactersMessage = phn[0:3]

Prints Etisalat number if the characters are either 050, 054 or 056

   if charactersMessage in ['050', '054', '056']:

       print("Etisalat Number")

Prints Du number if the characters are either 052, 055 or 058

   elif charactersMessage in ['052', '055', '058']:

       print("Du Number")

Prints error if otherwise

   else:

       print("Invalid")