Question

In: Computer Science

lets say i make a PYTHON code that lets a user guess a number between 1-1000,...

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

Solutions

Expert Solution

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


Related Solutions

Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i used random.randint(1,1000) -must give hints like (pick a lower/higher number) which i already did -tell the user when he has repeated a number (help) -the game only ends when you guess the number (help) -you loose $50 every failed attempt (done) ****I did it as a while loop -
Project 5-3: Guessing Game Create an application that lets a user guess a number between 1...
Project 5-3: Guessing Game Create an application that lets a user guess a number between 1 and 100. Console Welcome to the Guess the Number Game ++++++++++++++++++++++++++++++++++++ I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 You got it in 1 tries. Great work! You are a mathematical wizard. Try again? (y/n): y I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 Way too high! Guess...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT