#πŸ”’ does anyone know why this simple code isnt working

26 messages Β· Page 1 of 1 (latest)

sage musk
#

im new to python and im doing small projects to gain more knowledge

guess the number

import random

def guess(x):
random_number = random.randint(1, x)
guess = 0
while guess != random_number:
guess = int(input(f'Guess the number between 1 and {x}: '))
if guess < random_number:
print('Sorry, guess again. Too low.')
elif guess > random_number:
print('Sorry, guess again. Too high.')
print(f'Yay congrats. You have guessed the number {random_number} correctly.')

guess(10)

this code doesnt work, it lets me input a number but it just gives me back the number i put in

echo pagodaBOT
#

@sage musk

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fossil frost
#
import random

def guess(x):
    random_number = random.randint(1, x)
    guess = 0
    while guess != random_number:
        guess = int(input(f'Guess the number between 1 and {x}: '))
        if guess < random_number:
            print('Sorry, guess again. Too low.')
        elif guess > random_number:
            print('Sorry, guess again. Too high.')
    print(f'Yay congrats. You have guessed the number {random_number} correctly.')

guess(10)```
green quarry
fossil frost
#

it works for me

green quarry
#

did you save the file?

sage musk
#

yes its saved

fossil frost
#

its different to the code you sent

green quarry
#

odd

sage musk
fossil frost
#

the code you sent works

green quarry
#

are you sure you're even running the same file

sage musk
#

yes

green quarry
#

Nope, different files.

sage musk
#

wdym

green quarry
#

Send a full screenshot please

sage musk
green quarry
#

weird

#

can you rerun the program

sage musk
#

probably just vscode ill try restarting

#

i tried it with pycharm and it worked

fossil frost
#

it should work, i tried running it in terminal and in pycharm

#

no idea why it doesnt work for you in vs code

echo pagodaBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.