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

    new_friend = Spy('', '', 0, 0.0)  #adding a new friend on account a spy

    #taking friend's details
    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)

    #checking for authenticity of a friend
    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'

    return len(friends)
コード例 #2
0
def add_friend():
    new_friend = Spy('', '', 0, 0.0)

    new_friend.name = raw_input("enter your name")
    # len function checks the length text to prevent from empty input to the name
    if len(new_friend.name) > 0 and new_friend.name.isspace(
    ) == False:  #isspace() checks whether the string consists of whitespace
        new_friend.salutation = raw_input("Are they Mr. or Miss.?: ")
        if new_friend.salutation == "Mr." or new_friend.salutation == "Miss.":

            new_friend.name = new_friend.salutation + " " + new_friend.name
            new_friend.age = int(raw_input("enter your age"))
            new_friend.rat = float(raw_input("enter your rating"))

            if new_friend.age > 12 and new_friend.rat > spy.rating:
                friends.append(new_friend)
                print "friend added"

            else:
                print "please enter valid age or rating"

        else:
            print "please enter valid salutation"

    else:
        print "Sorry!!we can't move further please enter valid spy name"

    return len(friends)  # it returns no of friends which are added in the fri
コード例 #3
0
ファイル: main1.py プロジェクト: lakshayrajput/spy-chat
def add_Friend():
    #-----------------------------FULL-FILL THE REQUIREMENTS------------------#

    spy.name = raw_input("Enter your friend name: ")
    while spy.name.isalpha() == False:
        spy.name = raw_input(
            "Name contains only'A-Z' or 'a-z' alphabets.Please enter again: ")

    spy.salutation = raw_input(
        "Which one would you prefer for your friend \" Mr or Ms. \" :")
    value = True
    while value:
        if spy.salutation == 'mr' or spy.salutation == 'Mr' or spy.salutation == 'MR' or spy.salutation == 'ms' or spy.salutation == 'Ms' or spy.salutation == 'MS':
            value = False
        else:
            spy.salutation = raw_input(
                "Please enter a valid salutation \" Mr or Ms. \": ")

    spy.salutation = 'M' + spy.salutation[1:]
    spy.salutation = spy.salutation + "."
    while len(spy.name) <= 0:
        spy.name = raw_input("Please enter valid name: ")

        #spy.name = spy.salutation + " " + spy.name
        print("Welcome " + spy.name)
    #spy.name = spy.salutation + " " + spy.name

    confirmAge = raw_input(
        "Press 'Y' if you are in b/w (12 - 50) years,otherwise press any other key..: "
    )
    if confirmAge.upper() != 'Y':
        print("Sorry !" + spy.name + " can't become a spy.")
        exit()
    else:
        spy.age = int(raw_input("Enter your friend age: "))
        while spy.age > 50 or spy.age < 12:
            spy.age = int(raw_input("Incorrect Age. Please enter again: "))

        spy.rating = float(raw_input("Enter your friend rating: "))
        while spy.rating < 0 or spy.rating > 5:
            spy.rating = float(
                raw_input("Incorrect Rating. Please enter again: "))

        spyIsOnline = True
        # -----------------ADDING THE NEW SPY TO THE SPY FRIEND-LIST----------------#
        friends.append(spy)
        print("Now " + spy.salutation + ". " + spy.name +
              " has been added to your friend-list..")

        # ---------------TOTAL NO OF FRIENDS----------------------#
        total_Friends = len(friends)
        print("Total number of friends you have = " + str(total_Friends))
        count = 1
        for temp in friends:
            print(str(count) + ". " + temp.salutation + " " + temp.name)
            count = count + 1
    print(
        "-----------------------------------------------------------------------------------------------------"
    )
