ugly, but works. Guess my number python

There are still things to work out.  But I definately need to move on.

Here's a working version.
Fixed another thing.   I think the 'is_it_integer' and 'validate_guess'  are now working right.
Never know!  I always seem to stumble on more problems.

import random
import sys
from sys import exit
### WORK> IN PROGRESS>


def guess_my_number():
start = print("Guess my number! range = 0-100. ")
print(('.')*15)
cpu_number = random.randint(1,101)
print(f" computers number = {cpu_number}.")
guesses = []
stopper = True
count = 1
stopper = True

your_guess = input("Your guess....:")

while stopper:
your_guess = is_it_integer(your_guess)
ready = False
if is_it_integer(your_guess):
guess = int(your_guess)
ready = True
if not is_it_integer(your_guess):
guess = validate_guess(your_guess)
ready = True
#if look_for_equals(guesses, your_guess):
#print(count)
#print(f"you already guessed the number: {your_guess}")
#your_guess = int(input("try again ..."))
if ready:
print(f"your guess is {guess}")
print(ready)
if count == 10:
print(f"Sorry, my number was {cpu_number}")
stopper = False

elif guess == cpu_number:
print(f"You win! You got the answer in {count} trys!")
stopper = False
elif guess > cpu_number: #and your_guess != cpu_number:
your_guess = input("Your guess is too high. Try again.")
your_guess = is_it_integer(your_guess)
guesses.append(your_guess)
count += 1
elif guess < cpu_number: #and your_guess != cpu_number:
your_guess = input("Your number is too low. Try again.")
your_guess = is_it_integer(your_guess)
count +=1
guesses.append(your_guess)
else:
print("Error.")

# This isn't used yet -->
def check_for_yes(playing):
playing = input("Do you want to play? yes, no, quit.")
if playing.lower() in ['yes', 'y']:
return True
elif playing.lower() in ['quit', 'q', 'no', 'n']:
print("Bored already? Later!.")
exit(0)
return False
else:
print("Else is executing")
exit(0)
# This isn't working yet -->
def look_for_equals(somelist, arg):
if arg in somelist:
return True
else:
return False

def is_it_integer(prompt):
n = prompt
try:
int(n) == n
prompt = True
return n
except ValueError:
print("error.")
prompt = False
return prompt

def validate_guess(arg):
valid = is_it_integer(arg)
while not valid:
print("This is not a valid number.")
new_guess = input("new guess....:")
valid = is_it_integer(new_guess)
if valid:
new_guess = int(new_guess)
return new_guess
valid = True
else:
print("error.")
print(f"{valid}")
print(f" validation = {new_guess}")
return new_guess


guess_my_number()

Comments

Popular posts from this blog

Statistics, Python, Making a Stem Plot

Pandas Python and a little probability

JavaScript Ascii animation with while loops and console.log