2021年3月6日星期六

The rules of my Guessing Game are not being followed

import random    a = random.randint(1,100)  b = input("Input a number to guess: ")  c = int(b)  guesses = []    while c != a :      guesses.append(c)      c = int(input("Input a number to guess: "))      if c < 1 or c > 100:          print("OUT OF BOUNDS")          continue      if c == a:          print("That's right!!")          break      if len(guesses) >= 2:          if abs(a - c) > abs(a - guesses[-2]):              print("Colder")          else:              print("Warmer")      if len(guesses) == 1:          if abs(a - c) <= 10:              print("Warm!")          else:              print("Cold")    print(guesses)  

The game rules are:

  1. If a player's guess is less than 1 or greater than 100, say "OUT OF BOUNDS"
  2. On a player's first turn, if their guess is within 10 of the number, return "WARM!" further than 10 away from the number, return "COLD!"
  3. On all subsequent turns, if a guess is closer to the number than the previous guess return "WARMER!" farther from the number than the previous guess, return "COLDER!"
  4. When the player's guess equals the number, tell them they've guessed correctly and how many guesses it took!

But the above code isn't working, it's not showing warmer and colder correctly, also it shows warm and cold after 2nd input. How to fix this?

https://stackoverflow.com/questions/66513030/the-rules-of-my-guessing-game-are-not-being-followed March 07, 2021 at 11:52AM

没有评论:

发表评论