Question

In: Computer Science

Think a Number Bob and Alice play a game in which Bob gives Alice a challenge...

Think a Number Bob and Alice play a game in which Bob gives Alice a challenge to think of any number M between 1 to N. Bob then tells Alice a number X. Alice has to confirm whether X is greater or smaller than number M or equal to number M. This continues till Bob finds the number correctly. Your task is to find the maximum number of attempts Bob needs to guess the number thought of by Alice

Solutions

Expert Solution

import random

def numberGame():

#bob being the computer think of a random number between 1 to 108 as per question specification

n = random.randint(1, 108)

attempts = 0

#alice being u guess the number

x = int(input("X: "))

#untill entered number and the gueses number are equal alice keep guessing

while x != n:

#if n is greater then the current guessed number inform alice

if x > n:

print("lesser!")

elif x < n:

print("greater!")

else:

print("Number is ", x)

break

#keep counting the number of attempts

attempts += 1;

#guess next number

x = int(input("try again :"))

print("Number of attempts: ", attempts)

def main():

numberGame()

if __name__ == "__main__":

main()

please don't forget to upvote.Thankyou


Related Solutions

:) Alice and Bob play the following game: in each round, Alice first rolls a single...
:) Alice and Bob play the following game: in each round, Alice first rolls a single standard fair die. Bob then rolls a single standard fair die. If the difference between Bob’s roll and Alice's roll is at most one, Bob wins the round. Otherwise, Alice wins the round. (a) (5 points) What is the probability that Bob wins a single round? (b) (7 points) Alice and Bob play until one of them wins three rounds. The first player to...
Alice and Bob play the following game. They toss 5 fair coins. If all tosses are...
Alice and Bob play the following game. They toss 5 fair coins. If all tosses are Heads, Bob wins. If the number of Heads tosses is zero or one, Alice wins. Otherwise, they repeat, tossing five coins on each round, until the game is decided. (a) Compute the expected number of coin tosses needed to decide the game. (b) Compute the probability that Alice wins
PLEASE DO NOT COPY OTHERS ANSWER, THANK YOU! Alice and Bob play the following game: in...
PLEASE DO NOT COPY OTHERS ANSWER, THANK YOU! Alice and Bob play the following game: in each round, Alice first rolls a single standard fair die. Bob then rolls a single standard fair die. If the difference between Bob’s roll and Alice's roll is at most one, Bob wins the round. Otherwise, Alice wins the round. (a) (5 points) What is the probability that Bob wins a single round? (b) (7 points) Alice and Bob play until one of them...
Alice and Bob are playing a game in which each of them has three strategies, A,...
Alice and Bob are playing a game in which each of them has three strategies, A, B, or C. If their choices do not match (e.g., if Alice picks B and Bob picks C), then no money is exchanged; otherwise Alice pays Bob $6 (if they both choose A), or $3 (if they both choose B), or $1 (if they both choose C). Is this a zero-sum game? Find a mixed-strategy Nash equilibrium for it. Is this the only equilibrium...
Alice and Bob bet 50 dollars with each other in a game in which their friend...
Alice and Bob bet 50 dollars with each other in a game in which their friend Charlie tosses a two-sided coin 3 times in a remote location. If Alice correctly predicts the majority face (i.e. the face which occurred the most often in the three tosses), she gets to keep Bob's money as well. Charlie calls them and lets them know that at least 1 heads has occurred.a) Assuming that the coin was fair, what is the probability that the...
Question 1 - Game Theory (7 Marks) Alice and Bob are playing a game of simultaneous...
Question 1 - Game Theory Alice and Bob are playing a game of simultaneous moves where they are deciding which concert they will attend on Saturday night. Two musicians are performing that night locally, Artist 1 and Artist 2. Alice prefers to go to Artist 1 with Bob rather than Artist 2 with Bob, and she prefers going to Artist 2 with Bob rather than going to Artist 2 alone. Moreover, she prefers going to Artist 1 alone rather than...
Now assume that Alice and Bob are twins, and Alice left Earth and Bob stayed behind...
Now assume that Alice and Bob are twins, and Alice left Earth and Bob stayed behind fixing his spaceship. If Alice spent some time moving near the speed of light before returning to Earth, which statement is correct when Alice returns to Earth? a. Alice will say that she is younger than Bob, and he will agree. b. Bob will say that he is younger than Alice, and Alice will say that she is younger than Bob. c. Alice will...
Alice and Bob are supposed to meet in the cafeteria. Alice arrives at a random time...
Alice and Bob are supposed to meet in the cafeteria. Alice arrives at a random time between noon and 1pm, and wait for 15 minutes upon her arrival and then leaves. Bob also also arrives at a random time between noon and 1 pm, but waits up to 20 minutes and then leaves. (a) What is the probability that Bob arrives before 12:20? (b) What is the probability that Alice and Bob meet? (c) If Bob arrives later than Alice,...
Alice and Bob visit the gym on Saturday for their hourlong workouts. Alice always arrives between...
Alice and Bob visit the gym on Saturday for their hourlong workouts. Alice always arrives between 2:00 and 3:00 and Bob between 2:30 and 3:30. Assuming their arrival times are drawn independently and uniformly from the specified intervals (i.e. any arrival time in the given window is equally likely), and assuming they each stay for precisely one hour, what is the probability that on any given Saturday there exists a moment in time when all two are present at the...
Both Alice and Bob toss a fair coin three times. The probability that Alice records a...
Both Alice and Bob toss a fair coin three times. The probability that Alice records a different numbers of heads than Bob is given by A/B, where A and B are relatively prime integers (greatest common divisor is 1). Find A + B.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT