Question

In: Computer Science

I need to write PYTHON program which is like a guessing game using randint function which...

I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the next try you also pick 1) also you start with $600, every failed attempt you loose $100 and if you reach $0 the next failed attempt you must get $-100 and so on... i was using a while loop but the loop wont run properly, this is supposed to be basic code, but i cant get it to work

Solutions

Expert Solution

Code

import random

n=random.randint(1,1000) #generate random number
v=600
l=[]
while True:
  a=int(input("guess the number: "))
  if a==n: #break if found the answer
    print(n,"is the correct answer")
    print("Final amount you got is:",str(v)+"$")
    break
  if a in l: #if previously picked
    print("You already picked",a)
    v=v-100
  else:
    if a<n: #less than the answer
      print(a,"is less than the amswer")
      v=v-100
      l.append(a)
    else: #greater than the answer
      print(a,"is greater than the answer")
      v=v-100
      l.append(a)

Terminal Work

.


Related Solutions

Write a program using Python that allows the user to play a guessing game (please provide...
Write a program using Python that allows the user to play a guessing game (please provide a picture of code so it is easier to read). The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: Normally, we would have the program select a random number as the "secret number". However, for the purpose of testing your program (as well as grading it), simply use an assignment...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 20, and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." If the user guesses the number, the application should congratulate the...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
IN C++ Write a program to play the Card Guessing Game. Your program must give the...
IN C++ Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. -Guess only the suit of the card. -Guess both the face value and suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
Number guessing Game (20 Marks) Write a C program that implements the “guess my number” game....
Number guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
I need to write an interpreter for arithmetic expressions in Python. This program receives an input...
I need to write an interpreter for arithmetic expressions in Python. This program receives an input string with an arithmetic expression and does: 1. prints a ">>>" as if it was a terminal 2. lets us allocate a variable to a a numeric value (as "a = 3") then it stores {'a':3} to a dictionary memory 3. whenever it receives an expression or input, transform it to postfix notation and print it (even when allocating variables) 4. it is able...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT