Ejemplo n.º 1
0
def addFriend():
    # new_friend['name']=raw_input("Enter your Friend's name.. ")
    # new_friend['salutation']=raw_input('are they Mr. or Ms.? ')
    # new_friend['age']=input('Age? ')
    # new_friend['rating']=input('Rating? ')

    newspy = Spy(raw_input("Please enter your friend's name:"), raw_input("Are they Mr. or Ms.?: "),
                 input("What's the age?"), input("What is their Spy rating?"))

    if newspy.salutation == 'Mr.' or newspy.salutation == 'mr.':
        newspy.salutation = 'Mr.'
    else:
        newspy.salutation = 'Ms.'

        newspy.name = newspy.salutation + newspy.name

    if len(newspy.name) > 0 and newspy.age > 12 and newspy.age < 50:
        friends.append(newspy)
        with open("friends.csv.txt", "a") as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([newspy.name, newspy.salutation, newspy.age, newspy.rating, True])
        print "Friend Added !!"
    else:
        print 'The crediantials don\'t match the profile of a spy'

    return len(friends)
Ejemplo n.º 2
0
def add_friend():
    # initially setting details of friend to zero
    new_friend = Spy('', '', 0.0, 0)
    # asking the user to enter name
    new_friend.name = raw_input('Please tell your friend name:')
    # asking the user to enter salutation
    new_friend.salutation = raw_input('What should we call you Mr. or Ms.:')
    # asking the user to enter rating and converting it to float
    new_friend.rating = float(raw_input('Please tell your friends rating:'))
    # asking the user to enter age and converting it to integer
    new_friend.age = int(raw_input('Please tell your friends age:'))
    # check the standards of rating
    spy_rating(new_friend.rating)
    # checking the salutation
    # checks if user has right age to proceed, valid name and rating greater than user
    if 12 < new_friend.age < 50 and name_validation(new_friend.name) and 5 >= new_friend.rating >= spy.rating and \
            valid_salutation(new_friend.salutation):
        # stripping off spaces before and after his name
        new_friend.name = new_friend.name.strip(" ")
        new_friend.salutation = new_friend.salutation.strip(" ")
        # appending the new friend to friends list
        friends.append(new_friend)
        print 'Friend added'
    else:
        print 'Sorry we can\'t enter spy with that invalid details or your age might be low'
    # returning the no. of friends to the calling function
    return len(friends)
Ejemplo n.º 3
0
def add_friend():

    new_friend = Spy('','',0,0.0)

    new_friend.name = raw_input("enter  your friend's name: ")
    new_friend.salutation = raw_input("are they (Mr. or Ms. or Mrs.)?: ")
    if (new_friend.salutation == 'Mr.'):
        print 'he is a male'
    elif(new_friend.salutation == 'Ms.') or (new_friend.salutation == 'Mrs. '):
        print'she is a female'
    else:
        print 'please enter a valid salutation'

        new_friend.salutation = raw_input("are they (Mr. or Ms. or Mrs.)?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = int(raw_input("Age? "))

    new_friend.rating = float(raw_input("Spy rating? "))

    if len(new_friend.name) > 0 and new_friend.age > 15 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)
Ejemplo n.º 4
0
def add_friend():  #Function to add a friend.

    new_friend = Spy('', '', 0, 0.0)  #Creating object for class 'Spy'

    name = raw_input("Enter friend's name: ")  #taking input.
    salutation = raw_input("Enter friend's salutation: ")
    new_friend.age = int(raw_input("Enter friend's age: "))
    new_friend.rating = float(raw_input("Enter friend's rating: "))
    count = 0
    for i in name:  #checking valid name or not.
        if name.isdigit() or name == "" or name.isspace(
        ):  #Checking for valid name input.:
            count = count + 1
    if count != 0:
        print "\nWARNING: Invalid name entented"
    count1 = 0
    for i in salutation:  #checking valid salutation or not.
        if salutation.isdigit() or salutation == "" or salutation.isspace(
        ):  #Checking for valid salutation input.
            count1 = count1 + 1
    if count1 != 0:
        print "\nWARNING: Invalid saluation entented"
    if count == 0 and count1 == 0:
        if old == 1:
            if name != "" and 12 < new_friend.age < 50 and new_friend.rating >= spy.rating and new_friend.rating <= 5 and salutation != "":
                new_friend.name = name
                new_friend.salutation = salutation
                friends.append(new_friend)
                print "New friend added."
            else:  #checking all corner cases.
                if new_friend.rating < 0 or new_friend.rating > 5:
                    print "Friend's rating entered is not eligible"
                elif new_friend.rating < spy.rating:
                    print "Friend's rating is less than the spy rating."
                elif new_friend.age <= 12 or new_friend.age >= 50:
                    print "Friend's age is not eligible."
                elif new_friend.salutation == "":
                    print "Friend's salutation cannot be left empty."
                elif new_friend.name == "":
                    print "Friend's name cannot be left empty."

        elif old == 0:  #if user selects for the new user, then we check the rating with the new user's rating with friend's rating.
            if name != " " and 12 < new_friend.age < 50 and new_friend.rating >= spy.rating and new_friend.rating <= 5 and salutation != "":
                new_friend.name = name
                new_friend.salutation = salutation
                friends.append(new_friend)
                print "New friend added."
            else:
                if new_friend.salutation == "":
                    print "Friend's salutation cannot be left empty."
                elif new_friend.age <= 12 or new_friend.age >= 50:
                    print "Friend's age is not eligible."
                elif new_friend.rating < new_spy.rating:
                    print "Friend's rating is less than the spy rating."
                elif new_friend.name == "":
                    print "Friend's name cannot be left empty."
    return len(friends)  #For number of friends.
Ejemplo n.º 5
0
def add_friend():
    # using class spy
    new_friend = Spy(" ", " ", 0, 0.0)

    # ask user for name and salutation of friend
    new_friend.name = raw_input("Please add your friend's name: ")
    pattern_n = '^[a-zA-Z\s]+s'

    new_friend.salutation= raw_input("What do we call you Mr. or Ms.?: ")
    pattern_s = '^[a-zA-Z\s]+s'

    # concatination for full name
    new_friend.name = new_friend.salutation + " " + new_friend.name

    # ask for age of friend, int represents type casting in int
    new_friend.age = int(raw_input("Age? "))
    pattern_a = '^[0-9]+$'

    #ask for rating of friend, float represents type casting in float
    new_friend.rating = float(raw_input("Spy rating? "))
    pattern_r = '^[0-9]+\.[0-9]+$'

    # users input validations
    if len(new_friend.name) > 0 and new_friend.name.isdigit() == False and re.match(pattern_n,new_friend.name)!=None and re.match(pattern_s,new_friend.salutation)!=None and new_friend.age > 12 and new_friend.rating < 50 and re.match(pattern_a,new_friend.age)!=None and new_friend.salutation.isalpha() ==  True and new_friend.rating >= 0 and re.match(pattern_r,new_friend.rating)!=None:

        # add friend if conditions satisfies
        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\n ', 'blue'))
    print (colored('Please enter the right data, don\'t make mistakes. ', 'blue'))

    # returning total no of friends.
    return len(friends)
Ejemplo n.º 6
0
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("What to call Mr. or Ms.?: ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = int(raw_input("Age? "))

    new_friend.rating = float(raw_input("Spy rating? "))

    if len(new_friend.name) > 0 and new_friend.name.isdigit(
    ) == False and re.match(pattern_n, new_friend.name) != None and re.match(
            pattern_s, new_friend.salutation
    ) != None and new_friend.age > 12 and new_friend.rating < 50 and re.match(
            pattern_a,
            new_friend.age) != None and new_friend.salutation.isalpha(
            ) == True and new_friend.rating >= 0 and re.match(
                pattern_r, new_friend.rating) != None:

        friends.append(new_friend)
        print(colored('Friend Added!', 'blue'))
    else:
        print(
            colored(
                'Sorry! Invalid entry. We can\'t add spy with the details you provided\n ',
                'blue'))
    print(colored('Please enter the right data, don\'t make mistakes.',
                  'blue'))

    return len(friends)
Ejemplo n.º 7
0
def add_friend():

    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("Please add your friend's name: ")
    if new_friend.name.isalpha(
    ) == True:  # isalpha() is function here used to check whether an entry from user is string or not.
        new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

        new_friend.name = new_friend.salutation + " " + new_friend.name

        new_friend.age = raw_input("What is their Age?")
        if new_friend.age.isdigit():
            new_friend.age = int(new_friend.age)

            new_friend.rating = raw_input("what is their Spy rating?")
            if new_friend.rating.isdigit():
                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'
            else:
                print "Rating is not feasible."
        else:
            print "Age must be of integer type. "
    else:
        print "please add a valid spy name!"
    return len(friends)
Ejemplo n.º 8
0
def add_friend():

    new_friend = Spy('', '', 0, 0.0)

    # Asking details of new friend
    new_friend.name = raw_input("Please add your friend's name: ")

    if (new_friend.name > 0):
        new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

        if (new_friend.salutation > 0):
            new_friend.name = new_friend.salutation + " " + new_friend.name
        else:
            print 'Provide proper salutation'

        new_friend.age = int(raw_input("Age?"))

        new_friend.rating = float(raw_input("Spy rating?"))

        if len(
                new_friend.name
        ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
            friends.append(new_friend)
            print '\n Friend Added!'
        else:
            print '\n Sorry! Invalid entry. We can\'t add spy with the details you provided'
    else:
        print '\n Provide proper name!!'

    # Returning length of friends list i.e  number of friends
    return len(friends)
def add_friend():
    #spy is a class for adding a friend
    new_friend = Spy('', '', 0, 0.0)

    #input your friends name please!!!!
    new_friend.name = raw_input(
        "Please enter your friend's name you would like to add in a spyChat: ")
    new_friend.salutation = raw_input("Are your friend Mr. or Ms.?: ")

    #printing friends name with salutation
    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Please enter your Age?")

    #converting string to integer as age is an integer, not a string
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Please enter your Spy rating?")

    #converting string to float as rating is an float, not a string
    new_friend.rating = float(new_friend.rating)

    #based on the below conditions if it meets, then friends will be added else not added
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print 'Congratulations!!!!! Friend Added successfully!'
    else:
        print 'Sorry for that! we can\'t add your friend due to invalid entry.'

#returning number of friends added
    return len(friends)
Ejemplo n.º 10
0
def add_friend():

    #add_friend function will add a new friend to the friends list.

    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("please add your 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('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 cant add spy with the detail you provided'

    return len(friends)
Ejemplo n.º 11
0
Archivo: main.py Proyecto: mudra19/spy
def add_friend():

    # class object new friend is initialised

    new_friend = Spy('', '', 0, 0.0)
    #get details of friend and save them in class variables

    new_friend.name = raw_input("please add your friend's name: ")

    new_friend.salutation = raw_input('Mr or Ms? :')

    new_friend.name = new_friend.salutation + ' ' + new_friend.name

    new_friend.age = int(raw_input('Age?:'))

    new_friend.rating = float(raw_input('Rating of spy?:'))

    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 we can\'t add spy with the details you provided'

    return len(friends)
Ejemplo n.º 12
0
def add_friend():
    #Initializing The Variable new_friend
    new_friend = Spy('', '', 0, 0.0)
    #Getting Name Of the Friend
    new_friend.name = raw_input("Please add your friend's name: ")
    #Getting Salutation Of the Friend
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")
    #Concatinating Salutation And Name
    new_friend.name = new_friend.salutation + " " + new_friend.name
    #Getting Age
    new_friend.age = raw_input("Age?")
    #Converting Age To Integer
    new_friend.age = int(new_friend.age)
    #Getting Rating
    new_friend.rating = raw_input("Spy rating?")
    #Converting Rating To FloatingPoint
    new_friend.rating = float(new_friend.rating)
    #If Friend's Name is Not Empty ,Age is above 12 and friend's rating is above or equals to spy's rating
    if len(
            new_friend.name
    ) > 0 and new_friend.age > 12 and new_friend.age < 50:  #new_friend.rating >= spy.rating:
        friends.append(new_friend)  #Add Friend to The Friends List
        print 'Friend Added!'
    else:  #If The Required Conditions are not Met
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'

    return len(friends)  #Return The Length of the friends list
Ejemplo n.º 13
0
def add_friend():
    new_friend = Spy("", "", 0, 0)

    new_friend.name = raw_input("Enter your friend's name :\n")

    new_friend.salutation = raw_input("Is your friend Mr. or Ms. :\n")

    new_friend.age = int(raw_input("Enter your friend's age :\n"))

    new_friend.rating = float(raw_input("Enter your friend's rating :\n"))

    # Checking eligibility of new friend
    # The criteria that his spy_rating should be greater than mine seems to be a bit wonky :-(
    if len(
            new_friend.name
    ) > 0 and 12 < new_friend.age < 50 and spy.rating <= new_friend.rating <= 5.0:

        # Adding a new friend to my friends list
        friends.append(new_friend)

        print new_friend.salutation + " " + new_friend.name + " is now your friend"

    else:

        print "This spy is not eligible to be your friend!"

    # Returning the no of friends
    return len(friends)
Ejemplo n.º 14
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)

    # Raw input allows to take input from user and new_friend.name is a variable where variable is stored.
    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

    # Variable has been updated
    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)

    # spy friend should meet the requirements for which we apply condition using IF keyword
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:

        # .append adds friend to new_friend
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        # \ is used before 't which is used for escaping character
        # Another better way of doing this is "Sorry! Invalid entry. We can\'t add spy with the details you provided"

        print 'Sorry! Invalid entry. We can\'t add spy with the details you just provided. .'
    return len(friends)
Ejemplo n.º 15
0
def add_friend():
    # new dictonary for every new friend addded
    new_friend = Spy('', '', 0, 0.0)

    # friends Info
    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 = int(raw_input(new_friend.name + "\'s Age? "))
    new_friend.rating = float(raw_input(new_friend.name +
                                        "\'s Smart rating? "))

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= 1:
        try:
            with open("friends_data.csv", 'ab') as friends_data:
                write = csv.writer(friends_data)
                write.writerow([
                    new_friend.name, new_friend.salutation, new_friend.age,
                    new_friend.rating
                ])
        except:
            print 'File not available'
        friends.append(new_friend)
        print '\nNew Friend Name " %s " Age " %d " of Rating " %.2f " Added into Friend List.' % (
            new_friend.name, new_friend.age, new_friend.rating)

    else:
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'

    # return length of frineds list
    return len(friends)
Ejemplo n.º 16
0
def add_friend():
    #create a list to hold friend names,friend ages and friend rating
    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.name = new_friend.salutation + " " + new_friend.name
    #ask the user age
    new_friend.age = raw_input("Age?")
    new_friend.age = int(new_friend.age)
    #ask the user_rating
    new_friend.rating = raw_input("Spy rating?")
    new_friend.rating = float(new_friend.rating)
    #check condition if name is not empty ,age is gretaer than 12 and rating of the friend spy is greater than or equal to the user spy rating
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        #print the appropiate message
        print 'Friend Added!'
    else:
        print 'Sorry! Invalid rating entry. We can\'t add spy with the details you provided'

#return no of friends the user has
    return len(friends)
Ejemplo n.º 17
0
def add_friend():

    new_friend = Spy('','',0,0.0)
    new_friend.name = raw_input("Please add your friend's name: ")

#Handling edge case scenarios.
    if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend.name):
        print "Invalid entry. "
        new_friend.name = raw_input("Please re enter a valid name")
    else:
        print new_friend.name

    new_friend.salutation = raw_input("How would you like to address them? ")
    new_friend.name = new_friend.salutation + " " + new_friend.name
    new_friend.age = raw_input("How old is your friend?")
    new_friend.age = int(new_friend.age)
    new_friend.rating = raw_input("And their rating too please?")
    new_friend.rating = float(new_friend.rating)

