Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing these functions in python. I have included the text that 's in the file: pikachu,Abc123charmander,Xyz123squirtle,SquirtleSquad99Pidgey2020,Pqr123fearow,Pidgey2020 # function: valid_username # input: a

I need help writing these functions in python. I have included the text that's in the file: pikachu,Abc123charmander,Xyz123squirtle,SquirtleSquad99Pidgey2020,Pqr123fearow,Pidgey2020

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
# function: valid_username # input: a username (string) # processing: determines if the username supplied is valid. for the purpose of this program a valid username is defined as follows: (1) must be 5 characters or longer (2) must be alphanumeric (only letters or numbers) (3) the first character cannot be a number # output: boolean (True if valid, False if invalid) # TESTER CODE print( valid_username(' abc123') ) # True print( valid_username(' abcde' ) ) # True print( valid_username(' abc') # False print( valid_username('@#$%^') # False print( valid_username('labcde' ) ) # False print( valid_username(" ') # False# function: valid_password # input: a password (string) # processing: determines if the password supplied is valid. for the purpose # of this program a valid password is defined as follows: # (1) must be 5 characters or longer (2) must be alphanumeric (only letters or numbers) # (3) must contain at least one lowercase letter # (4) must contain at least one uppercase letter (5) must contain at least one number # output: boolean (True if valid, False if invalid) # TESTER CODE print( valid_password( 'Abc123' ) # True print( valid_password(' Abc123xyz' ) # True print( valid_password( ' Ab12' ) # False print( valid_password(' abc123') # False print( valid_password(' 123456') # False print( valid_password(' Abc123#' ) # False print( valid_password(" ') # False# function: username_exists # input: a username (string) # processing: determines if the username exists in the file 'user_info. txt' # output: boolean (True if found, False if not found) # TESTER CODE print( username_exists( 'pikachu' ) # True print( username_exists(' charmander') # True print( username_exists(' squirtle' ) # True print( username_exists( 'Pidgey2020' ) # True print( username_exists( ' SquirtleSquad99') # False print( username_exists(' eevee' ) # False print( username_exists( 'bobcat') # False print( username_exists( " ') # False# function: check_password # input: a username (string) and a password (string) # processing: determines if the username / password combination # supplied matches one of the user accounts represented # in the 'user_info. txt' file # output: boolean (True if valid, False if invalid) # TESTER CODE print( check_password( 'pikachu' , 'Abc123') # True VV print( check_password(' squirtle', 'SquirtleSquad99') # True print( check_password(' fearow' , 'Pqr123' ) # False print( check_password(' foobar', 'Hello123') # False print( check_password(" ', ") # False# function: add_user # input: a username (string) and a password (string) # processing: if the user being supplied is not already in the # 'user_info. txt' file they should be added, along with # their password. # output: boolean (True if added successfully, False if not) # TESTER CODE add_user(' foobar', 'abcABC123' ) add_user('barfoo' , 'xyz123ABC' ) add_user(' foobar', 'aTest123') # this should fail # OUTPUT - check 'user_info. txt' to ensure that that two new accounts have been created# function: send_message # input: a sender (string), a recipient (string) and a message (string) # processing: writes a new line into the specific messages file for the given users with the following information: sender I date_and_time message\\ for example, if you call this function using the following arguments: send_message( 'craig', 'pikachu', 'Hello there! nice to see you!') the file 'messages/pikachu. txt' should gain an additional line data that looks like the following: craigl11/14/2020 12:30:05|Hello there! nice to see you!' note that you can generate the current time by doing the following: import datetime d = datetime. datetime. now() month = d. month day = d. day year = d. year ... etc. for hour, minute and second keep in mind that you may need to 'append' to the correct messages file since a user can receive an unlimited number of messages. you may also need to create a new message file if one does not exist for a user. # output : nothing # TESTER CODE send_message( 'pikachu', 'charmander', 'Hey there!') send_message( ' charmander' , 'pikachu', 'Good to see you!') send_message( 'pikachu', 'charmander', "You too, ttyl') # OUTPUT - two new messages files should be created - 'pikachu. txt' and 'charmander. txt" # each should have the following content (dates will be different, though) # # pikachu . txt # charmander |11/14/2020 13:37:15| Good to see you! # # charmander . txt # pikachul11/14/2020 13:37:15/Hey there! # pikachu | 11/14/2020 13:37:15/ You too, ttylFinally you will be writing two additional functions to complete the tools needed to write this program. The first function you will be writing will print out all messages for a specific user. Here's the IPO for this function: # function: print_messages # input: a username (string) # processing: prints all messages sent to the username in question. assume you have this file named 'pikachu. tx # charmander | 11/14/2020 13:37:151Hey there! charmander |11/14/2020 13:37:15|You too, ttyl # # this function should generate the following output: Message #1 received from charmander # Time: 11/14/2020 13:37:15 Hey there! Message #2 received from charmander # Time: 11/14/2020 13:37:15 # You too, ttyl # output : no return value (simply prints the messages) Once you can print messages successfully the last function you will need to write will be a function to delete all messages for a given user. The IPO for this function is as follows: # function: delete_messages # input: a username (string) # processing: erases all data in the messages file for this user # output: no return value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions