Example #1
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '.',
        'age': 0,
        'rating': 0.0,
        'is_online': False
    }
    new_friend['name'] = raw_input("Please add your friend's name: ")
    new_friend['salutation'] = raw_input("Are they Mr. or Ms.?: ")

    # concatination.
    new_friend['name'] = new_friend['salutation'] + " " + new_friend['name']

    new_friend['age'] = int(raw_input("Age? "))

    new_friend['rating'] = float(raw_input("Spy rating? "))

    # users input validations
    if len(new_friend['name']
           ) > 0 and new_friend['age'] > 12 and new_friend['age'] < 50:
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'

    # returning total no of friends.
    return len(friends)
Example #2
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '',
        'age': 0,
        'rating': 0.0,
        'is_online': False
    }

    new.name = raw_input("please add your friend's name: ")
    new.salutation = raw_input("are they Mr. or Ms.? ")
    #concatenation
    new_friend.name = new_friend.salutation + " " + new_friend.name

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

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

    #user input validations
    if len(new_friend.name
           ) > 0 and new_friend.age > 12 and new_friend.age < 50:
        new_friend.is_online = True
        friends.append(new_friend)
        print colored('Friend added!')
    else:
        print 'Sorry,invalid entery'

        #returing total no. of friends
    return len(friends)
Example #3
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '.',
        'age': 0,
        'rating': 0.0,
        'is_online': False
    }
    new_friend['name'] = raw_input(" Please add your friend's name: ")
    new_friend['salutation'] = raw_input(" Are they Mr. , Miss or Mrs.?: ")

    # concatination.
    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['age'] < 50:
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        print ' Sorry..! Invalid entry. Spy can\'t be added with invalid details'

        return len(friends)
Example #4
0
def add_friend():
    new_friend_name = {
        'name': '',
        'salutation': '',
        'age': 0,
        'rating': 0.0,
        'is online': False
    }
    new_friend_name['name'] = raw_input("Please add your friend's")
    new_friend_name['salutation'] = raw_input("Is he/she ")

    new_friend_name[
        'name'] = new_friend_name['salutation'] + " " + new_friend_name['name']

    new_friend_name['age'] = int(raw_input("Age .? "))
    new_friend_name['rating'] = float(raw_input("rating is..?? "))

    if len(
            new_friend_name['name']
    ) > 0 and new_friend_name['age'] > 12 and new_friend_name['age'] < 55:
        new_friend_name['is online'] = True
        friends.append(new_friend_name)
        print "Friend is added..!!"
    else:
        print "user has not inserted any value"
    return len(friends)
Example #5
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '',
        'age': 0,
        'rating': 0.0,
        'is_online': False,
        'chats': []
    }
    # Adding new friend
    # Verification done using regex
    new_friend['name'] = raw_input(
        colored("Enter your Friend's Name\n", "yellow"))
    while new_friend['name'].isalpha() == False:
        cprint("Name can't be empty and only contains alphabets", "red")
        new_friend['name'] = raw_input(
            colored("Enter your Friend's Name\n", "yellow"))
    new_friend['salutation'] = raw_input(
        colored("Enter your Friend's Salutation\n", "yellow"))
    while new_friend['salutation'].isalpha() == False:
        cprint("Salutation can't be empty and only contains alphabets", "red")
        new_friend['salutation'] = raw_input(
            colored("Enter your Friend's Salutation\n", "yellow"))
    new_friend['name'] = new_friend['name'] + " " + new_friend['salutation']
    new_friend['name'] = colored(new_friend['name'], "magenta", attrs=['bold'])
    while True:
        try:
            new_friend['age'] = int(
                raw_input(colored("Enter his Age\n", "yellow")))
            age_pattern = '^[0-9]{1,3}$'
            if re.match(age_pattern, str(new_friend['age'])) != None:
                if new_friend['age'] >= 18 and new_friend['age'] <= 50:
                    break
                else:
                    cprint("Age must be b/w (18-50) Sorry -_-",
                           "grey",
                           attrs=['bold'])
            else:
                cprint("Age cant be more then 3 digits", "red")

        except ValueError:
            cprint("Please enter correct age ", "red")
    while True:

        try:
            new_friend['rating'] = float(
                raw_input(colored("Enter his Rating B/W (0-5)\n", "yellow")))

            if new_friend['rating'] <= 5.0:
                break

            else:
                cprint("Rating must be b/w 0 -5 ", "red")
        except ValueError:
            cprint("rating must be in number", 'red')

    new_friend['is_online'] = True
    friends.append(new_friend)
    return len(friends)
Example #6
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '.',
        'age': 0,
        'rating': 0.0,
        'is_online': False
    }

    wholecheck = True
    while (wholecheck):
        tempcheck = True
        patternsalutation = '^Mr|Ms$'
        patternname = '^[A-Za-z][A-Za-z\s]+$'
        patternage = '^[0-9]+$'
        patternrating = '^[0-9]+\.[0-9]$'
        while tempcheck:
            new_friend['name'] = raw_input("Please add your friend's name: ")
            if (re.match(patternname, new_friend['name']) != None):
                tempcheck = False
            else:
                print colored("invalid name , try again", 'red')
        tempcheck = True
        while tempcheck:
            new_friend['salutation'] = raw_input("Are they Mr. or Ms.?: ")
            if (re.match(patternsalutation, new_friend['salutation']) != None):
                tempcheck = False
            else:
                print colored("invalid salutation , try again", 'red')
            new_friend[
                'name'] = new_friend['salutation'] + " " + new_friend['name']
        tempcheck = True
        while tempcheck:
            new_friend['age'] = raw_input("Age? ")
            if (re.match(patternage, new_friend['age']) != None):

                tempcheck = False
            else:
                print colored("invalid age , try again", 'red')
        tempcheck = True
        while tempcheck:
            new_friend['rating'] = raw_input("Spy rating? ")
            if (re.match(patternrating, new_friend['rating']) != None):
                tempcheck = False
                wholecheck = False
            else:
                print colored("invalid rating , try again", 'red')
                # users input validations

    if (len(new_friend['name']) > 0):
        friends.append(new_friend)
        print colored('Friend Added!', 'green')
    else:
        print colored(
            'Sorry! Invalid entry. We can\'t add spy with the details you provided',
            'red')
        # returning total no of friends.
        return len(friends)
Example #7
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '.',
        'age': 0,
        'rating': 0.0,
        'is_online': False
    }

    repeatcheck = True # it can be used as Temporary variable
    # Defining use of RE
    tempcheck = True
    patternsalutation = '^Mr|Ms$'
    patternname = '^[A-Za-z][A-Za-z\s]+$'
    patternage = '^[0-9]+$'
    patternrating = '^[0-9]+\.[0-9]$'
            # Validating Each Values Using Regular Expression
    while tempcheck:
        new_friend['salutation'] = raw_input(" Are you  Mr. or Ms.? : ")
        if (re.match(patternsalutation, new_friend['salutation']) != None):
            tempcheck = False
        else:
            print colored("Wrong entry.Enter Again!", 'red')
            new_friend['name'] = new_friend['salutation'] + "." + new_friend['name']   # concatenation.
        tempcheck = True
    while tempcheck:

        new_friend['name'] = raw_input("Please add your friend's name: ")
        if (re.match(patternname, new_friend['name']) != None):
            tempcheck = False
        else:
            print(colored("Wrong entry.Enter Again!", 'red'))
    while tempcheck:
        new_friend['age'] = raw_input("What is your Age?:")
        if (re.match(patternage, new_friend['age']) != None):
            tempcheck = False
        else:
            print(colored("Wrong entry.Enter Again!", 'red'))
    tempcheck = True  # temporary variable
    while tempcheck:
        new_friend['rating'] = raw_input("What is your Spy rating?")
        if (re.match(patternrating, new_friend['rating']) != None):
            tempcheck = False
            repeatcheck = False
        else:
            print colored("Wrong choice.Enter Again!", 'red')
                 # users input validations
            if len(new_friend['name']) > 0 and new_friend['age'] > 12 and new_friend['age'] < 50:
                friends.append(new_friend)
                print ('Friend Added!','green')    # Success msg
            else:
                print colored ('Sorry! Invalid entry. We can\'t add spy with the details you provided','red') # Error msg

        # returning total no of friends.
            return len(friends)
Example #8
0
def add_friend():
    new_friend = Spy(" ", " ", 0, 0.0, False)
    temp_check = True
    #temporary variable
    #Validation Using regular expressions
    patternsalutation = '^Mr|Ms$'
    patternname = '^[A-Za-z][A-Za-z\s]+$'
    patternage = '^[0-9]+$'
    patternrating = '^[0-9]+\.[0-9]$'
    #Validating Each Values Using Regular Expression
    while temp_check:
        salutation = raw_input("Mr. or Ms.? : ")
        if (re.match(patternsalutation, salutation) != None):
            temp_check = False
        else:
            print colored("Enter Again!!!!", 'red')
    temp_check = True
    while temp_check:
        new_friend.Name = raw_input("Enter Name: ")
        if (re.match(patternname, new_friend.Name) != None):
            temp_check = False
        else:
            print colored("Enter Again!!!!", 'red')

    # concatenation.
    new_friend.Name = salutation + "." + new_friend.Name
    temp_check = True
    while temp_check:
        new_friend.Age = raw_input("Age?")
        if (re.match(patternage, new_friend.Age) != None):
            temp_check = False
            new_friend.Age = int(new_friend.Age)
        else:
            print colored("Enter Again!!!!", 'red')
    temp_check = True
    #temporary variable
    while temp_check:
        new_friend.Rating = raw_input("Spy rating?")
        if (re.match(patternrating, new_friend.Rating) != None):
            temp_check = False
            new_friend.Rating = float(new_friend.Rating)
        else:
            print colored("Enter Again!!!!", 'red')
    # validating input->AGE and RATING,i.e.,
    #Age b/w 12 and 50
    #Rating b/w 0.0 to 5.0
    #Rating of friend must be greater than or equal to User Rating
    if new_friend.Rating <= 5.0 and new_friend.Age > 12 and new_friend.Age < 50 and new_friend.Rating >= spy.Rating:
        # add_friend
        friends.append(new_friend)
        print colored("Friend Added", 'green')
    else:
        print colored("Sorry invalid entry!!!!", 'red')
    # returning number of friends
    return len(friends)
def add_friend():
    # Using the class spy
    new_friend = Spy(" ", " ", 0, 0.0)
    while True:
        new_friend.name = raw_input("Please add your friend's name:- ")
        if len(new_friend.name) > 0:
            while True:
                new_friend.salutation = raw_input("Are they Mr. or Ms. ?:- ")
                if len(new_friend.salutation) > 0:
                    if (new_friend.salutation == 'ms.'
                            or new_friend.salutation == 'Ms.'
                            or new_friend.salutation == "Mr."
                            or new_friend.salutation == "mr."):
                        # ask for the age of the friend
                        while True:
                            new_friend.age = raw_input("Age?:- ")

                            # Type casting to integer
                            if len(new_friend.age) > 0:
                                new_friend.age = int(new_friend.age)
                                if 18 < new_friend.age < 50:
                                    # After the conditions are satisfied the friend will be added
                                    friends.append(new_friend)
                                    print(colored('FRIEND ADDED!', "magenta"))

                                else:
                                    print(
                                        colored(
                                            "Sorry but your age is not valid for spy!",
                                            'red'))
                                    print(
                                        colored("       THANK YOU!       ",
                                                'yellow'))
                                    exit()
                                return len(friends)
                                #application will terminate
                                # The no of friends the spy has will be returned.
                                # The no of friends the spy has will be returned.
                            else:
                                print(
                                    colored("Sorry but age cannot be blank!",
                                            'red'))

                        # The no of friends the spy has will be returned.
                    else:
                        print(colored('Please enter valid salutation!', 'red'))
                else:
                    print(colored('Salutation cannot be blank!', 'red'))
        else:
            print(colored('Name cannot be blank!', 'red'))
            return len(friends)
Example #10
0
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '.',
        'age': 0,
        'rating': 0.0,
        'is_online': False,
        'chats': []
    }
    temp_variable = True
    while temp_variable:
        pattern = '^[a-zA-Z\s][a-zA-Z\s]*$'
        new_friend['name'] = raw_input("Please add your friend's name: ")
        if (re.match(pattern, new_friend['name'])):
            temp_variable = False
            print "Please provide some more information of yours."
        else:
            print "Please input only alphabetical characters."
    temp_variable = True
    while temp_variable:
        new_friend['salutation'] = raw_input("Are they Mr. or Ms.?: ")
        pattern = '^ms|mr|MR|MS|Mr|Ms'
        if (re.match(pattern, new_friend['salutation'])):
            new_friend[
                'name'] = new_friend['salutation'] + " " + new_friend['name']
            temp_variable = False
        else:
            print "Ooopssss! Find your gender.."
    while True:
        try:
            new_friend['age'] = int(raw_input(
                "Age? "))  # converting users input to integer (typecasting)
            break
        except ValueError:
            print "Stupid idiot! write a numeric value"

    new_friend['rating'] = float(raw_input("Spy rating? "))

    # users input validations
    if len(new_friend['name']) > 0 and new_friend['age'] > 12 and new_friend[
            'age'] < 50 and new_friend['rating'] > spy.rating:
        friends.append(new_friend)
        print 'Friend Added!'
    else:
        print 'Sorry! Something went wrong. We can\'t add spy with the details you provided'

    # returning total no of friends.
    return len(friends)
Example #11
0
def add_friend():
    # Adding a new friend
    new_friend = Spy('', '', 0, 0)
    new_friend.name = raw_input("Add your friend : Name : ")
    new_friend.salutation = raw_input("Are they Mr. 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>12 and new_friend.rating>=spy.rating:
        friends.append(new_friend)
        print "Friend Added \n"

    else:
        print "Sorry!! invalid entry "

    return len(friends)


    
Example #12
0
def add_friend():
    newfriend = {
        "name": "",
        "salutation": "",
        "age": 0,
        "rating": 0.0,
        "status": False
    }
    tempcheck = True  # temporary variable
    # Validation Using Regex
    patternsalutation = '^Mr|Ms$'
    patternname = '^[A-Za-z][A-Za-z\s]+$'
    patternage = '^[0-9]+$'
    patternrating = '^[0-9]+\.[0-9]$'
    # Validating Each Values Using Regular Expression
    while tempcheck:
        newfriend["salutation"] = raw_input(
            "What should we call them (Mr./Mrs.): ")
        if (re.match(patternsalutation, newfriend["salutation"]) != None):
            tempcheck = False
        else:
            print colored("Enter Again!!!!", 'red')

    tempcheck = True
    while tempcheck:
        newfriend["name"] = raw_input("Pleae add your friend\s name: ")
        if (re.match(patternname, newfriend["name"]) != None):
            tempcheck = False
        else:
            print colored("Enter Again!!!!", 'red')

    newfriend['name'] = newfriend['salutation'] + "" + newfriend['name']

    tempcheck = True
    while tempcheck:
        newfriend['age'] = (raw_input("Age? "))
        if (re.match(patternage, newfriend['age']) != None):
            tempcheck = False
            newfriend['age'] = int(raw_input("Age? "))
        else:
            print colored("Enter Again!!!!", 'red')

    tempcheck = True  # temporary variable
    while tempcheck:
        newfriend['rating'] = (raw_input("Rating? "))
        if (re.match(patternrating, newfriend['rating']) != None):
            tempcheck = False
            newfriend['rating'] = float(raw_input("Rating? "))
        else:
            print colored("Enter Again!!!!", 'red')

    # validation

    if len(newfriend["name"]) > 0 and newfriend["age"] > 12 and newfriend[
            "age"] < 50 and newfriend["rating"] >= Spy["rating"]:
        friends.append(newfriend)
        print colored("Friend added! ", 'green')

    else:
        print colored("Sorry invalid entry.Can\'t add a spy", 'red')

    # returning number of friends
    return len(friends)
def add_friend():
    new_friend = {
        'name': '',
        'salutation': '',
        'age': 0,
        'rating': 0.0,
        'is_online': False,
        'chats': []
    }


    while True:
        new_friend['name'] = raw_input("Please add your friend's name: ")
        #regex for valid friends name
        pattern = '^[a-zA-Z\s]+$'
        if (re.match(pattern, new_friend['name']) != None):
            print 'Valid name'
            break
        else:
            print "Invalid name. Try alphabet's only."

    # check whether spy has input something or not
    if len(new_friend['name']) > 0:
        new_friend['salutation'] = raw_input("What should we call you ? : ")
    #using regex for age as number only
        new_friend['age'] = raw_input("Enter your age: ")
        # validate age
        age_pattern = '^[0-9]{1,3}$'  # only maximum 3 digit numerical value is allowed.
        if (re.match(age_pattern, new_friend['age']) != None):
            # valid age
            new_friend['age'] = int(new_friend['age'])
            if (new_friend['age'] > 12 and new_friend['age'] < 50):
                # input spy rating.
                new_friend['rating'] = raw_input("What is your spy rating (Max 10.0): ")
                # validate spy rating
                rating_pattern = '^[0-9]{1,2}[.][0-9]{1}$'
                if (re.match(rating_pattern, new_friend['rating']) != None):
                    # valid rating i.e
                    new_friend['rating'] = float(new_friend['rating'])
                    if (new_friend['rating'] >= spy['rating'] and new_friend['rating'] <= 10.0):
                        new_friend['is_online'] = True
                        # concatination of salutation and name of spy.
                        new_friend['name'] = new_friend['salutation'] + " " + new_friend['name']
                        new_friend['is_online'] = True
                        friends.append(new_friend)
                        cprint('Friend Added!', 'grey', attrs=['bold'])
                        # returning total no of friends.
                        return len(friends)
                    else:
                        cprint ("friend rating must be greater than user rating",'red')
                        add_friend()
                else:
                    cprint ("Invalid rating. Try again with correct details.",'red')
                    add_friend()
            else:
                cprint ("Age must be between 12 to 50 years",'red')
                add_friend()
        else:
            cprint ("Invalid age. Try again with correct details.",'red')
            add_friend()
    else:
        cprint ("Invalid name. Try again with correct details.",red)
        add_friend()