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"
use python please
def check_character(word, index):
# Type your code here.
if __name__ == '__main__':
print(check_character('happy birthday', 2))
print(check_character('happy birthday', 5))
print(check_character('happy birthday 2 you', 15))
print(check_character('happy birthday!', 14))
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Write a function that accepts a string as an argument and returns true if the argument ends with the substring .doc'. Otherwise, the function should return falsearrow_forwardC program Write 2 functions that can convert an input string to all lowercase and to all uppercase. Write a program to illustrate the use of these 2 functions. Test Data: Input the string: ComputerEngineering Output: Lowercase: computerengineering Uppercase: COMPUTERENGINEERINGarrow_forwardThe following functions are all intended to check whether a string representing a dna sequence contains any characters that are not 'a','c','g','t', 'A', 'C', 'G', or 'T'. At least some of these functions are wrong. Which ones are correct? A) def valid_dna1(dna): for c in dna: if c in 'acgtACGT': return True else: return False B) def valid_dna3(dna): for c in dna: flag = c in 'acgtACGT' return flag C) def valid_dna4(dna): for c in dna: if not c in 'acgtACGT': return False return True -------------------------------------------------------------------------------------------------------------------------------------------------------- valid_dna1 only valid_dna4 only None of them. valid_dna1, and valid_dna4 onlyarrow_forward
- Declare a function named contains_char. Its purpose is when given two strings, the first of any length, the second a single character, it will return True if the single character of the second string is found at any index of the first string, and return False otherwise.arrow_forwardScrabble Scrabble is a game where players get points by spelling words. Words are scored by adding together the point values of each individual letter. Define a function scrabble_score (word:str) -> int that takes a string word as input and returns the equivalent scrabble score for that word. score = {"a": 1, "c": 3, "f": 4, "i": 1, "1": 1, "o": 1, "r": 1, "u": 1, "t": 1, "x": 8, "z": 10} For example, "b": 3, "h": 4, "n": 1, Your Answer: == 20 assert scrabble_score("quick") assert scrabble_score("code") == 7 1 # Put your answer here 2 Submit "e": 1, "d": 2, "g": 2, "k": 5, "j": 8, "m": 3, "q": 10, "p": 3, "s": 1, "w": 4, "v": 4, "y": 4,arrow_forward4. Complete the function show_upper. This function takes one parameter - a string (s). It should return a string made up of all the upper-case characters in s. For example, if s is “aBdDEfgHijK” then show_upper should return “BDEHK”. It should return the upper-case string - not print it. Do not change anything outside show_upper.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education