def add_friend(): new_friend = { 'name': '', 'salutation': '', 'age': 0, 'rating': 0.0, 'chats': [] } #the user will be asked to give the details of their desired friend new_friend['name'] = raw_input('Please add your friend\'s name: ') new_friend['salutation'] = raw_input("Are they Mr. or Ms.?: ") new_friend['name'] = new_friend['salutation'] + " " + new_friend['name'] new_friend['age'] = raw_input('Age?') new_friend['age'] = int(new_friend['age']) new_friend['rating'] = raw_input('Spy rating?') new_friend['rating'] = float(new_friend['rating']) #if the user does enter a valid string as the name and the age is valid as set greater than 12 , the syatem will accept the entry #else the user will be promted to enter a valid name or valid age if len(new_friend['name']) > 0 and new_friend['age'] > 12 and new_friend['rating'] >= spy['rating']: friends.append(new_friend) print 'Friend Added!' else: print 'Sorry! Invalid entry. We can\'t add a spy with the given details ' return len(friends)
def add_friend(): new_friend = { 'name': raw_input("Please add your friend's name: "), 'salutation': raw_input("Are they Mr. or Ms.?: "), 'age': 0, 'rating': 0.0, 'chats': [] } new_friend['name'] = new_friend['salutation'] + " " + new_friend['name'] new_friend['age'] = raw_input("Age?") new_friend['age'] = int(new_friend['age']) new_friend['rating'] = raw_input("Spy rating?") new_friend['rating'] = float(new_friend['rating']) if len( new_friend['name'] ) > 0 and new_friend['age'] > 12 and new_friend['rating'] >= spy['rating']: friends.append(new_friend) print('Friend Added!') else: print( 'Sorry! Invalid entry. We can\'t add spy with the details you provided' ) return len(friends)
def add_friend(): new_friend = Spy('','',0,0.0) #added in the spy class new_friend.name = raw_input("Please add your friend's name: ") if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend): print "Invalid entry." else: print new_friend new_friend.salutation = raw_input("Formal Salutation: Mr. or Ms. or Mrs. ") new_friend.name = new_friend.salutation + " " + new_friend.name new_friend.age = raw_input("Age?") new_friend.age = int(new_friend.age) new_friend.rating = raw_input("Spy rating?") new_friend.rating = float(new_friend.rating) if len(new_friend.name) > 2 and new_friend.age > 15 and new_friend.rating >= spy.rating: friends.append(new_friend) print 'New Friend Added!' else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided!!' return len(friends)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input('Please add your friend\'s name :') new_friend.salu = raw_input('are they Mr or Miss ? :') new_friend.age = int(raw_input('age:')) new_friend.rating = float(raw_input('spy rating')) if (new_friend.name.isalpha() ) and new_friend.age > 12 and new_friend.rating >= spy.rating: #add friend into friend list friends.append(new_friend) else: print 'Sorry! invalid entry.We can\'t add spy with the detalis you provided ' return len(friends)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input("Enter friends name") new_friend.salutation = raw_input("Are they Mr. or Ms.?: ") new_friend.name = new_friend.salutation + " " + new_friend.name new_friend.age = raw_input("Age?") new_friend.age = int(new_friend.age) new_friend.rating = raw_input("Spy rating?") new_friend.rating = float(new_friend.rating) new_friend.chats = [] if len(new_friend.name) > 0 and new_friend.age > 12: friends.append(new_friend) print colored('\nFriends Added', 'yellow', attrs=['bold']) else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided' return len(friends)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = input("please ! add your friends name ? ") name = new_friend.name new_friend.salutation = input("Are they MR OR MS") new_friend.name = new_friend.salutation + " " + name new_friend.age = int(input("enter age ?")) new_friend.rating = float(input("spy rating ?")) if len(new_friend.name) > 0: print("spy name is not empty") if (name_vali(name) is True) and age_val(new_friend.age): friends.append(new_friend) else: print( "sorry invalid entry . we can't add spy with details you provided") # return the no of friends in dictionary return len(friends)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input("Please add your friend's name: ") new_friend.salutation = raw_input("Are they Mr. or Ms.?: ") new_friend.age = raw_input("Age?") new_friend.age = int(new_friend.age) new_friend.rating = raw_input("Spy rating?") new_friend.rating = float(new_friend.rating) if len(new_friend.name ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating: friends.append(new_friend) print 'Friend Added!' print_friends() else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided' return len(friends)
def add_friend(): #creating empty values for new friend new_friend = Spy('', 0, '', 0.0) #to evaluate all details of spy's new friend like name, age, rating and salutation new_friend.name = raw_input("add your friends name:") new_friend.salutation = raw_input("are they Mr. or Ms.:?") new_friend.name = new_friend.name + " " + new_friend.salutation new_friend.age = int(raw_input("age?")) new_friend.rating = float(raw_input("spy rating?")) #to check the spy's friend's age, rating and the name that should not be empty if len(new_friend.name ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating: friends.append(new_friend) print colored('Friend Added!', 'red') else: print colored( 'sorry! invalid entry. we can\'t add spy with the details you provided', 'blue') return len(friends)