#timing game
import random
import time
import numpy as np
def player_interval_input():
error1 = True
# main while loop, checks if input is in range
error2 = True
# while loop is inside of error1, checks if input is an int or float
while error1:
interval = input("enter interval between 0 and 3:")
while error2:
try:
interval = float(interval)
error2 = False
except ValueError:
print("invalid input")
if interval in np.arange(0,3,0.25):
error1 = False
else:
print("interval has to be in between 0 and 3, try again")
def min_max_input():
error3 = True
# input for min and max range of random numbers
while error3:
range_min = input("enter minimum:")
range_max = input("enter maximum:")
if range_min.isdigit() or range_max.isdigit():
range_min = int(range_min)
range_maxb = int(range_max)
error3 = False
else:
print("invalid input")
start = input("press 1 to start:")
try:
start =int(start)
except ValueError:
print("invalid input, try again")
if start == 1:
player_interval_input()
min_max_input()
answer = random.randrange(range_min,range_max)
print("press G when the number shown is " + str(answer))
print()
#main function, runs the guessing program
run = True
while run:
time.sleep(interval)
randnum = random.randint(range_min,range_max)
print(randnum)
I'm trying to make a small little game where the objective is to press a key when a certain number shows up. I defined 2 functions, function player_interval_input()
to let the player decide the interval/speed at which the numbers show up, and function min_max_input()
to let the player decide the range of numbers that show up.
I made three values - interval
, range_min
and range_max
which are all supposed to be integers or floats that the user inputs in these functions, but unfortunately they don`t show up as defined values in the later part of the code.
Why does this happen, and how to I fix it?