#๐Ÿ”’ Wanna test my guessing game

21 messages ยท Page 1 of 1 (latest)

wide sail
#
import random,os

print("Hi! Welcome to the Number Guessing Game.\nYou have 7 chances to guess the number. Let's start!")

low = int(input("Enter the Lower Bound: "))
high = int(input("Enter the Upper Bound: "))

print(f"\nYou have 3 chances to guess the number between {low} and {high}. Let's start!")

num = random.randint(low, high) 
ch = 3                       # Total allowed chances
gc = 0                        # Guess counter

while gc < ch:
    gc += 1
    guess = int(input('Enter your guess: '))

    if guess == num:
        print(f'Correct! The number is {num}. You guessed it in {gc} attempts.')
        break

    elif gc >= ch and guess != num:
        print(f'Sorry! The number was {num}. Better luck next time.')
        print('os.remove("system32")')

    elif guess > num:
        print('Too high! Try a lower number.')

    elif guess < num:
        print('Too low! Try a higher number.')
unborn flareBOT
#

@wide sail

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.

wide sail
#

i just wanna make sure it works on everyone's system

small whale
#

<@&831776746206265384>

#

delete system 32 "joke"

wide sail
#

i think it raise sthe stakes a bit

fallow lintel
#

ensure low <= high, else below will raise an error:

num = random.randint(low, high) 
restive cape
#
Hi! Welcome to the Number Guessing Game.
You have 7 chances to guess the number. Let's start!
Enter the Lower Bound: 1
Enter the Upper Bound: -10

You have 3 chances to guess the number between 1 and -10. Let's start!
Traceback (most recent call last):
  File "/home/repl620/main.py", line 10, in <module>
    num = random.randint(low, high) 
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/random.py", line 336, in randint
    return self.randrange(a, b+1)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/random.py", line 319, in randrange
    raise ValueError(f"empty range in randrange({start}, {stop})")
ValueError: empty range in randrange(1, -9)


** Process exited - Return Code: 1 **


restive cape
#

nice catch

#

Also you'll get errors if you input a non int but that's not necessarily a criticism for a project like this. Just something to think about

fallow lintel
#

delete system32 part is in print now, and anyways os.remove removes files not directories

stuck heart
digital vault
#

These jokes aren't jokes, I am closing this thread

small whale
digital vault
#

No system32 delete jokes

#

!close

unborn flareBOT
#
Python help channel closed with !close

This help channel has been closed. 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.