In: Computer Science
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
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
.