コード例 #4
0
def add_friend(
):  # declaration of add_friend function which is used to add friend
    new_friend = {
        'name': '',
        'salutation': "",
        'age': 0,
        'ratings': 0.0,
        'online': True,
        'chats': []
    }
    valid_name = True
    valid_salutation = True
    while valid_name:
        new_friend['name'] = raw_input("what is the name of friend ?:  ")
        if len(new_friend['name']) >= 3:
            while valid_salutation:
                new_friend['salutation'] = raw_input(
                    "what we call your frnd : ")
                if len(new_friend['salutation']) >= 2:
                    new_friend['name'] = new_friend[
                        'salutation'] + " " + new_friend['name']
                    valid_name = False
                    valid_salutation = False
                else:
                    print 'invalid salutaion'
        else:
            print "please enter valid name"
    valid_age = True
    while valid_age:
        new_friend['age'] = raw_input("Age of frnd")
        if len(new_friend['age']) > 0:
            valid_age = False
        else:
            print 'invalid age'
    valid_rating = True
    while valid_rating:
        new_friend['rating'] = raw_input("Rating of  a frnd")
        if len(new_friend['rating']) > 0:
            valid_rating = False
        else:
            print 'invalid ratings'
        new_friend['online'] = True
        if len(new_friend['name']) >= 3 and 55 >= int(
                new_friend['age']
        ) >= 12 and new_friend[
                'rating'] >= spy.rating:  # We are givig a certain conditon to add a friend
            friends.append(new_friend['name'])
            with open('friend.csv', 'a') as friends_data:
                writer = csv.writer(friends_data)
                writer.writerow([
                    new_friend['name'], new_friend['rating'],
                    new_friend['age'], new_friend['online']
                ])
        else:
            print "friend cannot be added "
    return len(friends)
コード例 #5
0
def load_friends():
    with open('friend.csv', 'rU') as friends_data:
        reader = list(csv.reader(friends_data, dialect='excel'))
        for row in reader[1:]:
            if row:
                name = (row[0])
                age = (row[1])
                rating = (row[2])
                spy = Spy(name, age, rating)
                friends.append(spy)
コード例 #6
0
def add_Friend():

    spy.name = raw_input("Enter your friend name: ")
    while spy.name.isalpha() == False:
        spy.name = raw_input("Name contains only'A-Z' or 'a-z' alphabets.Please enter again: ")

    spy.salutation = raw_input("Which one would you prefer for your friend \" Mr or Ms. \" :")
    value = True
    while value :
        if spy.salutation == 'mr' or spy.salutation == 'Mr' or spy.salutation == 'MR' or spy.salutation =='ms' or spy.salutation == 'Ms' or spy.salutation == 'MS' :
            value =False
        else :
            spy.salutation = raw_input("Please enter a valid salutation \" Mr or Ms. \": ")

    spy.salutation = 'M' + spy.salutation[1:]
    while len(spy.name) <= 0:
        spy.name = raw_input("Please enter valid name: ")

        spy.name = spy.salutation + " " + spy.name
        print("Welcome " + spy.name)
    spy.name = spy.salutation + " " + spy.name

    confirmAge = raw_input(
        "Hey dude your is in B/W (12 - 50) years ? if yes then press'Y',if not then press any other: ")
    if confirmAge.upper() != 'Y':
        print("Sorry ! You can't become a spy.")
        exit()
    else:
        spy.age = int(raw_input("Enter your friend age: "))
        while spy.age > 50 or spy.age < 12:
            spy.age = int(raw_input("Incorrect Age. Please enter again: "))

        spy.rating = float(raw_input("Enter your friend rating: "))
        while spy.rating < 0 or spy.rating > 5:
            spy.rating = float(raw_input("Incorrect Rating. Please enter again: "))

        spyIsOnline = True
        friends.append(spy)
        print("Now your friend '"+spy.salutation+" "+spy.name+"' is online..")
        # --------TOTAL NO OF FRIENDS-------------#
        total_Friends = len(friends)

        print("Total number of friends you have = "+str(total_Friends))
コード例 #7
0
def add_friend():

    new_friend['name'] = raw_input(bcolors.HEADER +
                                   "Please add your friend's name:\t ")
    new_friend['salutation'] = raw_input(bcolors.OKBLUE +
                                         "Are they Mr. or Ms.:\t")

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

    new_friend['age'] = input("Age\t")

    new_friend['rating'] = input("Spy rating\t")

    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'

    return len(friends)