Question

In: Computer Science

Write code for a game of picking match sticks. You must make sure that the computer...

Write code for a game of picking match sticks. You must make sure that the computer always wins. The game is as follows

There are 26 matchsticks initially. The computer will ask the user to pick anywhere between 1 and 4 matchsticks. The player (whether the user or the computer) who has to pick up the last matchstick (or matchsticks) is the loser. You will have to use a combination of branching and looping commands with appropriate prompts and the input() function.

Hint: The computer will always win if you code appropriately. When coding consider the following:

1. You must first print a statement to the screen which explains the game

2. You must print the remaining matchsticks after each round

3. You must finally print the final statement about who won the game.

In order to always ensure that the computer wins: the sum of the matchsticks chosen by the user and the computer should equal 5.

NB: Include picture of python code

Solutions

Expert Solution

print('Rules:')
print('1. There are 26 matchsticks initially')
print('2. In each turn, a player picks anywhere between 1 and 4 matchsticks')
print('3. The player who has to pick up the last matchstick (or matchsticks) is the loser')
current = 26
k=1
loser=1
print('Matchsticks at the start:',current)
while current>0:
print('\nRound:',k)
user=int(input('Pick number of matchsticks: '))
current-=user
if current<=0:
loser=0
else:
print('Computer picks {} matchsticks'.format(5-user))
current-=(5-user)
if current<=0:
loser=1
else:
print('End of round {}, remaining matchsticks: {}'.format(k,current))
k+=1
if loser==0:
print('You lose!! Computer wins')
else:
print('Computer loses! You win!!!')
  
  
  


Related Solutions

The following flow chart is a bubble sort. Write the code for this sort. Make sure...
The following flow chart is a bubble sort. Write the code for this sort. Make sure you display each pass and comparison. Include comments.
--- Note: to save time, write the code directly on Moodle and make sure to save...
--- Note: to save time, write the code directly on Moodle and make sure to save your code frequently Write a complete Java code that contain two classes. A GradeBook and a GradeBookTester. - The GradeBook class contains the followings: - An array of grades (integer array) declared as a field. - A constructor that takes an integer value as parameter (len), and creates the grades array of size equals to len. - A method called fillArray that fills the...
* Make sure you turn in your code (take a screen shot of your code in...
* Make sure you turn in your code (take a screen shot of your code in R)and answers. Conduct the hypothesis and solve questions by using R. 2) A random sample of 12 graduates of a secretarial school averaged 73.2 words per minute with a standard deviation of 7.9 words per minute on a typing test. What can we conclude, at the .05 level, regarding the claim that secretaries at this school average less than 75 words per minute on...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is...
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Prove that a complement of any finite set of binary strings F has a decidable membership. Will such F always be recursive?
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Prove that for any positive integer k, the open line segment (1/2k+1, 1/2k) contains uncountably many real numbers. You must apply Cantor’s diagonalization directly, i.e., you cannot base your proof on the fact that the line segment (0, 1) contains uncountably many reals (hint: think in binary).
Computer Science: Please be sure to make sure answer is legible if answer is written. :)...
Computer Science: Please be sure to make sure answer is legible if answer is written. :) Is the set of total Boolean-valued functions, i.e., those whose range is T or F, countable? Prove your answer.
For this problem, you will write a program in which the computer plays a dice game...
For this problem, you will write a program in which the computer plays a dice game called Craps. You might need to explore some Python documentation on random() for this homework assignment. PROVIDE A GRAPHICAL FLOWCHART as part of your submission for this solution Rules: The player rolls two six-sided dice. After rolling, the sum of what the dice show is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is...
Code the game of Rock, Paper, Scissors between a human player and the computer. You can...
Code the game of Rock, Paper, Scissors between a human player and the computer. You can check out the game on Wikipedia if you are not familiar with it. Create a 4 option menu with the human player choices, plus the option of exiting the game. Randomly determine the computer’s choice (although a great deal of AI research has gone in to determining the best computer move). • Loop the game until the human player exits. • Count the number...
Part I: Constructing proofs. You must write down all proofs in acceptable mathematical language: make sure...
Part I: Constructing proofs. You must write down all proofs in acceptable mathematical language: make sure you mark the beginning and end of the proof, define all variables, use complete, grammatically correct sentences, and give a justification for each assertion (e.g., by definition of…). Definitions: • An integer ? is even if and only if there exists an integer ? such that ? = 2?. • An integer ? is odd if and only if there exists an integer ?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT