Random Number Game and Removing Numbers

Viewed 26

I'm trying to create a random number game in Python which the computer starts by giving a random number from 1 to 10 and then consecutively, the computer and the user can remove a few numbers. The person that removes the last number to 0 loses.

An example of the output that I imagine is like this:

The starting number is: 5
computer removes: 3
2 numbers are left
User removes: 1
1 number is left
computer removes 1
user wins!

What functions can I use to perform the removing task?

1 Answers

You can use

import random
random.randint(0, 10)

to create a random integer and assign it to a variable. And the same function to subtract a random value.

You can use input() to ask a user for their input.

Related