用python写一个猜数字游戏的代码
```
import random
 
random python
# Generate a random number between 1 and 9
random_number = random.randint(1,9)
 
guess_number = 0
count = 0
 
while guess_number != random_number and count < 3:
    guess_number = int(input("Guess the number: "))
    if guess_number > 0 and guess_number < 10:
        if guess_number > random_number:
            print("Number is less than " + str(guess_number))
        elif guess_number < random_number:
            print("Number is greater than " + str(guess_number))
    else:
        print("Enter a valid number!")
    count += 1
   
if guess_number == random_number:
    print("You guessed it correctly!")
else:
    print("Sorry! The number is " + str(random_number))
```

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。