Question: Python 3 please Exercise 1. Replace. Using the methods split and join (without using the existing function str.replace), write a function replace(s, old, new) that

 Python 3 please Exercise 1. Replace. Using the methods split and

Python 3 please

Exercise 1. Replace. Using the methods split and join (without using the existing function str.replace), write a function replace(s, old, new) that replaces all occurrences of old with new in a string s: > replace('Mississippi', 'i', 'I') 'MISSISSIPPI' > replace('I love spom! Spom, yum!', 'om', 'am') 'I love spam! Spam, yum! Exercise 2. Shuffle Write a function shuffle(Ist) that shuffles the elements of a list in place. In place means that the function does not construct a new list, but directly modifies the contents of the list sent to it. Your function will not have a return statement. A simple shuffling algorithm works as follows. Let n be the length of the list. For every index i in range(n), draw a random value r in the range i python shuffle.py That they may have life and have it more abundantly life have abundantly That it more they may and have Exercise 3. Draw cards. Write a function deck() that constructs and returns a list of 52 strings representing a deck of cards. Your strings should be of the following form: '10 of Spades', 'Queen of Hearts', etc. The four suits in a deck of cards are called Hearts, Diamonds, Spades, and Clubs, and the thirteen ranks are 2-10, Jack, Queen, King, and Ace. You can start by creating two lists: one for the suits and one for the ranks. Write a function choose_cards(n) that returns a list of n cards from a full 52-card deck chosen with replacement, i.e. the card is returned to the deck after every draw and may be randomly chosen again. . Write a function draw_cards(n) that returns a list of n cards from a full deck without replacement. An algorithm for doing so will first shuffle the deck and return the first n cards from it. Write a function suit_count(hand) that takes in a list of cards and returns a list of four numbers containing how many cards there are in every suit starting with spades, followed by hearts, diamonds, and finally clubs. Exercise 4. Factorial, recursive version Write a recursive version of the factorial function rfactorial(n) which returns the value of n! where n is assumed to be a positive integer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!