#Mandatory conditions to be satisfied for adding a friend.
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
        print "Congratulations! You have a new friend."
    else:
        print "Uh huh! Your friend is not good enough. Try again with different details."

    return len(friends)
Ejemplo n.º 18
0
def add_friend():
    #Function defined to add spy's friends alongwith the details of them
    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("Enter your friend's name Spy: ")
    if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend.name):
        print "Invalid entry. Please Enter a valid name of single word without special characters"
        new_friend.name = raw_input("Enter your friend's name Spy: ")
    else:
        print "Thats a valid friend name"

    new_friend.salutation = raw_input("MR or MS : ")

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("How old is your mate?")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("How amazing are they?")
    new_friend.rating = float(new_friend.rating)

    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.rating >= 3.5:

        friends.append(new_friend)
        print 'You have a new Friend <3!'
    else:
        print 'Sorry! This friend isn\'t worth you. We can\'t add spy with the details you gave'

    return len(friends)
Ejemplo n.º 19
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    new_friend.name = raw_input("Please add your friend's name: \n")

    if set('[special symbols":;\']+$ " "').intersection(new_friend):
        print "Invalid entry."
    else:
        print new_friend

    new_friend.salutation = raw_input(
        "Formal Salutation: Mr. or Ms. or Mrs. \n")
    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Age?\n")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Spy rating?\n")
    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 'New Friend Added!\n'
    else:
        print "Sorry! Invalid entry. We can\'t add spy with the details you provided!!\n"

    return len(friends)
Ejemplo n.º 20
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    #friend name,salutation age and rating is added to data
    new_friend.name = raw_input("Please add your friend's name: ")
    if set('[~!@#$%^&*()+{}":;\']" "').intersection(new_friend.name):
        print "Invalid entry. Please enter a Valid Name!"
        new_friend.name = raw_input("enter your friend's name=")
        if set('[~!@#$%^&*()+{}":;\']" "').intersection(new_friend.name):
            print "Invalid name! Please try again."
            exit()
    else:
        print "That's a valid friend 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 of your friend ?")
    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!. We can't add spy with the details you provided"

    return len(friends)
Ejemplo n.º 21
0
def add_friend():
    new_friend = Spy("", "", 0, 0.0)

    new_friend.name = raw_input("Whats the name of your friend?")
    if len(new_friend.name) > 0 and new_friend.name.isspace() == False:
        new_friend.salutation = raw_input(
            "What should we call your friend: Mr. or Ms.?")
        if new_friend.salutation == "Mr." or new_friend.salutation == "Ms.":
            new_friend.name = new_friend.salutation + " " + new_friend.name
            new_friend.age = raw_input("Whats the age?")
            new_friend.age = int(new_friend.age)
            new_friend.rating = raw_input("Whats the rating?")
            new_friend.rating = float(new_friend.rating)
            if new_friend.age > 12 and new_friend.rating > 3.5:
                friends.append(new_friend)
                print "New friend added!!"
            else:
                print "Sorry! Can't add the friend with the information provided!!"

        else:
            print "Enter Mr. or Ms."

    else:
        print "Enter valid name!!"

    return len(friends)
Ejemplo n.º 22
0
def add_friend():

    new_friend = Spy(" ", " ", 0, 0.0)

    new_friend.name = raw_input("Please add your friend's name?")

    # here len()>0 func checks that user should not press enter without giving any name
    # isspace() func does not allow the user to enter blank spaces in place of name
    if len(new_friend.name) > 0 and new_friend.name.isspace() == False:
        new_friend.salutation = raw_input("Are they Mr. or Ms.?")

        # to check that user does not enter anything else except Mr. or Ms.
        if new_friend.salutation == "Mr." or new_friend.salutation == "Ms.":

            new_friend.name = new_friend.salutation + " " + new_friend.name
            new_friend.age = int(raw_input("Age?"))
            new_friend.rating = float(raw_input("Spy rating?"))

            if new_friend.age > 12 and new_friend.rating >= spy.rating:
                friends.append(new_friend)  #adding new friends to old list
                print "New friend added!"

            else:
                print "Sorry! We can't add a spy with the details you provided.Please enter valid age or valid rating.."
        else:
            print "Please enter valid option.Choose either Mr. or Ms."
    else:
        print "Please enter valid spy name!!"

    return len(friends)  # returns no of friends in friends list
Ejemplo n.º 23
0
def add_friend():
    # The function should ask the user for the name, age and rating of their spy friend
    new_friend = Spy('','',0,0.0)

    # The function converts the data as appropriate
    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)

    # The function should add the friend to various lists only if name is not empty, age is greater than 12 and rating of the friend spy is greater than or equal to the user spy 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!'
    # If any of the above conditions are not met it displays an appropirate message
    else:
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'
    # The function should return and print the number of friends the user has
    return len(friends)
Ejemplo n.º 24
0
def add_spy_friend():

    # Spy is a class
    new_spy_friend = Spy('', '', 0, 0.0)

    new_spy_friend.name = raw_input(
        colored("Please add your friend's name:", 'red'))
    new_spy_friend.salutation = raw_input(
        colored("Are they Mr. or Ms.?: ", 'red'))

    new_spy_friend.age = raw_input(colored("Age?", 'red'))
    new_spy_friend.age = int(new_spy_friend.age)

    new_spy_friend.rating = raw_input(colored("Spy rating?", 'red'))
    new_spy_friend.rating = float(new_spy_friend.rating)

    if len(
            new_spy_friend.name
    ) > 0 and new_spy_friend.age > 12 and new_spy_friend.rating >= spy.rating:
        friends.append(new_spy_friend)
        print colored('Friend Added', 'red')
        total_spy_friend()
    else:
        print colored(
            'Sorry! Invalid entry. We can\'t add spy with the details you provided',
            'red')

    return len(friends)
Ejemplo n.º 25
0
def add_friend():
    # Using the class spy
    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.?: ")

    # ask for the age of the friend
    new_friend.age = raw_input("Age?: ")
    # Type casting to integer
    new_friend.age = int(new_friend.age)

    # Ask for the rating of the friend
    new_friend.rating = raw_input("Spy rating?: ")
    # Type casting to float
    new_friend.rating = float(new_friend.rating)

    # Add a friend of correct age and equal or higher rating
    # Valid name of strings must be entered
    if len(new_friend.name) > 0 and new_friend.name.isdigit() == False and 12 < new_friend.age < 50 and new_friend.salutation.isalpha() == True and  new_friend.rating >= spy.rating :

        # After the conditions are satisfied the friend will be added
        friends.append(new_friend)
        print(colored('Friend Added!', "cyan"))
    else:
        print(colored("Sorry, the friend cannot be a spy!", "blue"))

    # The no of friends the spy has will be returned.
    return len(friends)
Ejemplo n.º 26
0
def add_friend():


    new_friend = Spy('','',0,0.0)

    new_friend.name = raw_input("Please add your friend's name: ")
    try:
        assert any([char not in string.ascii_letters for char in new_friend.name]) is False

        print "valid name"
        new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")

        new_friend.name = new_friend.salutation + " " + new_friend.name

        new_friend.age = int(raw_input("Age?"))


        new_friend.rating = float(raw_input("Spy rating?"))


        if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= 4:
            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)

    except AssertionError:
        print "invalid name"
Ejemplo n.º 27
0
def add_freind():

    new_friend = Spy("", 0, 0.0, True)
    new_friend.name = raw_input("What is the name of friend ? ")
    new_friend.salutation = raw_input(
        "What should we call you ? (Mr. or Ms.) ")
    new_friend.name = new_friend.salutation + " " + new_friend.name
    new_friend.age = input("What is the age of friend ? ")
    new_friend.rating = input("What is your rating ? ")

    if len(new_friend.name
           ) >= 3 and 50 >= new_friend.age and new_friend.rating >= spy.rating:

        friends.append(new_friend)
        print "friend is added"
        with open('friends.csv', 'a') as friends_data:
            writer = csv.writer(friends_data)
            writer.writerow([
                new_friend.name, new_friend.age, new_friend.rating,
                new_friend.is_online
            ])

    else:
        print "Freind cannot be added"
    return len(friends)
