In: Computer Science
lets say i make a PYTHON code that lets a user guess a number between 1-1000, every failed attempt you get a hint (go lower or go higher) how can i penalize the user if they dont follow the hints, example ( go higher!... your next pick: a smaller number... 2 you loose $100 for not following hint) 2 and the user has unlimited attempts, until he guesses the number, this is made using random.randint(1,1000) function THE ONLY THING IM MISSING IS THE PART IN BETWEEN THE 2'S
import random
random_number = random.randint(1,1000)
#comment the bellow line to prevent print the random number
print(f"The Random Number is {random_number} for debugging purpose")
money_loose = 0
user_number = int(input("Guess the Number: "))
while True:
if random_number == user_number:
print("Hurrah, You Got The Correct Number")
print(f"Total Money loose = ${money_loose}")
break
while random_number > user_number:
new_input = int(input("Nope..!!, Go Higher. Enter Again: "))
if user_number >= new_input:
#do what ever you want to do to deduct money
print("You didn't obey the hint, -$100")
money_loose = money_loose + 100
user_number = new_input
while random_number < user_number:
new_input = int(input("Nope..!!, Go Lower. Enter Again: "))
if user_number <= new_input:
#do what ever you want to do to deduct money
print("You didn't obey the hint, -$100")
money_loose = money_loose + 100
user_number = new_input