Advertisement
Himel-Rana

Ans to the q. no: 4

Apr 17th, 2021
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # Bangladesh Country code: +880
  2. # India Country code: +91
  3. # Pakistan Country code: +92
  4. # Usa Country code: +1
  5. # UK country code +44
  6.  
  7. # number to country
  8. def get_country(number):
  9.     if number[0:4] == '+880' or number[0:3] == '880':
  10.         return "Bangladesh"
  11.     elif number[0:3] == '+91' or number[0:2] == '91':
  12.         return "India"
  13.     elif number[0:3] == '+92' or number[0:2] == '92':
  14.         return "Pakistan"
  15.     elif number[0:2] == '+1' or number[0:1] == '1':
  16.         return "United States (US)"
  17.     elif number[0:3] == '+44' or number[0:2] == '44':
  18.         return "United Kingdom (UK)"
  19.     else:
  20.         return "Unknown Country"
  21.  
  22.  
  23. phone_numbers = open('phone-numbers.txt', 'r')
  24. Lines = phone_numbers.readlines()
  25.  
  26. count = 0
  27. for line in Lines:
  28.     count += 1
  29.     country = get_country(line.strip())
  30.     print("Phone Number: {} country: {}".format(line.strip(), country))
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement