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.')
#๐ Wanna test my guessing game
21 messages ยท Page 1 of 1 (latest)
@wide sail
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.
Closes after a period of inactivity, or when you send !close.
i just wanna make sure it works on everyone's system
how did that get there
i think it raise sthe stakes a bit
ensure low <= high, else below will raise an error:
num = random.randint(low, high)
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 **
you beat me to it!!!
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
delete system32 part is in print now, and anyways os.remove removes files not directories
agree
bro its not that deep lol they just printed it out
These jokes aren't jokes, I am closing this thread
They edited it. Before the edit they even specified a more specific filepath
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.