Ejemplo n.º 28
0
def add_friend():
    # using class spy
    new_friend = Spy(" ", " ", 0, 0.0)

    # ask user for name and salutation of friend
    new_friend.name = raw_input("Please add your friend's name: ")
    new_friend.salutation= raw_input("What to call Mr. or Ms.?: ")
    new_friend.name = new_friend.salutation + " " + new_friend.name
    new_friend.age = int(raw_input("Age? "))
    new_friend.rating = float(raw_input("Spy rating? "))
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.age < 50 and new_friend.age :


        # add friend if conditions satisfies
        friends.append(new_friend)
        with open('friends.csv', 'wb') as friends_data:
           writer = csv.writer(friends_data)
           writer.writerow([new_friend.name, new_friend.salutation, new_friend.rating, new_friend.age, new_friend.is_online])

        print (colored('Friend Added!', 'magenta'))
    else:
        print (colored('Sorry! Invalid entry. We can\'t add spy with the details you provided\n ', 'blue'))
        print (colored('The convention to follow is: \n ', 'blue'))
        print (colored('1. Name can be alphabets only.\n ', 'blue'))
        print (colored('2. Age can be digits only.\n ', 'blue'))

    # returning total no of friends.
    return len(friends)
Ejemplo n.º 29
0
def add_friend():

    new_friend = Spy('', '', 0, 0.0, '')

    new_friend.name = raw_input(
        "Let\'s add your friend. Enter your friends name:")
    new_friend.salutation = raw_input(
        'What would you like us to call him/her? Mr. or Ms.?:')

    new_friend.name = new_friend.salutation + " " + new_friend.name

    new_friend.age = raw_input("Enter Age")
    new_friend.age = int(new_friend.age)

    new_friend.rating = raw_input("Enter 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 colored('Congratulation! Your friend has been added!', 'blue',
                      'on_grey')
    else:
        print colored('OOPS! Unable to add spy with the details you provided',
                      'red', 'on_white')

    return len(friends)
Ejemplo n.º 30
0
def add_friend():
    # using class user
    new_friend = Spy(" ", " ", 0, 0.0)

    # ask user for name
    new_friend.name = raw_input("Please add your friend's name: ")

    # user name validation.
    if len(new_friend.name) > 0:
        if len(new_friend.name) > 20:
            print("Your name length is big.")
    else:
        print("Name should be not empty or length is less then 20 char.")
        return add_friend()

    new_friend.salutation = raw_input("What to call Mr. or Ms.?: ")

    # user salutation validation
    if len(new_friend.salutation) > 0:
        if len(new_friend.salutation) > 5:
            print("Your salutation is too big.")
    else:
        print("Salutation empty or check length")
        return add_friend()

    # concatination for full name
    new_friend.name = new_friend.salutation + " " + new_friend.name

    # ask for age of the friend
    new_friend.age = int(raw_input("Age: "))

    if 12 < new_friend.age < 50:
        True
    else:
        print colored("Age should be in between 12 to 50", "red")
        return add_friend()

    #ask for rating of friend, using float
    new_friend.rating = float(raw_input("Spy rating? "))

    if new_friend.rating > 0.0:
        True
    else:
        print("Rating should be more than 0.0")
        return add_friend()

    # add friend if all conditions check
    friends.append(new_friend)
    print('Friend Added!')
    with open("friends.csv", "a") as friends_data:
        writer = csv.writer(friends_data)
        writer.writerow([
            new_friend.name, new_friend.salutation, new_friend.age,
            new_friend.rating, new_friend.is_online
        ])

    #total no of friends
    return len(friends)
Ejemplo n.º 31
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)
    new_friend.name = raw_input("please add your friends name : ")
    new_friend.salutation = raw_input("are they mr or miss : ")
    new_friend.age = int(raw_input("age: "))
    new_friend.rating = float(raw_input("rating: "))
    if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
        friends.append(new_friend)
    else:
        print("sorry! invalid entry. we can't add a spy with the details you provided. please try again later. ")
    return len(friends)