Question

Hi, I need help in solving Python programming problem below:

When John gambles at the casino, he always uses a special system of tactics that he devised himself. Its based on always bet

Given N = 8 and K = 0, the answer is 7. K is 0 so John bets 1 chip in each round. The number of chips were as follows: at the

Given N = 10 and K = 10, the answer is 4. The shortest game would be: at the beginning: 1 after the 1st round: 2 (he bet 1) a

Thank you.

Best Regards

2 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: I am posting code and its outputs. Please comment in case of any modifications.

def fun(n,k):
    allin = 0
    d1 = dict()
    while(1):
        if n==2:
            d1[n] = "he bet 1"
            break
        if n%2==0 and allin<k:
            d1[n] = "all in"
            allin+=1
            n=int(n/2)
        else:
            d1[n] = "he bet 1"
            n-=1
    print("at the beginning: 1\n")
    count=1
    for key in sorted(d1):
        if count%10==2:
            temp = str(count)+"nd"
        elif count%10==3:
            temp = str(count)+"rd"
        elif count==1:
            temp = str(count)+"st"
        else:
            temp = str(count)+"th"
        print("After {} round: {} ({})".format(temp,key,d1[key]))
        count+=1

    print("\nHe played all-in {} times".format(allin))


print("Enter N and K: ")
a = [int(x) for x in input().split()]
fun(a[0],a[1])

Code Pic:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 def fun(n, k): allin = 0 d1 = dict() while(1): if n==2: d1[n] = he bet 1 break if n%2==0 aOutput:

Enter N and K: 234 23 at the beginning: 1 After 1st round: 2 (he bet 1) After 2nd round: 3 (he bet 1) After 3rd round: 6 (all

Add a comment
Answer #2
public class Solution3 
{
   public int solution(int N, int K)
   {
      int n=N;
      int k=K;
      int rounds=0;
      System.out.println(n);
      while ( n>1 )
      {
         if (n % 2 == 0 && k>0)
         {
            n >>= 1;
            k--;
         }
         else
         {
            n--;
         }
         System.out.println(n);
         rounds++;
      }
      return rounds;
   }


Add a comment
Know the answer?
Add Answer to:
Hi, I need help in solving Python programming problem below: Thank you. Best Regards When John...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.....

    Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.. A non-empty array A consisting of N integers is given. You can perform a single swap operation in array A. This operation takes two indices I and J, such that 0 S13 J<N, and exchanges the values of A[i] and A[J]. The goal is to check whether array A can be sorted into non-decreasing order by performing at most one swap operation. For example,...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • I really need help with this python programming assignment Program Requirements For part 2, i need...

    I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n):   lst = []   for i in range(1,n+1):     val = float(input('Enter float '+str(i)+': '))     lst.append(val)   return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • 1) Let x be a continuous random variable that is normally distributed with a mean of...

    1) Let x be a continuous random variable that is normally distributed with a mean of 21 and a standard deviation of 7. Find to 4 decimal places the probability that x assumes a value a. between 24 and 30. Probability = b. between 17 and 31. Probability = ------------------------------------------------------------------------------------------------------------------------------------------------------ 2) Let x be a continuous random variable that is normally distributed with a mean of 65 and a standard deviation of 15. Find the probability that x assumes a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT