Ejemplo n.º 1
0
def add_friend():
    # new_friend is object of Spy class.
    new_friend = Spy("", "", 0, 0.0)
    # Adding details for new friend.
    new_friend.name = raw_input("Please  add your friends name:")

    new_friend.salutattion = raw_input("Mr. or Mrs.")
    new_friend.age = int(raw_input("Age:"))
    new_friend.rating = float(raw_input("Spy Rating:"))

    # checking condition that is he eligible to be a spy or not
    if len(
            new_friend.name
    ) > 0 and 12 < new_friend.age < 50 and 0.0 <= new_friend.rating <= 5.0:
        # if conditons are true than add to friend list
        friend.append(new_friend)
        # and to notify us print friend added statement.
        print "friend Added."
    # If condition are not valid.
    else:
        # Then friend entry won't be accepted.
        print "Enter Valid Entry."
    # returning the lenght of friend list.
    return len(friend)
Ejemplo n.º 2
0
# we take default user or new user
user = raw_input("Continue as default user(Y|N):")
user = user.upper()
# if default we call the spy object from hello.py
if user == 'Y':
    print "Welcome %s \n Age:%d \nRating:%.1f" % (spy.name, spy.age,
                                                  spy.rating)
    print "One of the Best Spy"
    start_chat(spy)

# we take input from the user and check whether the conditions are valid or not.
else:
    spy = Spy("", "", 0, 0.0)
    spy.name = raw_input("Enter Your name:")
    if len(spy.name) > 0:
        spy.salutattion = raw_input("Mr.or Mrs.")
        if len(spy.salutattion) > 0:
            spy.age = int(raw_input("Age:"))
            if 18 <= spy.age <= 50:
                spy.rating = float(raw_input("Rating:"))
                if 0.0 <= spy.rating <= 5.0:
                    print "Spy Rating:%.1f" % (spy.rating)
                    # checking whether spy_rating good average or bad through conditioning loops.
                    if spy.rating >= 4.5:
                        print "One of the best Spy."
                    elif 4.5 > spy.rating >= 3.5:
                        print "Better than most Spies."
                    elif 3.5 > spy.rating >= 2.5:
                        print "Need to improve."
                    else:
                        print "Not for Field Work."