def add_friend(): frnd=Spy('','',0,0.0) #to add a new friend frnd.name = raw_input('What is your friend \'s name? ') frnd.sal = raw_input("What should we call your friend?") frnd.age = input('What is your friend\'s age ? ') frnd.ratings = input('What is your friend\'s rating ?') frnd.is_online= True if len(frnd.name)>2 and 14<frnd.age<60 and frnd.ratings>spy.ratings: # conditons for adding new friend friends.append(frnd) #adding this new friend in the list of already existing friends with open('friends.csv','a') as friends_data: writer = csv.writer(friends_data) writer.writerow([frnd.name, frnd.sal, frnd.ratings, frnd.age, frnd.is_online]) else: print "Friend cannot be added." return len(friends) # will return to add_friend()
def add_friend(): friend_obj = Spy(" ", " ", 0, 0.0) friend_obj.name = input("Enter your friend name:") # Validating the name if friend_obj.name.isspace is True or len(friend_obj.name) == 0: print("Enter a valid name") else: # To capitalize the first character of a string friend_obj.name = friend_obj.name.capitalize() friend_obj.salutation = input("What do you want to use"\ " with your friend name Dr./Mr./Mrs?\n") friend_obj.salutation = friend_obj.salutation.capitalize() # Updating the values of the variable friend_obj.name = f'{friend_obj.salutation} {friend_obj.name}' friend_obj.age = int(input("Enter the Spy age:")) if 12 < friend_obj.age < 50: friend_obj.ratings = float(input("Enter the spy Ratings"\ " for your friend:")) if friend_obj.ratings >= 4.5 or 3.5 <= friend_obj.ratings < 4.5: friends.append(friend_obj) else: print("Enter a valid rating") else: print("You are not eligible for being a spy") # To return the numbers of friends user have return len(friends)
elif spy_exist.upper()=="Y": #if spy is new then the registration starts spy = Spy(" "," ",0,0.0) spy.name = raw_input("What is your spy name?") if spy.name.isspace(): #to ensure that input is not space print "Enter a valid name." elif len(spy.name)>2: #to check the length of the input print "Welcome " + spy.name +". Glad to have you with us." spy.salutation=raw_input("What should we call you (Mr. or Ms.)?") if spy.salutation=="Mr." or spy.salutation=="Ms.": spy.name=spy.salutation + spy.name #concatenation print "Alright " + spy.name + ". I would like to know a little bit more about you." spy.age = input("What is your age?") if 60>spy.age>14: print "Your age is correct." spy.ratings = input("What is your ratings?") if spy.ratings>8.0: print "Great spy" #commenting under nested ifs elif 5.5<spy.ratings<=8.0: print "Average spy" elif 3.0<spy.ratings<=5.5: print "Bad spy" else: print "Are you really a spy?" spy_is_online=True print "Authentication is completed. Welcome %s of age: %d having ratings %f " % (spy.name,spy.age,spy.ratings) spy_chat(spy.name,spy.age,spy.ratings) # to provide options to the spy else: print "Sorry.Your age is not eligible to be a spy." else: print"Invalid salutation"
if spy.name.isspace is True or len(spy.name) == 0: print("Enter a valid name") else: # Capitalizing the first character of the name entered by user spy.name = spy.name.capitalize() spy.salutation = input("What do you want to use with your name"\ " Dr./Mr./Mrs?\n") spy.salutation = spy.salutation.capitalize() spy.age = int(input("Enter the Spy age:")) # Validating the age and ratings entered by user if 12 < spy.age < 50: spy.ratings = float(input("Enter the spy Ratings:")) if spy.ratings >= 4.5: print("Great Ace") elif 3.5 <= spy.ratings < 4.5: print("Better one") else: print("Enter a valid rating") # Setting the user online spy.is_online = True start_chat(spy) else: print("You are not eligible for being a spy") exit()