![]() | |
Teachers Assignments Assignments Other Pages | Project 8: Assigned: Mon Oct 07 2024 In this project, you will write functions that manipulate and iterate over strings. Part 0, 1 points: Write a function >>> has_character('monkey', 3, 'k')
True
>>> has_character('cheese', 3, 'x')
False You can assume that the index is a legal index for the string. (We'll change that later.) Tester.Part 1, 0 points: Do the exercise at the end of section 7.3. Part 2, 1 points: Write the function >>> middle_char('ball')
'l'
>>> middle_char('soccer ball')
'r' Tester.Part 3, 2 points: Write the function >>> first_middle_last('sails')
'sis'
>>> Tester.Part 4, 0 points: Expert Practice: modify >>> middle_char('I')
'I'
>>> Part 5, 1 points: Write a function, >>> char_two_strings('hi', 'monkey', 2)
'm'
>>> char_two_strings('hi', 'monkey', 1)
'i' Tester.Part 6, 1 points: Write a function, >>> index_status('hi', 0)
'h'
>>> index_status('hi',10)
'too high'
>>> index_status('hi', -10)
'too low' Tester.Part 7, 1 points: Write a function, >>> num_legal_indices('hi')
4 That's because the indices -2, -1, 0, and 1 all work for the string "hi". Tester.Part 8, 1 points: Improve your function Part 9, 1 points: Write a function, >>> print_duckling_names('JKL')
Jack
Kack
Lack
>>> print_duckling_names('JKLMNOPQ')
Jack
Kack
Lack
Mack
Nack
Ouack
Pack
Quack
>>> Tester.Part 10, 1 points: Write a function, >>> get_all_between_string(2, 5)
'2 3 4 '
>>> print(get_all_between_string(2, 5))
2 3 4
>>> get_all_between_string(4, 5)
'4 '
>>> get_all_between_string(4, 3)
''
>>> (You don't need to add the single quotes, that's the interpreter telling you the result of those lines is a string.) Tester.Part 11, 2 points: Write a function, >>> odd_characters_only('monkey')
'oky'
>>> x = odd_characters_only('mouseface')
>>> print(x)
osfc
>>> Tester.Part 12, 1 points: Write a boolean function, >>> has_vowels('monkey')
True
>>> has_vowels('fly')
False Tester.Part 13, 1 points: Write a function, >>> no_spaces('monkey monkey monkey')
'monkeymonkeymonkey'
>>> x = no_spaces("It's time to fly!")
>>> print(x)
>>> It'stimetofly! Tester.Part 14, 1 points: Write a function, >>> vowels_only('monkey')
'oe' Tester.Part 15, 1 points: Write a function, >>> reverse_string('monkey')
'yeknom' Tester.Part 16, 2 points: For any string variable, say >>> awesome = 'Ana, nab a banana!'
>>> print(awesome[3])
,
>>> print(awesome[0] + awesome[2] + awesome[6])
aaa
>>> Write a new function, last_characters(string, n) , that returns a string with only the last n characters of string . Example:>>> last_characters('awesomesauce', 8)
'omesauce' Tester.Part 17, 3 points: Write a function, >>> extend_string('monkey', 20)
'monkeymonkeymonkeymo'
>>> extend_string('monkey', 10)
'monkeymonk'
>>> extend_string('monkey', 3)
'mon' Tester.Part 18, 0 points: Expert Practice: write a function, >>> pongify('planar chaos')
'planar chaossoahc ranalpplanar chaos'
>>> pongify('hybridization')
'hybridizationnoitazidirbyhhybridization'
>>> pongify('matrix')
'matrixxirtammatrix' Tester.Part 19, 3 points: Write a function >>> starts_with('champions of kamigawa', 'betrayers')
False
>>> starts_with('champions of kamigawa', 'champ')
True
>>> starts_with('hamburger', 'ham')
True
>>> starts_with('hamburger', 'hamburger')
True Tester.Part 20, 2 points: Write a similar function, >>> ends_with('champions of kamigawa', 'kamigawa')
True
>>> ends_with('kamigawa block', 'betrayers')
False Tester.Part 21, 1 points: Implement the Part 22, 1 points: Implement the Part 23, 3 points: Implement the >>> find_last('abrakadabra', 'a')
10
>>> find_last('alakazam', 'a')
6 Tester.Part 24, 2 points: Implement the >>> max_count('abrakadabra')
5
>>> max_count('alakazam')
4 Tester.Part 25, 3 points: Implement the >>> most_frequent_character('abrakadabra')
'a'
>>> most_frequent_character('blastoise')
's' Tester.Part 26, 2 points: Write a function, >>> x = smallest_missing_digit("0123456789")
>>> print(x)
None
>>> x = smallest_missing_digit("I t0ld you, I am some1 important 2 many people!")
>>> x
3
>>> x = smallest_missing_digit("9870")
>>> print(x)
1 Tester.Part 27, 3 points: Write a function, >>> sum_digits(31)
4
>>> sum_digits(0)
0
>>> sum_digits(1234)
10 Tester.Part 28, 1 points: Now write the function that's similar to the last, except that it keeps going until there's only one digit left, >>> sum_digits_limit(31)
4
>>> sum_digits_limit(0)
0
>>> sum_digits_limit(123456789)
9 Tester.Part 29, 1 points: Write a new function, >>> in_both('cheat', 'strongbad')
'a'
>>> in_both('strongbad', 'strongsad')
'strongad'
>>> in_both('steve', 'marzipan'))
'' Tester.Part 30, 1 points: Write the function, >>> centered_title('monkeys Galore')
' Monkeys Galore ' Tester.Part 31, 1 points: Write the function, >>> to_fancy_title('monkeys Galore')
'~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monkeys Galore ~~~~~~~~~~~~~~~~~~~~~~~~~~~' Tester.Part 32, 3 points: Write the function, >>> snake_to_camel('our_market_research_shows_that_players_like_really_long_card_names')
'ourMarketResearchShowsThatPlayersLikeReallyLongCardNames' Tester.Part 33, 1 points: Write the function, Part 34, 2 points: Write the function, >>> is_abecedarian("fly")
True
>>> is_abecedarian('ant')
True
>>> is_abecedarian('wasp')
False
>>> is_abecedarian('aaaaaaa')
True Instead of assuming something about the case of the letters in the string, you can use the lower() String method to get the lower case version like this: You may assume that every character in the argument string is a letter. How could your code use with the find method to figure out which letter comes first? Tester.Part 35, 0 points: Expert Practice: Exercise 8.5. Submitting your Project: Make sure all your code is in a file labelled with your user name (everything before the @ in your school email address) followed by |