def add_friend(): new_friend = Spy('','',0,0.0) #added in the spy class new_friend.name = raw_input("Please add your friend's name: ") if set('[~!@#$%^&*()_+{}":;\']+$ " "').intersection(new_friend): print "Invalid entry." else: print new_friend new_friend.salutation = raw_input("Formal Salutation: Mr. or Ms. or Mrs. ") 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) > 2 and new_friend.age > 15 and new_friend.rating >= spy.rating: friends.append(new_friend) print 'New Friend Added!' else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided!!' return len(friends)
def add_friend(): # input name,age,rating of the spy by the user name = raw_input('What is your friend\'s name?') salutation = raw_input('Are they Mr. or Miss') name = salutation + name age = raw_input('What is your friend\'s age?') rating = raw_input('What is your friend\'s rating?') # convert age into int and rating to float age = int(age) rating = float(rating) # validation to check that name has a value # validation to check age of spy is between 12 and 50 # validation to check that the spy's friend rating is greater than or equal to that of spy # IF THE VALIDATIONS ARE TRUE THAN THE DATA OF FRIEND IS ADDED TO THE LISTS if len(name.strip()) != 0 and 12 < age < 50 and rating >= spy.rating: new_friend = Spy(name, age, salutation, rating) friends.append(new_friend) print 'Friend added' else: # ELSE IF VALIDATIONS ARE NOT SATISFIED THEN A SORRY MESSAGE IS PRINTED print 'Sorry! We can\'t enter the spy with the details you provided.' \ 'There may be on eof the following errors' \ '1. Name is not valid' \ '2. Age is not in integer format' \ '3. Rating is not in number format' print 'you have' + str(len(friends)) + 'friends in total' return len(friends)
def load_frnds(): # Function to load friends with open("friends.csv", "rb") as friend_data: # Opening file friends.csv reader = list(csv.reader(friend_data)) # reading from file for row in reader[1:]: frnd = Spy(name=row[0], salutation=row[1], age=row[2], rating=row[3]) friends.append(frnd) # Appending in the friends list
def load_frnd(): with open('friends.csv', 'rb') as friends_data: reader = csv.reader(friends_data) for row in reader: spy = Spy(Name=row[0], Salutation=row[1], Age=row[3], Rating=row[2]) friends.append(spy)
def signup(): spy = Spy("","",0,0.0) #class for spy details spy.name = raw_input("Enter your name ") # name taken as input from user if spy.name.isspace(): # check for space input print ' Enter a valid name ' elif spy.name.isdigit(): print ' Enter a valid name ' elif len(spy.name) > 2: # checking for length of string print " welcome " + spy.name+" "+" Glad to have with us. " # concatenating strings spy.sal = raw_input("What do we call you (Mr. or Ms. or Mrs.)") if spy.sal == "Mr." or spy.sal == "Ms." or spy.sal == "Mrs.": # condition for checking input salutation spy_name = spy.sal+" "+spy.name print " Alright " + spy_name + " I\'d like to know little more about you......" spy.age = input('what\'s your age') if 55 <= spy.age <= 12: # nested if to check range of age print 'You are not eligible to be a spy' else: rating = input('enter your ratings ') if spy.rating > 5: print 'Great Spy!!!' elif spy.rating > 4: print 'Good Spy...!' elif spy.rating > 3.5: # elif is used for more than one condition print ' Average Spy ' elif spy.rating > 2.5: print ' Need To Work Hard !!! ' else: print ' Who Hired You...Get Out !!! ' spy_is_online = True print 'Authentication complete. Welcome ' + spy.name + ' age: ' + str(spy.age) + ' and your rating is : ' + str(spy.rating) # typecasting of integer to string spy_chat(spy.name, spy.age, spy.rating) # calling function spy_chat else: print ' Enter a valid salutation ' else: print ' Ooops!! Please enter a valid name. '
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input("Enter friends 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) new_friend.chats = [] if len(new_friend.name) > 0 and new_friend.age > 12: friends.append(new_friend) print colored('\nFriends Added', 'yellow', attrs=['bold']) else: print 'Sorry! Invalid entry. We can\'t add spy with the details you provided' return len(friends)
def add_friend(): frnd = Spy("", "", 0, 0.0) firstname = raw_input("enter your friends name ") frnd.sal = raw_input("enter friend salutation:") frnd.age = input("enter age of friend::") frnd.rating = input("enter rating:") frnd.name = frnd.spy + " " + frndname if len(frnd.name ) >= 2 and 12 < frnd.age < 60 and frnd.rating >= spy.rating: friends.append(frnd) else: print "Sorry enter Valid Details" return len(friends)
def add_friend(): # function to add friend # taking friend detail as input frnd = Spy("","",0,0.0) # class for details of friend frnd.name = raw_input("What is your friend's name :") frnd.sal = raw_input("What is your friends salutation") frnd.age = input("What is the age :") frnd.rating = input("What are the rating :") frnd.is_online = True if len(frnd.name)>0 and 12<frnd.age<50 and frnd.rating > spy.rating: # adding the details in the respective lists with open('friend.csv','ab')as friend_data: writer = csv.writer(friend_data) writer.writerow([frnd.sal,frnd.age,frnd.rating,frnd.is_online]) print "Your frnd is added" friends.append(frnd) # appending friend details in friend list else: print "The friend cannot be added " return len(friends) # retuning length of list friend_name
def signup(): spy = Spy("", "", 0, 0.0) # class for spydetails spy.name = raw_input( 'Enter your username: '******'Enter a valid name ' elif spy.name.isdigit(): # to check for digit input print 'Enter a valid name ' elif len(spy.name) > 2: # checking for length of the string name password = raw_input("Enter your password: "******" " + spy.name print 'Alright ' + spy_name + '. I\'d like to know a little bit more about you...' spy.age = input('What\'s your age : ') if 50 <= spy.age <= 12: # nested if statement to check range of age print 'You are not eligible to be a spy.' else: spy.rating = input( 'What are your ratings : ') # taking ratings as input if spy.rating > 5: print 'Great Spy!!' elif spy.rating > 3.5: # elif statement for more than one condition print 'Average Spy.' elif spy.rating > 2.5: print 'Need to work hard!!' else: print 'Who hired you' spy_is_online = True print 'Authentication complete. Welcome ' + spy_name + '.Your age is ' + str( spy.age) + ' and your rating is ' + str( spy.rating) # typecasting of integer to string # writing details in login file with open("login.csv", "ab") as login: writer = csv.writer(login) writer.writerow([ spy.name, password, spy.sal, spy.age, spy.rating, spy_is_online ]) spy_chat(spy_name, spy.age, spy.rating) # calling function spy_chat else: print 'Enter a valid salutation' else: print 'Ooops! Enter a valid name '
def add_friend(): #define friend fxn to add new 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 int( new_friend.age) > 12 and new_friend.rating >= float(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)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input('Please add your friend\'s name :') new_friend.salu = raw_input('are they Mr or Miss ? :') new_friend.age = int(raw_input('age:')) new_friend.rating = float(raw_input('spy rating')) if (new_friend.name.isalpha() ) and new_friend.age > 12 and new_friend.rating >= spy.rating: #add friend into friend list friends.append(new_friend) else: print 'Sorry! invalid entry.We can\'t add spy with the detalis you provided ' return len(friends)
def add_friend(): #ADD FRIEND frnd = Spy(" ", " ", 0, 0.0) frnd.Name = raw_input("What is your name ? ") frnd.sal = raw_input("What should we call u ? ") frnd.Age = input("What is your age? ") frnd.Rating = input("What is your rating? ") frnd.is_online = True if len(frnd.Name) > 2 and 12 < (frnd.Age) < 50 and (frnd.Rating): friends.append(frnd) with open('friends.csv', 'a') as friends_data: writer = csv.writer(friends_data) writer.writerow( [spy.name, spy.saluation, spy.rating, spy.age, spy.is_online]) else: print "Friend cannot be added" return len(friends)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = input("please ! add your friends name ? ") name = new_friend.name new_friend.salutation = input("Are they MR OR MS") new_friend.name = new_friend.salutation + " " + name new_friend.age = int(input("enter age ?")) new_friend.rating = float(input("spy rating ?")) if len(new_friend.name) > 0: print("spy name is not empty") if (name_vali(name) is True) and age_val(new_friend.age): friends.append(new_friend) else: print( "sorry invalid entry . we can't add spy with details you provided") # return the no of friends in dictionary return len(friends)
def add_friend(): new_friend = Spy('','',0,0.0) new_friend.name = raw_input("\nPlease 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 = 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: friend_list.append(new_friend) print 'Friend Added!' else: print '\nSorry! Invalid entry. We can\'t add spy with the details you provided' return len(friend_list)
def add_friend(): #creating empty values for new friend new_friend = Spy('', 0, '', 0.0) #to evaluate all details of spy's new friend like name, age, rating and salutation new_friend.name = raw_input("add your friends name:") new_friend.salutation = raw_input("are they Mr. or Ms.:?") new_friend.name = new_friend.name + " " + new_friend.salutation new_friend.age = int(raw_input("age?")) new_friend.rating = float(raw_input("spy rating?")) #to check the spy's friend's age, rating and the name that should not be empty if len(new_friend.name ) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating: friends.append(new_friend) print colored('Friend Added!', 'red') else: print colored( 'sorry! invalid entry. we can\'t add spy with the details you provided', 'blue') return len(friends)
elif menu_choice == 5: read_chat_history() else: #The menu will disappear. show_menu = False else: print 'Sorry you are not of the correct age to be a spy\n' if answer == "Y": start_chat(spy) else: spy = Spy('', '', 0, 0.0) spy.name = raw_input( "Welcome to spy chat, you must tell me your spy name first: ") if len(spy.name) > 0: spy.salutation = raw_input("Should I call you Mr. or Ms.?: ") spy.age = int(raw_input("What is your age?")) spy.rating = float(raw_input("What is your spy rating?")) if spy.rating > 4.5: print "You have a great ace.\n" elif spy.rating >= 3.5 and spy.rating <= 4.5:
elif menu_choice == 5: read_chat_history() #if user selects option 6, then close the application else: show_menu = False else: print colored("sorry you are not of the correct age to be a spy", 'red') if question == "Y": start_chat(spy) else: #declaring empty values for spy spy = Spy('', 0, '', 0.0) #to know about the spy while asking all the details like name, salutation, age and rating spy.name = raw_input("welcome to spychat. tell me your name:") #to check if spy name is not empty if len(spy.name) > 0: spy.salutation = raw_input("what should we call you(Mr. or Ms.)?") spy.age = int(raw_input("what is your age:")) spy.rating = float(raw_input("what is your spy rating?")) start_chat(spy) else: print colored("a spy needs to have a valid name. please try again",
else: show_menu = False else: print 'Sorry you are not of the correct age to be a spy' if existing == "y": #if user is old then take the old information through import fxn from ss import spy_name, spy_salutation, spy_age, spy_ratting print spy_name print spy_salutation print spy_age print spy_ratting start_chat(spy) else: #enter the data for new user spy = Spy('', '', 0, 0.0) spy.name = str( raw_input("Welcome to spy chat, you must tell me your spy name first: " )) #username of new user if spy.name == str(spy.name): a = raw_input("what is ur gender (male. 0r female)") # input gender if a == "male": # nested if statement print "mr." + " " + spy.name + " welcome to spy chat" else: print "miss" + " " + spy.name + " welcome to spy chat" spy.age = int(raw_input( "What is your age?")) #check that the age of user is valid or not if spy.age > 16 and spy.age < 45: d = raw_input("may i know what is ur rating") # input ratting
from spydetails import spy, Spy # Importing datetime from datetime import datetime # Create a class for the chat messages class ChatMessage: def __init__(self, message, sent_by_me): self.message = message self.time = datetime.now() self.sent_by_me = sent_by_me #making some friends of our spy friend_one = Spy('Raja', 'Mr.', 27, 4.9) friend_two = Spy('Mata Hari', 'Ms.', 21, 4.39) friend_three = Spy('No', 'Dr.', 37, 4.95) friends = [friend_one, friend_two, friend_three] # starting application and printing a hello message print 'Hello' print 'Let\'s get started' # ask user to continue as existing spy or to create a new profile question = raw_input("Continue as " + spy.salutation + " " + spy.name + "(Y/N)?") # if user says yes then continue with existing profile if question.upper() == 'Y': print 'Welcome %s %s with age %d and rating %.1f' % ( spy.salutation, spy.name, spy.age, spy.rating)
from steganography.steganography import Steganography from datetime import datetime #import_date_time t = datetime.now() print t.strftime("%b %d %Y %H:%M:%S") #format_of_date_time import csv print "hello buddy!!" print 'let\'s get started' STATUS_MESSAGE = [ 'Sleeping', 'Talk is cheap,show me the Code', 'Keep Calm And Code Python' ] #status_message frnd1 = Spy('Aryan', 'Mr.', 23, 2.5) frnd2 = Spy('Abhimanyu', 'Mr.', 24, 2.5) friends = [frnd1, frnd2] def load_frnd(): with open('friends.csv', 'rb') as friends_data: reader = csv.reader(friends_data) for row in reader: spy = Spy(Name=row[0], Salutation=row[1], Age=row[3], Rating=row[2]) friends.append(spy)
while (show_menu): menu_choice = 'What do you want to do? \n 1. Add a status update \n 2.Add frinend \n 3.send a secrrt message \n 4.read a secret message \n 5.read chat history from a user \n 6. close appliction' menu_choice = raw_input(menu_choice) menu_choice = int(menu_choice) if menu_choice == 1: print 'You chose to update the status' current_status_message = add_status( current_status_message) #calling add _status funtion elif menu_choice == 2: add_friend() #calling add _friend funtion elif menu_choice == 3: send_message() #calling send_message funtion elif menu_choice == 4: read_message() #calling read_message funtion elif menu_choice == 5: read_chat_history() #calling read_chat_history funtion elif menu_choice == 6: show_menu = False else: print 'plz enter given choice number' #this for you are countinue with old spy details Yes or no question = raw_input('do you want the countinue yes(Y) or no(N) :') if (question.upper() == 'Y'): print 'okey' start_chat() else: spy = Spy('', '', 0, 0.0) spy.name = raw_input("Enter the name") vaildion(spy.name)
elif choice == 5: print "will read message of user" elif choice == 0: print "Exit" #if input is wrong else: print "Enter Valid Input" #welcome of user f = datetime.now() print f.strftime('%b %d %Y %H:%M:%S') print "Hello!" print 'Let\'s get started' #friends name with details frnd1 = Spy('ANIL', 'Mr.', 20, 5.3) frnd2 = Spy('Pooja', 'Ms.', 21, 7.0) friends = [frnd1, frnd2] #list of friends # available status list STATUS_MESSAGE = ['Sleeping', 'Available', 'Busy', 'At Work'] #asking user if user is already present or not spy_reply = raw_input('Are you a new user? Y/N') if spy_reply.upper() == 'N': #details of already present user print 'Welcome back..!! ' + spy.name + '. Your age is ' + str( spy.age) + ' and your rating is ' + str(spy.rating) #function calling spy_chat(spy.name, spy.age, spy.rating) if spy_reply.upper() == 'Y': spy = Spy('', '', 0, 0.0) spy.name = raw_input("what is your name?")