#π Guys i got a simple project it works fine but i need a professional review can you help me
22 messages Β· Page 1 of 1 (latest)
@light ivy
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.
@light ivy where is it?
I can send it in dms
you have to post it here.
Δ°ts too large for here
!paste
So that everyone can easily read your code, you can paste it in this website:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
maybe you can come back when you're at your desktop or laptop.
guessing_game.py
import random
import time
secret_number = None
guess = 0
guess_counter = None
hints_left = None
while True:
secret_number = random.randint(1, 100)
start_time = time.time()
hints_left = 3
guess_counter = 0
def first_hint():
if secret_number > 50:
print("The secret number is greater than 50")
else:
print("The secret number is smaller than 50")
def second_hint():
if secret_number % 2 == 1:
print("The secret number is odd. ")
elif secret_number % 2 == 0:
print("The secret number is even. ")
def third_hint():
if secret_number % 3 == 0:
print("The number is divisible by 3. ")
else:
print("The number is not divisible by 3. ")
while guess != secret_number:
try:
guess = int(input("Guess a number 1-100 (type 0 for a hint): "))
if guess == 0:
if hints_left == 3:
first_hint()
elif hints_left == 2:
second_hint()
elif hints_left == 1:
third_hint()
elif hints_left == 0:
print("No more hints! ")
hints_left = hints_left - 1
print(f"Hints remaining: {hints_left}")
continue
guess_counter = guess_counter + 1
if guess == secret_number:
end_time = time.time()
total_time = int(end_time - start_time)
print("Correct! You win!")
if guess_counter == 1:
print("You are so lucky, you got it first try! ")
else:
print(f"you guessed the right number in {guess_counter} times")
print(f"Time: {total_time} seconds!")
elif guess < secret_number:
print("Too low!")
else:
print("Too high!")
except ValueError:
print("Please enter a valid answer")
want_to_play = input("Do you want to play again? (y/n): ")
if not want_to_play.lower() == "y":
break
print("Thank you for playing")
This is my code if you want to help ty
you should turn first_hit, second_hit, etc. into functions that take secret_number as an argument. and you should move them out of the loop.
!code
When those functions were out of the loop they only did the secret number out of the loop and i dont want that cus i got if you want to play again y or n
have you written functions with parameters before?
Just to be clear Im new to python no I donβt think so
Anyways i hust asked ai and it totally agreed with you and explained why so tysm
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.