Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please break down each answer, having a hard time grasping the material so step by step would be appreciated. Also, please try to keep the

image text in transcribedimage text in transcribedimage text in transcribed

Please break down each answer, having a hard time grasping the material so step by step would be appreciated. Also, please try to keep the functions as basic as possible and easy to follow. Answers need to satisfy the sample usage for each problem so please ensure you run them in python and get matching outputs.

Thank you!

vowe 1 Index Write a function vowelindex that accepts a word (a str ) as an argument and returns the index of the first vowel in the word. If there is no vowel, 1 is returned. For this problem, both upper and lower case vowels count, and ' y ' is not considered to be a vowel. Sample usage: >> vowelIndex ('he170') 1 > vowelIndex ('string') 3 >> vowelindex ('string') 3 > vowelindex('BUY') 1 >> vowe Index('APPLE') 0 > vowelindex ('nymph7y') 1 >>> vowe 1 Index ('string') =3 True > vowe 1 Index ( 'nymph 7y)=1 True Write a function flipcase that accepts a word as an argument and returns the same word but with each upper case letter switched to lower case and vice-versa. Sample usage: > flipcase('ostrich') 'OSTRICH' flipCase ('LyNX') ' 1Yn ' flipCase('orangutan') 'ORANGUTAN' flipCase ('Aardvark') ' aARDVARK' flipCase ('CamelCase') 'CAMELCASE' flipCase('ostrich') == 'OSTRICH' True palindromes Write a function palindromes that accepts a sentence as an argument. The function then returns a list of all words in the sentence that are palindromes, that is they are the same forwards and backwards. Guidelines: - punctuation characters ..i1? should be ignored - the palindrome check should not depend on case Sample usage: paTindromes("Hey Anna, would you prefer to ride in a kayak or a racecar?") ['Anna', 'a', 'kayak', 'a', 'racecar'] palindromes ("Able was I ere I saw Elba.") ['I', 'ere', 'I'] palindromes ("Otto, go see Tacocat at the civic Center, their guitar solos are wow! ") ['otto', 'Tacocat', 'Civic', 'solos', 'wow'] palindromes ("Otto, go see Tacocat at the civic Center, their guitar solos are wow!" ) =[ 'otto', 'Tacocat', 'Civic', 'solos', 'wow'] True squares Write a function squares that accepts a 2-dimensional list of integers or a list of ranges as an input, and that returns the count of all the integers that are perfect squares. - a perfect square is an integer that is the square of another integer. 9 is a perfect square because 9 is equal to 3 squared. - don't worry about the ranges, if you write your code in the obvious way, it will also work for ranges. Sample usage: squares ([[1,2,3],[4,5],[6,7,8,9]])#1,4,9 are perfect squares 3 squares ([[1,2,3],[4,5,6],[7,8],[9,10,11,12],[13,14,15,16]]) 4 >> squares ( [ range (1,1000,7), range (1,500,13)] ) 12 > squares ( [range(2,1000,3), range (7,100,8),range(8,1000,5)] ) 0 >> squares ([range(1,1000,7), range (1,500,13)])==12 True rps (Exercise 5.26 from the textbook) Write a function rps that returns the result of a game of "Rock, Paper, Scissors". The function accepts two arguments, each one of ' R ', ' P ' , ' S ', that represents the symbol played by each of the two players. The function returns: - 1 if the first player wins - 0 if a tie - 1 if the second player wins - Scissors beats Paper beats Rock beats Scissors Sample usage: rps(R,PP)# player 2 wins, return 1 1 >rps(R,S ') \# player 1 wins, return 1 1 rps(s,s) tie, return 0 0 [(p1,p2,rps(p1,p2)) for p1 in 'RPS' for p2 in 'RPS'] [(R ', 'R', 0), ('R', 'P', 1), (R,S,1),(P,R,1),(P,P,0), (PP,S,1),(S,R,1),(S,P,1),(S,S,0)]

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

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

What can Chandra do to correct her mistake?

Answered: 1 week ago