7.13 LAB: Fun with characters Complete the check_character() function which has 2 parameters: A string, and a specified

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

7.13 LAB: Fun with characters Complete the check_character() function which has 2 parameters: A string, and a specified

Post by answerhappygod »

7 13 Lab Fun With Characters Complete The Check Character Function Which Has 2 Parameters A String And A Specified 1
7 13 Lab Fun With Characters Complete The Check Character Function Which Has 2 Parameters A String And A Specified 1 (62.9 KiB) Viewed 7 times
I need the code in Python. You can see what I have and what allis wrong with it. Thank you.
7.13 LAB: Fun with characters Complete the check_character() function which has 2 parameters: A string, and a specified index. The function checks the character at the specified index of the string parameter, and returns a string based on the type of character at that location indicating if the character is a letter, digit, whitespace, or unknown character. Ex: The function calls below with the given arguments will return the following strings: check_character ( 'happy birthday', 2) returns "Character 'p' is a letter check_character('happy birthday', 5) returns "Character is a white space" check_character ('happy birthday 2 you', 15) returns "Character '2' is a digit" check_character ('happy birthday!', 14) returns "Character !" is unknown' 40061226356627 LAB ACTIVITY 1 def check_character (word, index): if word[index].isalpha(): 1234 in 10 6 8 7.13.1: LAB: Fun with characters 5 if word[index].isspace(): 9 10 11 12 print('Character', '\" + str(word[index])+'\', 'is a letter') return print('Character', " + str(word[index])+ '\, 'is a white space') return" if word[index].isdigit(): print("character', '\ str(word [index])+', 'is a digit') return" print('Character', '\" + str(word[index])+'\', 'is unknown') return main.py 13 14 if 15 print(check_character (happy birthday', 2)) print(check_character( 'happy birthday', 5)) 16 17 print(check_character( 'happy birthday 2 you', 15)) _name _main__': Develop mode Submit mode 0/10 Load default template... When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading.
1: Compare output Output is nearly correct, but whitespace differs. See highlights below. Special character legend Your output Expected output 3: Unit test Your output Your output Character 'p' is a letter 2: Unit test Test check_character(word', 3) equals ("Character 'd' is a letter") Character 'd' is a letter check_character ('word', 3) incorrectly returned Character t is a white space Your output Character ¹2¹ is a digit Character is unknown Test check_character(word7', 4) equals ("Character 7 is a digit") Character '7' is a digit check_character ('word7', 4) incorrectly returned Your output Character 'p' is a letter Character ¹ 1 is a white space Character '2' is a digit Character is unknown 4: Unit test Test check_character (word or two, 7) equals ("Character is a white space") Character ! is a white space check_character ('word or two', 7) incorrectly returned 5: Unit test A Test check_character(word!', 4) equals ("Character is unknown") Character ! is unknown check_character ('word!', 4) incorrectly returned 0/2 0/2 0/2 0/2 0/2
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply