def add_friend(): #creating a new default friend new_friend = Spy("", "", 0, 0.0) time.sleep(0.3) new_friend.name = raw_input( "Input your friends name: ") #asking for friend's name new_friend.name = check_name( new_friend.name) #checking the validity of the name time.sleep(0.3) new_friend.sal = raw_input( "Is your friend Mr or Ms: ") #asking foor salutation new_friend.sal = check_Sal( new_friend.sal) #checking the validity of the salutation time.sleep(0.3) new_friend.age = int( raw_input("Age of your spy friend: ")) #age input in int time.sleep(0.3) new_friend.rating = input( "Enter your spy friend's spy rating: ") #rating input in float if (check_age(new_friend.age)): #check for appropriate age friends.append( new_friend ) #if valid new friend to be appended at the end of the friends list #writing details of new friend at the end of the file using ab with open("friends.csv", "ab") as friends_data: writer = csv.writer(friends_data) writer.writerow([ new_friend.name, new_friend.sal, new_friend.age, new_friend.rating, new_friend.is0nline ]) else: time.sleep(0.3) print "Sorry you are not of appropriate age to be a Spy!" #inappropriate age return len(friends) #return length of friends list
def add_friend(): frnd = Spy('', '', 0, 0.0) frnd.name = raw_input('What is your friend name ? ') #required an input frnd.sal = raw_input('What should we call you Mr. or Ms.') frnd.age = input('What is your age ? ') #required an input frnd.rating = input('What is your rating ? ') #required an input spy.is_online = True if len( frnd.name ) > 2 and 12 < frnd.age < 50 and frnd.rating > spy.rating and frnd.name.isalpha( ): #checking for the condition frnd.name = frnd.name.upper() frnd.sal = frnd.sal.upper() with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow( [frnd.name, frnd.sal, frnd.rating, frnd.age, spy.is_online]) print 'Your friend is added' else: print 'Friend cannot be added..' #displaying for the user return len(friends) #returning the value for the function
def add_friend(): #define add friend function frnd = Spy("", "", 0, 0.0) frnd.name = raw_input( "What is your friend's name ? ") #input friend's name frnd.sal = raw_input('Mr or Ms') frnd.age = input("What is your friend's age ?") #input friend's age frnd.rating = input( "What is your friend's rating ?") #input friend's rating frnd.is_online = True #set friend is online if len( frnd.name ) > 2 and 12 < frnd.age < 50 and frnd.rating > spy.rating and frnd.name.isalpha( ): #check condition for adding friend frnd.name = frnd.name.upper() frnd.sal = frnd.sal.upper() with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow( [frnd.name, frnd.sal, frnd.rating, frnd.age, frnd.is_online]) print 'your friend added successfully' else: print 'Friend cannot be added..' #conditional statement return len(friends) #return no of friends
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(): frnd=Spy('','',0,0.0) frnd.sal=raw_input('what should we call you?') frnd.name=raw_input('Enter your name: ') 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>spy.rating: friends.append(frnd) with open('friends.csv','a') as friends_data: writer=csv.writer(friends_data) writer.writerow([frnd.name,frnd.sal,frnd.age,frnd.rating,frnd.is_online]) print'Your friend is added successfully..' else: print'Friend cannot be added' return len(friends)
def add_friend(): # function to add friend # taking friends detail s input frnd = Spy ('','',0,0.0) frnd = {'name': "",'age':0,'ratings':0.0,'isonline':True,'chats':[]} # dictionary for details of friend frnd.name =raw_input("What is your friend's name : ") frnd.sal = raw_input("What should we call you") frnd.age=input("What is the age :") frnd.rating=input("What are the ratings : ") frnd.is_online = True if len(frnd.name)>0 and 12<frnd.age<50 and frnd.rating>spy.rating: # checking for spy details # adding the details in the respective lists friends.append(frnd) with open('friends.csv','a') as friends_data: writer = csv.writer(friends_data) writer.writerow([frnd.name, frnd.sal, frnd.rating, frnd.age, frnd.is_online]) else: print "The friend cannot be added " return len(friends) # returning length of list friend_name
def add_friend(): # defining function add_friend() frnd = Spy('', '', 0, 0.0) frnd.name = raw_input("What is your friend name? ") frnd.sal = raw_input("What should we call your friend? ") frnd.age = input("What is your friend age? ") frnd.rating = input("What is your friend rating? ") frnd.is_online = True if len( frnd.name ) > 2 and 12 < frnd.age < 50 and frnd.rating > spy.rating: #conditions for adding new friend with open('feiends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow([ frnd.name, frnd.salutation, frnd.rating, frnd.age, frnd.is_online ]) else: print "Friend cannot be added" return len(friends) #will return to add friend()
def add_friend(): frnd = Spy('', '', 0, 0.0) frnd.name = raw_input("Write your friend's name") frnd.sal = raw_input("Mr. or Ms.") frnd.name = frnd.sal + " " + frnd.name frnd.age = input("Enter Age") frnd.rating = input("Enter rating of your friend") frnd.online = True if len(frnd.name ) > 2 and 50 >= frnd.age >= 12 and frnd.rating >= spy.rating: friends.append(frnd) with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow([frnd.name, frnd.rating, frnd.age, frnd.online]) else: print("Friend with these values cannot be added ") return len(friends)
def add_friend(): frnd = Spy('', '', 0, 0.0) frnd.Name = raw_input("What is your name? ") frnd.sal = raw_input("What should we call you? ") frnd.Age = input("What is your age? ") frnd.Rating = raw_input("What is your Rating? ") frnd.is_online = True if len(frnd.Name) > 3 and 18 < frnd.Age < 50 and frnd.Rating > 3: with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow([ frnd.Name, spy.saluation, frnd.rating, frnd.age, frnd.is_online ]) else: print "Friend's Can't be added" return len(friends)