In this test, you will write a program that plays a game similar to the coin-flipping game, but using cards instead of c
Posted: Tue May 24, 2022 7:56 am
In this test, you will write a program that plays a game similar to the coin-flipping game, but using cards instead of coins. Feel free to use module cards.py that was created in Question 4.6.
Write a program called test4.py that plays the following card game:
The game starts with certain initialamount of dollars.
At each round of the game, instead of flipping a coin, the player shuffles a deck and draws 6 cards. If the drawn hand contains at least one ace, the player gains a dollar, otherwise they lose a dollar.
The game runs until the player either runs out of money or doubles their initial amount.
To test the game, given the initial amount, run it 1000 times to determine how many rounds does the game last on average.
Provide a user with an interface to enter the initial bankroll. For each entered number, the program should respond with the average duration of the game for that initial bankroll.
The average number of rounds is an approximately linear function of the initial bankroll:
Average number of rounds ≈ 4.865 × initial
This behavior differs from the quadratic dependence in the coin-flipping game because the chances to winning and losing a dollar are not 50% vs 50% anymore, but approximately 40% vs 60%.
This unit introduced the topic of creating your own module, i.e. my.py. If you decide to use your own modules in your submission, please remember to submit both test4.py and my.py(and/or any other modules your program might use). Otherwise, your instructor will not be able to run your program, and it will be graded "0"! So, please don’t forget to do this!
Write a program called test4.py that plays the following card game:
The game starts with certain initialamount of dollars.
At each round of the game, instead of flipping a coin, the player shuffles a deck and draws 6 cards. If the drawn hand contains at least one ace, the player gains a dollar, otherwise they lose a dollar.
The game runs until the player either runs out of money or doubles their initial amount.
To test the game, given the initial amount, run it 1000 times to determine how many rounds does the game last on average.
Provide a user with an interface to enter the initial bankroll. For each entered number, the program should respond with the average duration of the game for that initial bankroll.
The average number of rounds is an approximately linear function of the initial bankroll:
Average number of rounds ≈ 4.865 × initial
This behavior differs from the quadratic dependence in the coin-flipping game because the chances to winning and losing a dollar are not 50% vs 50% anymore, but approximately 40% vs 60%.
This unit introduced the topic of creating your own module, i.e. my.py. If you decide to use your own modules in your submission, please remember to submit both test4.py and my.py(and/or any other modules your program might use). Otherwise, your instructor will not be able to run your program, and it will be graded "0"! So, please don’t forget to do this!