1

Hello I just started programming in Python and I was just trying to make a RNG but there are some errors that I don't understand.

Here's the code

import random
import time

numbersGenerated = 0

print('Hello! How many numbers do you want?')
numbersNeeded = input()
print('What would you like the minimum for the numbers be?')
Min = input()
print('And the maximum?')
Max = input()

numbersNeeded = str(numbersNeeded)
numbersGenerated = str(numbersGenerated)

while numbersGenerated < numbersNeeded:
    number = random.randint(Min, Max)
    number = int(number)

    numbersGenerated = numbersGenerated + 1

    print(number)
    print()
    time.sleep(2)

print('All done. Hope to see you again!')

The Traceback Error says

File "C:/Python32/Number_Generator.py", line 20, in <module>
number = random.randint(Min, Max)    
File "C:\Python32\lib\random.py", line 215, in randint
return self.randrange(a, b+1)
TypeError: Can't convert 'int' object to str implicitly

I have changed lines thirteen and to int also but that didn't change the outcome.

2 Answers 2

4
  1. You are doing while numbersGenerated < numbersNeeded when numbersGenerated and numbersNeeded are strings, which is probably not what you wanted.

  2. You are calling random.randint(Min, Max) while Min and Max are strings, they should be integers.

  3. No need for number = int(number), it will already be an int.

  4. numbersGenerated = numbersGenerated + 1 again, the variable is a string

Sign up to request clarification or add additional context in comments.

Comments

1

In Python 3, you should convert the input from input explicitly:

Min = int(input())

and

Max = int(input())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.