文件";,第1行,在ValueError:源代码字符串不能包含null字节已忽略文件的剩余部分
def guess(x):
random_number = random.randint(1, x)
guess= 0
while guess = input (f'Guess a number beween 1 and %x')
guess(10)```
I am running this code in PyCHarm community edition !!
Please Help !
I am not to find this solution eventhough I tried multiple Sources
! !
如果你想用计算机猜一个数字,你可以使用:
import random
random.randint(1, 10)
或者,如果你想从用户那里得到一个猜测:
x = 10
input(f'Guess a number between 1 and {x}')
如果你想用电脑猜一个数字,直到它能找到用户输入:
import random
def guess(x):
number = int(input(f'Guess a number between 1 and {x}'))
while True:
num = random.randint(1, x)
print(num)
if num == number:
break
guess(10)
或者,人类猜测计算机选择了什么:
import random
def guess(x):
number = random.randint(0,x)
while True:
user_num = int(input(f"Guess a number between 0 and {x}:"))
if user_num == number:
print("You guessed it!")
break
guess(10)