samedi 27 juillet 2019

Making a guessing game and when I input 100 it says i need to go higher

So im making a guessing game where the computer picks a randomint between 1 - 100 and when guessing if you guess below the number it will tell you to go higher and if you guess above the number it will tell you to guess lower. It works for the most part it's just when I guess 100 it tells me to go higher.

Now before you start the game the computer will add a random number to an array and all you need to do is match the number provided in the array.

I've tried switching the array to a set but then i get this error message: "'dict' object has no attribute 'add'"

That is the code i am working with.

Also when trying to write to a file it doesn't seem to work too well

from random import *
from random import randint
import os

numbers = []
Guesses = []

os.system('CLS')
print("I want you to guess my number between 1 - 100")

f = open("Data.txt", "a")

print("Say 'yes' If You're Ready")

YN = input()



if YN == "yes":
    os.system('CLS')
    for _ in range(1):
        value = randint(1, 101)
        numbers.append(value)
        break



while True:
    Guess = input()
    Guesses.append(Guess)
    print(numbers)

    if Guess < str(value):
        print("Higher")

    elif Guess > str(value):
        print("Lower")

    elif Guess == str(value):
        os.system('CLS')
        f.write(str(Guesses))
        print("That Was Correct!")
        for x in Guesses:
            print(x)
        break

input()






Aucun commentaire:

Enregistrer un commentaire