def add_friend(): # function to add friend # taking friend detail as input frnd = Spy("","",0,0.0) # class for details of friend frnd.name = raw_input("What is your friend's name :") frnd.sal = raw_input("What is your friends salutation") frnd.age = input("What is the age :") frnd.rating = input("What are the rating :") frnd.is_online = True if len(frnd.name)>0 and 12<frnd.age<50 and frnd.rating > spy.rating: # adding the details in the respective lists with open('friend.csv','ab')as friend_data: writer = csv.writer(friend_data) writer.writerow([frnd.sal,frnd.age,frnd.rating,frnd.is_online]) print "Your frnd is added" friends.append(frnd) # appending friend details in friend list else: print "The friend cannot be added " return len(friends) # retuning length of list friend_name
def add_friend(): #ADD FRIEND frnd = Spy(" ", " ", 0, 0.0) frnd.Name = raw_input("What is your name ? ") frnd.sal = raw_input("What should we call u ? ") frnd.Age = input("What is your age? ") frnd.Rating = input("What is your rating? ") frnd.is_online = True if len(frnd.Name) > 2 and 12 < (frnd.Age) < 50 and (frnd.Rating): friends.append(frnd) with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow( [spy.name, spy.saluation, spy.rating, spy.age, spy.is_online]) else: print "Friend cannot be added" return len(friends)