def Take_profile(dict_name): while (True): spy.name = raw_input("enter your friend name :") #regex Pattern is used for validations pattern_n = '^[A-Z]{1}[a-z\s]+$' if (re.match(pattern_n, spy.name) != None): print("your name is :" + spy.name) break else: print "name cannot be numeric and Should start with capital letter" while (True): #validations used for salutations spy.salutation = raw_input("enter salutation Mr/Ms. :") if (spy.salutation == "Mr" or spy.salutation == "Ms"): print "hello " + spy.salutation + "." + spy.name break else: print "salutation not provided correctly" while (True): #validations for age used spy.age = raw_input("enter age :") pattern_a = '^[0-9]{1,3}$' if (re.match(pattern_a, spy.age) != None): print "your age is " + str(spy.age) spy.age = int(spy.age) break else: print "age cannot be 0 or alphabet" while (True): #validation for the rating that it should be float only try: spy.rating = float(raw_input("enter rating :")) if (spy.rating <= 5.0): print "your rating is " + str(spy.rating) break else: print "rating cannot be greater than 5" except Exception: print "invalid rating it can't be string" spy.is_online = True #full spy profile should be sent to start_chat for further task start_chat(spy.name, spy.age, spy.rating, spy.is_online)
from termcolor import colored import re print "Let's get started!" repeat = True while repeat: question = "Do you want to continue as" + spy['salutation'] + " " + spy[ 'name'] + "(Y/N) ?: " existing = raw_input(question) # validating user's input if (existing.upper() == 'Y'): # user want to continue as default user. # concatenation of salutation and name of spy spy_name = spy['salutation'] + " " + spy['name'] # starting chat application start_chat(spy['name'], spy['age'], spy['rating'], spy['is_online']) elif (existing.upper() == 'N'): # user wants to continue as a new user. # check whether spy has input something or not repeat = False wholecheck = True #temporary variable while wholecheck: tempcheck = True #again temporary variable # Validation Using Regex patternsalutation = '^Mr|Ms$' patternname = '^[A-Za-z][A-Za-z\s]+$' patternage = '^[0-9]+$' patternrating = '^[0-9]+\.[0-9]$' # validation using regular expression while tempcheck:
print(colored("\nHello!", "blue")) print "Let's get started!\n" #Ask the spy to continue as default spy or create new spy question = "Do you want to continue as " + spy.salutation + " " + spy.name + " (Y/N): " existing = raw_input(colored(question, "red")) # validating input if (existing.upper() == "Y"): # user wants to continue as default user. # concatination of salutation and name of spy. spy_name = spy.salutation + " " + spy.name # starting chat application. start_chat(spy.name, spy.age, spy.rating, spy.is_online) elif (existing.upper() == "N"): # user wants to continue as new user spy.name = raw_input("What is your name :") # chek spy has any input or not if len(spy.name) > 0: spy.salutation = raw_input("What should we call you ? : ") while True: try: spy.age = int( raw_input("Enter your age: ") ) # converting users input to integer (typecasting) break except ValueError: print "Invalid age. Try again"
from spy_details import spy, Spy from start_chat import start_chat question = "Do you want to continue as " + spy['salutation'] + " " + spy[ 'name'] + " (Y/N): " existing = raw_input(question) # <------------------validating users input---------------------> # if the user chooses the default spy if existing.upper() == "Y": # start the chat function is called start_chat(spy) # the user wants to add a new user elif existing.upper() == "N": # declare variables using a class spy = Spy(" ", " ", 0, 0.0) # Ask for the name spy.name = raw_input( "Welcome to spy chat, you must tell me your spy name first: ") # Check if the name is entered or not if len(spy.name) > 0 and spy.name.isdigit() == False: # ask for the salutation spy.salutation = raw_input("What should we call you Mr. or Ms.?") # check if salutation is entered or not if len(spy.salutation) > 0: # Ask for the age of the spy spy.age = raw_input("Please enter your age: ")
from globals import spy from start_chat import start_chat import re # Continue as a existing user print "Let's get Started" question = "Continue as %s %s (Y/N)" % (spy.salutation, spy.name) existinginput = raw_input(question) # validating new user's input if existinginput == "Y" or existinginput == "y": start_chat(spy.name, spy.age, spy.rating) elif existinginput == "N" or existinginput == "n": spy.name = raw_input("Enter your name here :") pattern = '^[a-zA-Z\s]+$' if (re.match(pattern, spy.name) != None): if len(spy.name) > 0: spy.salutation = raw_input("What should we call you? : ") spy.name = spy.salutation + " " + spy.name spy.age = 0 spy.rating = 0.0 spy.is_online = False while True: try: spy.age = int(raw_input("What is your age? ")) break except ValueError: print "Invalid age. Try again" # Checking the required age of user if type(spy.age) is int:
# import statements from spy_details import spy_name, spy_salutation, spy_age, spy_rating from start_chat import start_chat print "Let's get started!" question = "Do you want to continue as " + spy_salutation + " " + spy_name + " (Y/N): " existing = raw_input(question) # validating users input if (existing == 'Y' or existing == 'y') : # logic here. start_chat(spy_name, spy_age, spy_rating) elif (existing == 'N' or existing == 'n') : # new user code here. spy_name = raw_input("provide your name here :") # check whether spy has input something or not if len(spy_name) > 0: # code block if the condition is true. # concatination of salutation and name. spy_age = 0 spy_rating = 0.0 spy_is_online = False spy_salutation = raw_input("What should we call you ? : ") spy_age = raw_input("Enter your age. ?") print type(spy_age) spy_age = int(spy_name) print type(spy_age) spy_name = spy_salutation + " " + spy_name print 'Welcome ' + spy_name + " Glad to have you back with us" print "Alright " + spy_name + " i'd like to know little more about you before we proceed further" else:
from globals import Spy from termcolor import colored import re print "Let's get started!!!" whole=True #whole variable to iterate if value is not Y/N while whole: question = "Do you want to continue as " + spy.Name + "(Y/N) ? " existing = raw_input(question) # validating users input if existing.upper() == "Y": # default user whole=False start_chat(spy.Name, spy.Age, spy.Rating, spy.SpyOnline) elif existing.upper() == "N": # new user code here whole=False wholecheck=True#temporary variable while(wholecheck): tempcheck=True#temporary variable # Validation Using Regex patternsalutation='^Mr|Ms$' patternname='^[A-Za-z][A-Za-z\s]+$' patternage='^[0-9]+$' patternrating='^[0-9]+\.[0-9]$' # Validating Each Values Using Regular Expression while tempcheck: salutation = raw_input("Mr. or Ms.? : ")
import re from termcolor import colored print "Let's get started!!!" all=True #whole variable to iterate if value is not Y/N while all: question = "Do you want to continue as " + spy.Name + "(Y/N) ? " existing = raw_input(question) # validating users input if existing.upper() == "Y": # default user all=False start_chat(spy.Name, spy.Age, spy.Rating, spy.is_Online) elif existing.upper() == "N": # new user code here all=False check_all=True#temporary variable while(check_all): temp_check=True#temporary variable # Validation Using Regex patternsalutation='^Mr|Ms$' patternname='^[A-Za-z][A-Za-z\s]+$' patternage='^[0-9]+$' patternrating='^[0-9]+\.[0-9]$' # Validating Each Values Using Regular Expression while temp_check: salutation = raw_input("Mr. or Ms.? : ")
if __name__ == "__main__": print "Let's get started" # want to know user choice about login choice = raw_input('You want to start as guest Y/N : ') obj = Spy() if choice == "y" or choice == "Y": # getting guest user data # setting user data obj.setDetail() elif choice == "n" or choice == "N": # getting user data info = obj.get_user_info("your") # checking for error if info is False: print "Error in getting spy detail" exit(-1) else: print "Wrong Input" exit(-1) print "Authentication complete. Welcome" obj.showDetail() print "Proud to have you onboard" # sending to start chat for further execution start_chat()