def add_friend(): sys.stdout.write(Fore.YELLOW + " ") new_friend = Spy('', '', 0, 0.0) # Asking the user for input until they give a valid response while True: new_friend.spy_name = str( raw_input("\nPlease add your friend's name: ")) J5 = r"([a-zA-Z]+)" if re.search(J5, new_friend.spy_name): # i am happy with the value given # exiting loop break else: print "\nPlease Enter a valid value..!!" continue # Asking the user for input until they give a valid response while True: new_friend.spy_salutation = raw_input( "\nShould i call you Mr. or Ms.?: ") J6 = r"([Mm]r)" J7 = r"([Mm]s)" if re.search(J6, new_friend.spy_salutation) or re.search( J7, new_friend.spy_salutation): # i am happy with the vale given # exiting loop break else: print "\nPlease enter a valid value.." continue # Asking the user for input until they give a valid response while True: try: new_friend.spy_age = int(raw_input("\nEnter age: ")) except ValueError: print "\nSorry, i didn't understand that." continue if new_friend.spy_age < 0: print("\nSorry, your response must not be negative") continue else: # i am happy with the value # exiting loop break # Asking the user for input until they give a valid response while True: try: new_friend.spy_rating = float(raw_input("\nEnter rating: ")) except ValueError: print "\nSorry, i didn't understand that." continue if new_friend.spy_rating < 0: print("\nSorry, your response must not be negative") continue else: # i am happy with the value # exiting loop break if len( new_friend.spy_name ) > 0 and new_friend.spy_age > 12 and new_friend.spy_age < 50 and new_friend.spy_rating >= spy.spy_rating: friends.append(new_friend) print '\nFriend Added!' else: print '\nSorry! Invalid entry. We can\'t add spy with details you provided ' return len(friends)
if spy.spy_age < 0: print("\nSorry, your response must not be negative") continue else: # i am happy with the value # exiting loop break # Asking the user for input until they give a valid response while True: try: spy.spy_rating = float(raw_input("\nWhat is your spy rating: ")) except ValueError: print "\nSorry, i didn't understand that." continue if spy.spy_rating < 0: print("\nSorry, your response must not be negative") continue else: # i am happy with the value # exiting loop break