Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago