0

File "", line 1, in ValueError: source code string cannot contain null bytes Remainder of file ignored

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 
! !
6
  • 1
    your code is not understandable... please explain what do you want to do Commented Aug 4, 2022 at 17:21
  • 2
    and it has syntactically error in while head, you are not allowed to use = in while head Commented Aug 4, 2022 at 17:22
  • I am just letting My computer guess a number !! I am trying this demo from the Freecodecamp channel !! Commented Aug 4, 2022 at 17:29
  • 1
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='? the python error tells you exactly what's wrong ... Commented Aug 4, 2022 at 17:36
  • File "<string>", line 1, in <module> ValueError: source code string cannot contain null bytes Remainder of file ignored Commented Aug 5, 2022 at 19:30

1 Answer 1

1

if you want to computer guess a number, you can use:

import random
random.randint(1, 10)

or, if you want to get a guess from user:

x = 10
input(f'Guess a number between 1 and {x}')

and if you want to computer always guess a number untill it can find user input:

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)

or, human guess what computer selected:

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.