-2

Ok so I am making a python random number generator with the parameters defined by the user. I am writing this on python 3.4. this is the code:

import random
import time
name = input("whats your name? ")
numOfNums = input("ok " + name + " how many numbers do you want to randomize? ")

def randomGenerator():
    randomFinal = random.randint(1, numOfNums)
    print (randomFinal)
    rerun = input("Do you want to pick another random number? ")
    if rerun == "yes":
        time.sleep(0.05)
        randomGenerator()
    else:
        print("you may now close this windows")

randomGenerator()

I am having an issue with the line:

randomFinal = random.randint(1, numOfNums)

I cannot use the variable 'numOfNums' as a parameter. Do you have any ideas?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
MrGuy797
  • 55
  • 1
  • 1
  • 7
  • This post is different to the other post as I did not directly ask how to convert variables into integers, others trying to do the same thing may need to see this – MrGuy797 Jul 15 '15 at 11:26
  • There are literally hundreds of existing questions where people ask why their code isn't working and the answer is because they (for no reason I can ever figure out) assume that Python will convert their input to numbers. Yours neither gives a [minimal example](http://stackoverflow.com/help/mcve) nor the actual traceback (which is what most people with a similar problem would be searching for - indeed, had you *bothered to search on that error message*, you wouldn't have needed to ask), and therefore has absolutely no value to the community. **Just delete it.** – jonrsharpe Jul 15 '15 at 11:27
  • @MrGuy797 You might not have asked about changing your variable to an `int` but that's your problem. A problem that has been solved on here on SO probably dozens of times a day. – kylieCatt Jul 15 '15 at 11:56

1 Answers1

1

Make it an integer with int():

import random
import time
name = input("whats your name? ")
numOfNums = int(input("ok " + name + " how many numbers do you want to randomize? "))

def randomGenerator():
    randomFinal = random.randint(1, numOfNums)
    print (randomFinal)
    rerun = input("Do you want to pick another random number? ")
    if rerun == "yes":
        time.sleep(0.05)
        randomGenerator()
    else:
        print("you may now close this windows")

randomGenerator()
ᔕᖺᘎᕊ
  • 2,971
  • 3
  • 23
  • 38