def add_friend(): count = 0 name = raw_input('Enter Friend\'s name:\n') age = int(raw_input('\nEnter Friend\'s age:\n')) rating = raw_input('\nEnter Friend\'s Rating:\n') salutation = raw_input('\nEnter Friend\'s Salutation:\n') friend = Spy(name, age, rating, salutation) if friend.name.isalpha(): if friend.age > 18 or friend.age < 40: friends.append(friend) write_friend = open('friends.csv', 'a') write = csv.writer(write_friend) write.writerow( [friend.salutation, friend.name, friend.age, friend.rating]) write_friend.close() print('FRIEND ADDED\n') else: print('Age problem\n') else: print('Invalid Name \n') count_friend = open('friends.csv', 'r') read = csv.reader(count_friend) for row in read: count += 1 count_friend.close() return count
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.?: ") 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) #Completetion for successfully added friend if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating: friends.append(new_friend) print "Friend name successfully Added!" else: print("Sorry!You are not fit for spywork") return len(friends)
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("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) 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)
elif menu_choice == 2: number_of_friends = add_friend() print 'You have %d friends' % (number_of_friends) elif menu_choice == 3: send_message() elif menu_choice == 4: read_message() elif menu_choice == 5: read_chat_history() else: show_menu = False else: print 'Sorry you are too young to get tag of a spy ' if exist == "1": start_chat(spy) else: spy = Spy('', '', 0, 0.0) spy.name = raw_input("Welcome to spy chat,enter your name: ") if len(spy.name) > 0: spy.salutation = raw_input("Should I call you Mr. or Ms. or Miss.?: ") spy.age = raw_input("enter your age : ") spy.age = int(spy.age) spy.rating = raw_input("enter your spy rating : ") spy.rating = float(spy.rating) start_chat(spy)
elif menu_choice==3: SF.send_message() elif menu_choice==4: SF.read_message() elif menu_choice==5: break else: print('\nPlease enter a valid choice\n') #printing welcome message print ('Welcome to Spy_Chat\n') #input profile choice profile_choice=int(raw_input('Enter 1 to go with default profile or 2 to enter Details\n')) if profile_choice==1: spy=Spy('PierceBrosnan',27,'A+','Mr.') elif profile_choice==2: name=raw_input('Enter name of the spy\n') rating=raw_input('Enter rating of the spy\n') age=int(raw_input('Enter age of the spy\n')) salutation=raw_input('Enter The salutation Mr. or Ms.\n') spy=Spy(name,age,rating,salutation) else: print('Enter correct choice\n') sys.exit(0) #validating Name and Age if spy.name.isalpha() == False: print('Invalid Spy Name\n') sys.exit(0) if spy.age<18:
elif menu_choice == 5: read_chat_history() elif menu_choice == 6: print "Application closed" show_menu = False else: print "That was a wrong choice." #Dispalying meassage if spy age is not fufill else: print 'Sorry you are not of the correct age to be a spy' if existing.upper() == "Y": start_chat(spy) elif existing.upper() == "N" : spy = Spy('','',0,0.0) #For custom user app ask the name spy.name = raw_input("Welcome to spy chat, you must tell me your spy name first: ") if len(spy.name) > 0: #Ask the custom user the salutation he/she want spy.salutation = raw_input("Should I call you Mr. or Ms.?: ") if len(spy.salutation)>0: #Ask the user for their age spy.age = raw_input("What is your age?") if len(spy.age)>0: spy.age = int(spy.age) spy.rating = raw_input("What is your spy rating?")