Is my VS Code bugging or is something wrong with my code?

Solution 1:

The randnum1 in your input statement is not defined as it has not been defined globally. randnum1 is a local variable as it has only been defined in the genrand1() function so it's only accessible within the genrand1() function.

To define randnum1 globally, store the return value of the function in it: randnum1 = genrand1(). Like:

def genrand1():
    randnum1 = random.randrange(rand1a, rand1b)
    return randnum1

randnum1 = genrand1() #Stored here

rand1prompt = input("The random number will be " + randnum1 + ". Is this okay? (Type yes or no")
if rand1prompt := "yes":
    print("Okay, the number's set.")
    num1 = randnum1
elif rand1prompt := "no":
    print("Okay. Generating a new random number...")
    genrand1()
else:    
    print("Whoops. Something went wrong. Please type yes or no.")