Question

In: Computer Science

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

-

Solutions

Expert Solution

RAW CODE

import random

random_number = random.randint(1,1000)

print("Welcome to random number game")
guessed_values = [] ### List is made to keep track of the guessed values
while(1): ### Infinite loop, stops only when breaked
    number = int(input("Pick a number between 1-1000: "))
    if number in guessed_values: ### If number in the list, then tell that number is repeated.
        print("You are repeating this number, you aleardy tried it")
        guessed_values.append(number)
    elif number == random_number:
        print("Wow! You guessed it Right")
        print("Total_lose = ${}".format(len(guessed_values)*50))
        break #### Game ends when guessed right
    elif number > random_number:
        print("Pick a lower number")
        guessed_values.append(number)
    else:
        print("Pick a higher number")
        guessed_values.append(number)

SCREENSHOTS (CODE WITH OUTPUT)

CASE 1 (WITHOUT REPETITION)

CASE 2 (WITH REPETITION)

RAW CODE (NOT FOLLOWING HINTS)

import random

random_number = random.randint(1,1000)

print("Welcome to random number game")
guessed_values = [] ### List is made to keep track of the guessed values
count = 0
while(1): ### Infinite loop, stops only when breaked
    number = int(input("Pick a number between 1-1000: "))
    if number in guessed_values: ### If number in the list, then tell that number is repeated.
        guessed_values.append(number)
        count += 1
        if count == 1:
            print("Warning! Repeated value ($10 will be deducted from next attempt for every repeated value)")
        if count > 1:
            print("Repeated Value, $10 deducted")
            
    elif number == random_number:
        print("Wow! You guessed it Right")
        print("Total_lose = ${}".format(len(guessed_values)*50 + (count-1) * 10))
        break #### Game ends when guessed right
    elif number > random_number:
        print("Pick a lower number")
        guessed_values.append(number)
    else:
        print("Pick a higher number")
        guessed_values.append(number)

SCREENSHOTS (CODE WITH OUTPUT)

NOTE:- In this $10 is deducted every time on repeating value after the first warning. Eg:- If 2 times repeated after warning, then $20 panelty added in last.

##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####


Related Solutions

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...
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...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack,...
PYTHON BEGINNER Problem Create a program that lets the user play a simplified game of Blackjack, which is played between the user and an automated dealer as follows. The dealer shuffles a standard deck of 52 cards, draws two cards, and gives them to the user. The user can then choose to request another card from the dealer, adding it to their hand. The user can continue to request cards or choose to stop at any time. After each time...
Python! Create a program that does the following: Reads a number from the user. Calls a...
Python! Create a program that does the following: Reads a number from the user. Calls a function that finds all the divisors of that number. Calls another function to see if the number 7 is a divisor of the original number. Keeps reading input from the user and calling the function above until the user enters the letter ‘q’. Create 2 functions findDivisors() and lucky7(). Use docstrings to explain what each function does. Use the help() function to output the...
Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Time Calculator Create a C++ program that lets the user enter a number of seconds and...
Time Calculator Create a C++ program that lets the user enter a number of seconds and produces output according to the following criteria: • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
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...
Create an application that makes the user guess a number. The user must be allowed tries....
Create an application that makes the user guess a number. The user must be allowed tries. You must have a loop, user input (Scanner), and a constructor. (JAVA)
In Python: Design a program that lets the user enter the total rainfall for each of...
In Python: Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT