Question

In: Computer Science

In python please write the following code the problem. Write a function called play_round that simulates...

In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.

Solutions

Expert Solution

Here is the complete code for the given function in Python. I have added comments for a better understanding of the same:

import random

def play_round(player1, player2):

  while(True):

    c1 = random.randint(1,13) # Player 1 draws a card

    c2 = random.randint(1,13) # Player 2 draws a card

    if(c1 < c2):

      return player2 + ' wins!' # Player 2 has higher card

    elif(c2 < c1):

      return player1 + ' wins!' # Player 1 has higher card

Sample Run:

You can comment below the answer in case of any doubts and I will be happy to help.

Please give a thumbs up if the answer could be of help!

All the best!


Related Solutions

Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Write a small section of Python code that defines a function called check_even(value) - the function...
Write a small section of Python code that defines a function called check_even(value) - the function takes a numerical value as input and returns True or False based on whether the provided argument is divisible by 2 (i.e. is it odd or is it even). If the argument provided is not a number (as determined by built-in the isdigit() function - which only works on string data) then rather than crashing, the function should raise an exception which is caught...
In Python write a function that simulates the throwing of any even numbered dice which will...
In Python write a function that simulates the throwing of any even numbered dice which will be passed on as a parameter: customDice(sides). The function will return a random number rolled for that particular type of dice. Write the program that will utilize the customDice function with the following specification: Ask the user to pick which even-sided dice to use. The program will then roll the dice twice. If the total of both rolls is greater than the number of...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should have #two parameters: a dictionary and a string. The string may be #a key to the dictionary. The value associated with that key, #in turn, may be another key to the dictionary. # #Keep looking up the keys until you reach a key that has no #associated value. Then, return that key. # #For example, imagine if you had the following dictionary. #This one...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel...
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel and returns the transmitted signal.. SimpleChannel function will add a randomly generated noise (look for “rand” function) to the signal and return it. You can adjust the amplitude of the noise as you want in order to have a distinct noise effect. Then write another matlab code to show the channel noise. First create the signal and then simulate the channel by using your...
Please write in Python code Write a program that stores the following data in a tuple:...
Please write in Python code Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices
Python 3.7: Give the following sample code, write the following programs: • An iterator class called...
Python 3.7: Give the following sample code, write the following programs: • An iterator class called Iteratefirstn that implements __iter__() and __next__() methods where next method should raise an exception for the cur index if it is passed the last element otherwise set cur index to the next index and advance the index by one, i.e. cur, num = num, num+1. Instantiate the class to calculate the sum of 1000000 elements similar to the example. • Instead of implementing the...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an int. The function should return a tuple containing that int and its square. Suppose you were to call your function like this: print(make_squares_coordinate_pair(5)) This should output: (5, 25) Your function MUST be called make_squares_coordinate_pair. You can write code in the main part of your program to test your function, but when you submit, your code must ONLY have the function definition! 2, Write a...
Please use Python for both Concatenate List Elements Write a function called concat_list that accepts a...
Please use Python for both Concatenate List Elements Write a function called concat_list that accepts a list of strings as an argument and returns a string made up of all elements in the list concatenated together in order. For example, if the argument is ['one', 'two', 'three'], the return value would be 'onetwothree'. Remove List Duplicates Write a function called remove_duplicates that accepts a list and returns a list containing the same elements in the same order but with duplicates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT