コード例 #1
0
ファイル: Main.py プロジェクト: JagdeepThakur/SpyChat
def add_friend():

    sys.stdout.write(Fore.YELLOW + " ")

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

    # Asking the user for input until they give a valid response

    while True:

        new_friend.spy_name = str(
            raw_input("\nPlease add your friend's name: "))

        J5 = r"([a-zA-Z]+)"

        if re.search(J5, new_friend.spy_name):

            # i am happy with the value given
            # exiting loop
            break

        else:

            print "\nPlease Enter a valid value..!!"
            continue

    # Asking the user for input until they give a valid response

    while True:

        new_friend.spy_salutation = raw_input(
            "\nShould i call you Mr. or Ms.?: ")

        J6 = r"([Mm]r)"
        J7 = r"([Mm]s)"

        if re.search(J6, new_friend.spy_salutation) or re.search(
                J7, new_friend.spy_salutation):

            # i am happy with the vale given
            # exiting loop
            break

        else:

            print "\nPlease enter a valid value.."
            continue

    # Asking the user for input until they give a valid response

    while True:

        try:

            new_friend.spy_age = int(raw_input("\nEnter age: "))

        except ValueError:
            print "\nSorry, i didn't understand that."
            continue

        if new_friend.spy_age < 0:
            print("\nSorry, your response must not be negative")
            continue

        else:
            # i am happy with the value
            # exiting loop
            break

    # Asking the user for input until they give a valid response

    while True:

        try:

            new_friend.spy_rating = float(raw_input("\nEnter rating: "))

        except ValueError:

            print "\nSorry, i didn't understand that."
            continue

        if new_friend.spy_rating < 0:

            print("\nSorry, your response must not be negative")
            continue

        else:
            # i am happy with the value
            # exiting loop
            break

    if len(
            new_friend.spy_name
    ) > 0 and new_friend.spy_age > 12 and new_friend.spy_age < 50 and new_friend.spy_rating >= spy.spy_rating:

        friends.append(new_friend)

        print '\nFriend Added!'

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

    return len(friends)
コード例 #2
0
ファイル: Main.py プロジェクト: JagdeepThakur/SpyChat
        if re.search(J3, spy.spy_name):

            # we are happy with the value given
            # Exiting Loop

            break

        else:
            print "\nEnter a valid value..!"
            continue

    # Asking the user for input until they give a valid response

    while True:

        spy.spy_salutation = raw_input("\nShould I call you Mr. or Ms.??? ")

        J = r"([Mm]r)"
        J1 = r"([Mm]s)"

        if re.search(J, spy.spy_salutation) or re.search(
                J1, spy.spy_salutation):

            break

        else:

            print "\nPlease enter a valid value.."
            continue

    # Asking the user for input until they give a valid response