Skip to content

Instantly share code, notes, and snippets.

@AmirMahdyJebreily
Created July 25, 2023 14:34
Show Gist options
  • Save AmirMahdyJebreily/25ad50ce4d065812e12011ba8ce04549 to your computer and use it in GitHub Desktop.
Save AmirMahdyJebreily/25ad50ce4d065812e12011ba8ce04549 to your computer and use it in GitHub Desktop.
Advanced Python course of besat school - first code chalange
# CodeAgha 2023 - Advanced Python course of besat school - first code chalange
import re # import regex module
# regex for phone number validation
regex = r"((0?9)|(\+?989))((14)|(13)|(12)|(19)|(18)|(17)|(15)|(16)|(11)|(10)|(90)|(91)|(92)|(93)|(94)|(95)|(96)|(32)|(30)|(33)|(35)|(36)|(37)|(38)|(39)|(00)|(01)|(02)|(03)|(04)|(05)|(41)|(20)|(21)|(22)|(23)|(31)|(34)|(9910)|(9911)|(9913)|(9914)|(9999)|(999)|(990)|(9810)|(9811)|(9812)|(9813)|(9814)|(9815)|(9816)|(9817)|(998))\W?\d{3}\W?\d{4}"
contacts = {
"Ali": "+989123458965",
"Sara": "+989121068969",
"Somayeh": "+9809300010123",
"Heshmat": "+989022728293"
} # all contacs in a dictionary
ca = True # For continue the program
# program main loop
while ca :
print("Your contacts are:" , end=" ")
print(*contacts.keys(), sep=", ")
cname = input("Enter name of contact for add or view ditails: ") # inputed name
if(contacts.keys().__contains__(cname)):
print("\n{}\n".format(contacts[cname]))
else:
c = True
while(c): # loop of user phonenumber validation and adding new contact
phnum = input("\nThe inputed name was not found in contacts list\n Enter a phone number to add or enter \"x\" for cancel: ") # inputed phone number
if(phnum.lower() == "x"): # command 'x' for exit from user adding
c = False # exit validation loop
elif(re.findall(regex,phnum)):
contacts[cname] = phnum # add contact
print("\nOK\n")
c = False # exit validation loop
else:
print("\nInvalid opration\n") # error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment