Please help Python programming

Assig nm ents 1. Py3 .3 : O dd E ve n S tr in g Directions: An even number has a remainder of zero when being divided by two. An odd number is any number that does not have a remainder of zero when being divided by two. Remember modulus division with "%"? Write a Python program that will ask the user for a string (not a number) and then use the number of characters in the string to print out whether that value is odd or even. Test your code with several inputs to confirm that your program outputs the correct answer for all strings. 2. Py4 .3 S ta rs a nd S tr ip es Directions: Project: Stars and Stripes 1. Write functions with the following names: printTwentyStars, printTwentyDashes, and printTwoBlankLines. Complete code for each function that does what the name of the function says. Hint: You won't need any parameters for these functions. 2. Write functions with the followiong names: printASmallBox and printABigBox. Write code for each function calling the functions from step one above to display output of the two boxes below. Call functions printASmallBox, printTwoBlankLines, and printABigBox to display the output below. 3. For extra credit you can create additional functions and call those functions to display more outputs. 3. Py5 .3 R ock-P aper-S cis so rs In this project, we'll build ​ ​Rock-Paper-Scissors ​ from Scatch in IDLE! The program should do the following: 1. Prompt the user to select either Rock, Paper, or Scissors 2. Instruct the computer to randomly select either Rock, Paper, or Scissors 3. Compare the user's choice and the computer's choice 4. Determine a winner (the user or the computer) 5. Inform the user who the winner is 1. As in previous projects, it's helpful to let other developers know what your program does. 2. Begin by including a multi-line comment that describes what your program will do. 3. 4. 5. This game will also require Python code that isn't built-in or readily available to us. Since the program will select Rock, Paper, or Scissors, we need to make sure the computer randomly selects one option. 6. Use a ​function import ​ to import ​rand int ​ from the ​rand om ​ module. 7. On the next line, use a function import to import ​sleep ​ from the ​time ​ module. 8. Great! We've imported the code we'll need. We won't use it right now, but we will need it later, so let's move on. 9. In this game, we know there are a few things that are constant (things that will not change). For example, the options (Rock, Paper, or Scissors) will remain constant, so we can add those options and store them in a variable. 10. On the next line, create a list called ​opti ons ​ and store ​"R" ​, ​"P" ​, and ​"S" ​ in the list (as strings). Abbreviating the options will come in handy later. 11. The user will always either win or lose, so the corresponding win/lose messages that we print to the user will also remain constant. 12. On the next line, create a variable and set it equal to ​"You lo st!" ​, or another message of your choice that indicates the user lost. 13. Note: Want to code like a professional? Variables that store constant information should be typed in ​snake case ​ and should be entirely uppercase, as indicated in the ​Python style guide ​. 14. On the next line, create a variable and set it equal to a winning message, similar to what you did in Step 5. 15. Since the user must select an option and the computer must also select an option, we need a way to decide who the winner is. 16. Add a function called ​deci de_w inne r ​. The function should take two parameters: ​user_ cho ice ​ and ​comp uter _cho ice ​ . 17. Great! Let's start building the ​deci de_w inne r ​function. 18. First, use ​string formatting ​ to print to the user's choice. Since the user's choice is already a parameter of the function, you can use the same parameter when using string formatting. 19. On the next line, print ​Comp uter sel ecti ng.. . ​and then have the program sleep for 1 second. 20. On the next line, use string formatting to print the computer's choice, similar to what you did in Step 8. 21. How will we compare the user's selection to the computer's selection? 22. Thankfully, we stored the options (Rock, Paper, and Scissors) in a list that will remain constant. Since ​items in a list all have an index ​, we can simplify how the comparison should take place: we will compare the index of the user's choice and the index of the computer's choice. 23. Now we have to figure out how will we determine the index of the user's choice. Lucky for us, lists have a built-in function called ​inde x() ​. 24. Given an item that belongs to a list, the ​inde x() ​function will return the index of that item. Read more about how ​inde x() ​ works ​here ​. 25. On the next line, create a variable called ​user _cho ice_ ind ex ​. Set the variable equal to the result of calling the ​inde x() ​ function on the ​opti ons ​ list. 26. The ​index() ​ function should take ​user _cho ice ​ as an argument. 27. On the next line, create a variable to store the index of the computer's choice. Set it equal to calling the ​index() ​ function on the ​options ​ list. The function should take the computer's choice as an argument. 28. Perfect! You just completed the most challenging part of the project. Now it's time to code the rules that will determine the winner. 29. Start by adding an ​if ​ statement that checks if the user's choice is equal to the computer's choice. 30. What happens when both players pick the same option? It's a tie! 31. Inside the if statement, print a message to the user informing them of the tie. 32. Now it's time to think of the scenarios in which players win or lose. 33. Wait a minute...there are many different scenarios, and they're going to take a long time to code. Part of being a professional programmer is figuring out fast and efficient ways of solving problems, like this one. 34. Let's approach this problem with a ​glass half full ​ mentality: we'll print only the scenarios in which the user wins, otherwise the user will have lost. 35. What are the scenarios in which the user wins? User: Rock, Computer: Scissors User: Paper, Computer: Rock User: Scissors, Computer: Paper 36. Each option has a constant index in the ​opti ons ​list, and we can use that to our advantage. 37. Add an ​elif ​ statement that checks if the user selects "Rock" ​and ​ the computer selects "Scissors." Inside the statement, print the win message. ​Remember, Rock has an index of 0 and Scissors has an index of 2. 38. Perfect! But that takes care of only one scenario where the user wins. 39. Add two more ​elif ​ statements that print the win message when the user wins. You can use the scenarios from Step 16 to help you. 40. What if the user's choice has an index greater than 2? That's garbage! Add one more ​elif ​ statement that checks for this condition. 41. Inside of the ​elif ​ block, print a message to the user that indicates that an invalid option was selected. On the next line, use ​retu rn ​ to exit the block. 42. Finally, we've taken care of all of the cases where the user could win. But what if none of these conditions are met? Remember from Step 16 that the user would lose. 43. Add an ​else ​ block and print the loss message inside of it. 44. Great! We have the function that will decide who the winner is between the user and the computer, but we haven't written a function that actually starts the game. Let's do that now. 45. Create a new function called ​play _RPS ​. 46. On the next line and within the function, print the name of the game to the user. 47. On the next line, we'll have to prompt the user for their selection. Store their selection in a variable called ​user _cho ice ​. 48. To make it simpler, we should ask them to input as few characters as possible for their selection. Prompt them with the message: ​Sele ct R for Ro ck, P fo r Paper, or S for Scis sors : 49. Then, on the next line, sleep the program for 1 second. 50. Convert the user's choice to uppercase. This will match the format used in the options ​ list we created earlier. 51. The computer has to play too! Remember, the computer's choice has to be random, so we'll make use of ​rand int ​ to accomplish that. 52. On the next line, create a variable called ​comp uter _cho ice ​. Set the variable equal to a random ​element of the options list ​ using ​rand int ​and the list indices. 53. Remember, ​this ​ is how the ​rand int ​ function works. 54. Actually, in the last step, we ​hard coded ​ the random possibilities of the ​options list, but what if there were more possible options in the list? It wouldn't be efficient to always have to open up the file just to change the indices in the one line of code you just wrote. 55. First, delete the line of code you wrote in the Step 24. 56. Create a variable called ​comp uter _cho ice ​. As in the last step, set it equal to a random element of the options list using ​rand int ​. However, instead of using ​0 and ​2 ​ in the ​rand int ​ function, use ​0 ​as the first integer, and use ​len( opt ions) -1 as the second integer. 57. This will ensure that if we ever add more options to the game, we won't have to change this line of code. (Of course, there might be more rules.) 58. Great! The user has now submitted their choice and the computer has also made a random choice. It's time to determine a winner. Thankfully, we already wrote a function that can do that. 59. On the next line, call the ​deci de_w inne r ​ function. Pass in ​use r_cho ice ​ as the first argument and ​comp uter _cho ice ​ as the second argument. 60. Our program won't run unless we call the correct function! On the next line, call the ​play_RPS() ​function. Make sure it's outside of any other function. 4. Py7 .3 P ro je ct: S hake sp eare an In su lt s Develop a program that will randomly generate twenty Shakespearean insults using the lists of words in the table below. Each insult will have four words beginning with "Thou" followed by one randomly chosen word from each of the three lists. An example of twenty Shakespearean insults is below. Put as many words as you want from each list below into separate lists in your Python code; you don't have to use every word in each list. Hints: 1. To generate a random integer you must import the random module and then call the randint function with lower and upper bounds as the arguments for the function. 2. When generating a random number for selecting a word out of your list, don't physically count the number of words in the list; use the length function to calculate the number of words in the list. This way if you add or subtract any words from a list, the adjustment for the random number will be updated automatically by the code. 3. Keep in mind that the upper-bound parameter for the randint function is will return numbers including the upper bound and we don't want that number chosen because list indices start at 0. For example, if your list has 10 words in it, and you use arguments of 0 and 10 for the randint function; if the number 10 was chosen, you would get the following error - IndexError: list index out of range. So you need to use 0 and 9 as randint arguments for 10 random integers. Thou c ra ve n c o m mon-k is sin g b um -b aile y Thou c h urlis h c o m mon-k is sin g b la dder Thou e rra nt b ase -c o urt b u m -b aile y Thou e rra nt c o m mon-k is sin g a pple -jo hn Thou c lo ute d b oil- b ra in ed b agga ge Thou b ootle ss c o m mon-k is sin g b o ar- p ig Thou b ootle ss b eetle -h ead ed a pp le -jo hn Thou e rra nt c la y-b ra in ed b agga ge Thou d is se m blin g b eetle -h e aded b la dd er Thou e rra nt c la y-b ra in ed a pple -jo hn Thou c h urlis h b oil- b ra in ed a p ple -jo h n Thou d is se m blin g b eetle -h e aded b um -b aile y Thou e rra nt b oil- b ra in ed b oa r-p ig Thou d is se m blin g c o m mon-k is sin g b um -b a ile y Thou c lo ute d b at- fr o w lin g b agga ge Thou c lo ute d b oil- b ra in ed b um -b aile y Thou c h urlis h b ase -c o urt a pple -jo hn Thou c lo ute d c o m mon-k is sin g b u m -b ail e y Thou c lo ute d c la y-b ra in e d b la dder Thou c ra ve n b at- fr o w lin g b agg age Lis t 1 Lis t 2 Lis t 3 artle ss base -c o urt apple -jo hn baw dy bat- fo w lin g bagg age bootle ss beetle -h e aded bla d der ch urlis h boil- b ra in ed boar-p ig clo ute d cla y-b ra in ed bum -b a ile y cra ve n co m mon-k is sin g ca nke r-b lo sso m dis se m blin g diz zy-e ye d co xco m b erra nt dre ad-b olt e d death -to ke n fa w nin g earth -v e xin g dew berr y fo bbin g elf - s kin ned fla p-d ra gon fr o th y fe n-s u cke d flir t- g ill im pertin ent fo ol- b orn gudg eon in fe ctio us fu ll- g org ed hagg ard ja rrin g guts -g rip in g harp y lo ggerh eade d half - fa ce d hedg e-p ig lu m pis h hasty -w it te d horn -b east paunch y ill- b re edin g lo ut ra nk onio n-e ye d min now sa ucy re elin g-rip e nut- h ook sp le eny ro ugh-h ew n pig e on-e gg sp ongy ru de-g ro w in g pig n ut villa in ous ta rd y-g ait e d str u m pet wayw ard to ad-s p otte d va ssa l ye asty weath er-b it te n wagta il 5. 11.3 P ro je ct: G eom etr ic S olid s Write a Python program with a class for rectangular prisms and a subclass for cubes that will calculate volume and surface area of these geometric solids. Use the specs below to guide you through the process. 1. Create a RectangularPrism class that has three instance variables for the three dimensions of a rectangular prism (length, width, and height). 2. Create a class method named volume that will return the volume of a rectangular prism. The formula for calculating the volume is to multiply the three dimensions. 3. Create another class method named surfaceArea that will return the surface area of a rectangular prism. The formula for calculating the surface area is to sum the areas of all six faces. 4. Create a Cube class that is a subclass of the RectangularPrism class. The Cube class only needs one argument since all three dimensions are the same length. Use the argument for each of the three dimensions. 5. Do not create new class methods for volume and surfaceArea in the Cube class because they are inherited from the RectangularPrism class. 6. Download and unzip the attached file. Either copy your code with the two classes to the top of this file or copy the code from this file to the bottom of your code. Add __repr__() methods to your classes so that when the program is run the output will look as shown below. Recta ngula r P ris m w it h le ngth 2 w id th 3 a nd h eig ht 4 Volu m e = 2 4 Sufa ce A re a = 5 2 Cube w it h s id e 2 Volu m e = 8 Sufa ce A re a = 2 4 6. Py1 3.1 P ro je ct: G ue ss t h e N um ber For this assignment you will be writing a program from scratch! Follow the directions posted below. Level 1 ​. Write a Python program that asks the user to guess a number between 0 and 100 and give feedback that tells the user the guess was too high or too low until they correctly guess the number. Level 2 ​. After the user correctly guesses the number, add output telling the user how many guesses it took. Level 3 ​. The range for guessing changes after each guess. For example if the user's first guess is 50 and the feedback is that the guess was to high, the next guess should be between 0 and 50. To help the user, update the new range for the guess every time they are asked for another guess. Level 4 ​. What if the user accidentally types a number that is not within then range? Provide feedback that the guess was outside the range and then do not change the range for the guesses when prompted for another guess. Let's also not count a guess outside the range in their total number of guesses. Level 5 ​. After the user correctly guesses the number, ask if they would like to play again. If the first letter of their response is 'y' or 'Y' start over with a range from 0 to 100 again. Hint: Put your current loop that gets user guesses inside another loop that starts the game over again. Level 6 ​. Each time the user guesses the correct number include feedback giving the fewest number of guesses needed to correctly guess the number (low/best score). Hint: You can initialize the low score at a really high number like 100 guesses. Below is an example of the output for this game. Welc o m e to G uess th e N um ber! Ple ase e nte r y o ur g uess b etw een 0 a nd 1 00. 5 0 Too lo w . Ple ase e nte r y o ur g uess b etw een 5 0 a n d 1 00. 2 5 Your g uess is n ot b etw een 5 0 a nd 1 0 0. Ple ase e nte r y o ur g uess b etw een 5 0 a n d 1 00. 7 5 Too lo w . Ple ase e nte r y o ur g uess b etw een 7 5 a n d 1 00. 8 5 Too h ig h. Ple ase e nte r y o ur g uess b etw een 7 5 a n d 8 5. 8 0 Congra tu la tio ns. Y ou g u esse d t h e n um ber in 4 g uesse s! Your lo w s co re is 4 g uess e s. Would y o u lik e to p la y a ga in ? y e s Ple ase e nte r y o ur g uess b etw een 0 a nd 1 00. 2 0 Too h ig h. Ple ase e nte r y o ur g uess b etw een 0 a nd 2 0. 3 Congra tu la tio ns. Y ou g u esse d t h e n um ber in 2 g uesse s! Your lo w s co re is 2 g uess e s. Would y o u lik e to p la y a ga in ? n o 7. 13.2 P ro je ct - D ic e P oke r Our goal is to write a game program that allows a user to play video poker using dice. The program will display a hand consisting of five dice. The basic set of rules is as follows: ● The player starts with $100. ● Each round costs $10 to play. This amount is subtracted from the user's money at the start of the round. ● The player initially rolls a completely random hand. ● The player gets two chances to enhance the hand by rerolling some or all of the dice. ● At the end of the hand, the player's money is updated according to the following payout schedule: ○ Two Pairs = $5 ○ Three of a Kind = $8 ○ Full House (A Pair and a Three of a Kind) = $12 ○ Four of a Kind = $15 ○ Straight (1-5 or 2-6) $20 ○ Five of a Kind = $30 For this assignment you will build the Dice class that will handle all the aspects of the dice such as rolling the dice, keeping track of the values, and returning the score for the dice. Follow the steps below to complete this part of the assignment. The rest of the game will be completed in the next assignment. 1. The Dice class implements a collection of dice, which are just changing numbers. The obvious representation is to use a list of five ints. Our contructor needs to create a list and assign some initial values. 1. Define a class named Dice. 2. Define an init method that has one parameter named "self." 3. In the init method, create an instance variable named dice that holds an empty list. 4. Create a loop that will execute its body 5 times. 5. In the body of the loop append a random number from 1 to 6 to the list. Remember that to refer to an instance variable you begin with "self" and then a dot. Also remember that you must import the random library to use random functions. 6. To test that your code so far, add the following temporary driver code to the bottom of your file and run the program. Make sure you don't indent because this code is not part of the Dice class. 1. han d = D ic e () # C re a te s a D ic e o b je ct 2. prin t h an d.d ic e # P rin ts t h e in sta n ce v a ria b le d ic e ( 5 r a n dom num bers ) 2. We need a method to roll selected dice. We can specify which dice to roll by passing a list of indexes. For example, roll([0, 2, 3]) would roll the dice in positions 0, 3, and 4 of the dice list. We just need a loop that goes through the parameter list and generates a new random value for each listed position. 1. Define an instance method named "roll" that takes one argument (besides self). Give the parameter an appropriate name to hold the list of indexes we need to roll. 2. Create a for loop that will traverse through the parameter list. 3. Inside the loop, change the dice for each index value in the list to a random number from 1 to 6. Remember that to refer to the instance variable you must precede it with self and a dot. 4. To test that the new method works properly, add the following lines of code to the driver code from earlier: 1. han d.r o ll( [0 ,2 ,3 ]) # C han ge t h e n um bers in in dex p osit io n s 0 , 2, a n d 3 . 2. prin t h an d.d ic e # P rin ts t h e in sta n ce v a ria b le d ic e ( 5 r a n dom num bers ) 3. Finally, we need a method to that will determine the worth of the current dice. We need to examine the values and determine whether we have any of the patterns that lead to a payoff. Let's return a string labeling what the hand is and an int that gives the payoff amount. We need to check for each possible hand in a sensible order to guarentee the correct payout. For example, a full house also contains a three of a kind. We need to check for the full house before checking for three of a kind, since the full house is more valuable. One simple way of checking the hand is to generate a list of the counts of each value. That is, counts[i] will be the number of times that the value i occures in dice. If the dice are: [3,2,5,2,3] then the count list would be [0,0,2,2,0,1,0]. Notice that counts[0] will always be zero since dice values are in the range 1-6. Checking for various hands can then be done by looking for various values in counts. For example, if counts contains a 3 and a 2, the hand contains a triple and a pair; hence, it is a full house. 1. Define a method named score that takes no arguments (must have parameter self). 2. Create a list named counts that has 7 zeros. Remember that index zero won't be used because dice have numbers 1-6. 3. Create a loop that traverses through the dice list. 4. Inside the loop add one to the appropiate index value in the counts list for each value in the dice list. When the loop is done, the counts list should have the number of times each value occurs in the dice list. 5. Create an if statement the checks for the highest score, Five of a Kind. If any of the values in the counts list is 5, then return the string "Five of a Kind" and the value 30 since Five of a Kind pays $30. Here is the first line of the if statement: if 5 in counts: Here is the body of the if statement: return "Five of a Kind", 30 6. Add to the if statement by adding the next option using elif to check if there are any values of 4 in the counts list. If so, return the appropriate string and payout from the information at the beginning of this assignment. 7. Add another elif for Full House. Hint: You must check for 3 in counts and 2 in counts. 8. Add another elif for Three of a Kind. 9. Add another elif for a Straight. This is a little tricky so I will give you the setup for the elif and explain it: elif not (2 in counts) and (counts[1] == 0 or counts[6] == 0): Since we have already checked for 5, 4, and 3 of a kind, checking that there are no pairs guarantees that the dice show five distinct values. If there is no 6, then the values must be 1-5; likewise, no 1 means the values must be 2-6. 10. Add another elif for Two Pairs. This has a little trick too so I will give you the setup for the elif: elif counts.count(2) == 2: 11. Add an else as the last option that returns "Garbage", 0 12. To test that the code you created works properly, add the following code to the previous driver code. You also may want to create a loop around all the driver code so multiple examples are printed. You may need to run many times to finally get a Straight and Five of a Kind. Remember that in the final game, the user will be able to improve their hand two times before the value of the hand is calculated. 1. prin t h an d.s c o re () # P rin t t h e t y p e o f h an d a n d it s v a lu e 8. 13.3 P ro je ct - D ic e P oke r P art 2 Our goal is to write a game program that allows a user to play video poker using dice. The program will display a hand consisting of five dice. The basic set of rules is as follows: ● The player starts with $100. ● Each round costs $10 to play. This amount is subtracted from the user's money at the start of the round. ● The player initially rolls a completely random hand. ● The player gets two chances to enhance the hand by rerolling some or all of the dice. ● At the end of the hand, the player's money is updated according to the following payout schedule: ○ Two Pairs = $5 ○ Three of a Kind = $8 ○ Full House (A Pair and a Three of a Kind) = $12 ○ Four of a Kind = $15 ○ Straight (1-5 or 2-6) $20 ○ Five of a Kind = $30 1. Now we are ready to turn our attention to the task of actually implementing the poker game. We know that the PokerApp will need to keep track of the dice and the amount of money. Let's initialize these values in the constructor. 1. Define a new class named PokerApp in the same file as the Dice class. 2. Inside the PokerApp define an init method that only has one parameter, self. 3. Inside the init method, create an instance of the Dice class, Dice(), and store the instance in an instance variable called dice. Remember to precede the instance variable with self and a dot. 4. Inside the init method, create an instance variable named money and initialize it to 100. Remember self-dot. 5. To test the PokerApp class and its contructor use the following driver code: 1. game = PokerApp() 2. print game.money 3. Printing the dice instance variable is a little more tricky. Try it by adding the following code to the driver code above: 1. print game.dice 2. This doesn't work because the dice instance variable is an object. To print the value inside the object you must use dot notation and call the instance variable on that object. Change the last line of code to: 1. print game.dice.dice 2. Now we want to loop the program allowing the user to continue playing hands until he or she is either out of money or chooses to quit. Sincee it costs $10 to play a hand, we can continue as long as the amount of money is at least $10. 1. Define a method called wantToPlay that has a parameter self. 1. Inside the method, use raw_input to ask the user "Do you wish to try your luck?" and store the result in a local variable named ans. 2. Now we need to see if the user responded with "yes" or "y". If the first letter of ans is uppercase or lowercase "y" then return True, otherwise return "False." Hint: The first letter of a string is index zero. 2. Define another method called run with a parameter, self. 1. Inside the method, ouput the following: You currently have $100. 2. Inside the method, create a loop that executes as long as the money balance is at least $10 and a call to the wantToPlay method is true. Don't forget the self-dot. 3. Inside the loop make a call to a method named playRound and send no arguments. 3. Most of the work of the program has now been pushed into the playRound method. Each round will consist of a series of rolls. Based on these rolls, the program will have to adjust the player's score. 1. Define the playRound method with only the self parameter. 2. Inside the playRound method, subtract 10 from the money. 3. Make a call to another instance method called doRolls that takes no arguements. This method will be in charge rolling the dice and rerolling if the user chooses. We will write this method in the next section. 4. When control returns from the doRolls method we will have the final hand to be played so we need to score the hand by calling the score method in the dice class. To do this we must use call the method using the dice instance variable (don't forget the self-dot). The score method will return two values: the type of hand and the payout. So here's how it will look: 1. result, score = self.dice.score() 5. Print the values returned by the score method according to this sample output: Full House. You win $12. 6. Add the payout to the player's money. 7. Print the new amount player money according the following sample output: You currently have $102. 4. Finally, we are down to the nitty-gritty details of implementing the dice rolling process. Initially, all of the dice will be rolled. Then we need a loop that continues rolling user-selected dice until either athe user chooses to quit rolling or the limit of three rolls is reached. 1. Roll all the dice using the roll method in the Dice class. 2. Create a local variable to keep track of the roll number. Initialize this variable to 1 since we are on the first roll. 3. Print the roll of the dice using the following sample: Dice: [2, 3, 2, 1, 5, 5] 4. Get input from the user asking for which dice to reroll and store in a local variable named toRoll: toRoll = input("Enter list of which to change ([] to stop) ") 5. Create a loop that will execute as long as the roll count is less than three and the user didn't type in an empty list to stop. 1. Inside the body of the loop, call the roll method of the dice class rolling the dice the user selected. 2. Increment the roll count by 1. 3. Output the new hand of rolled dice. Use the same code as earlier. 4. Create a conditional statement that asks the user if they want to roll again but only if the roll count is still less than three. 5. Your PokerApp class should now be complete. To run the game you should only need to create a PokerApp object and then call its run method. These commands should not be part of the class and therefore should not be indented. 1. game = PokerApp() 2. game.run()