I'm attempting to write a program that generates a random string of numbers, with its length based on user input. I wrote it in Sublime Text, and it worked perfectly with SublimeREPL, but I then took it into IDLE and attempted to run it and it threw an invalid syntax error.
import string
import random
# Random Number Password Generator
def digit_password(length):
final = []
while length > 0:
final.append(random.choice(string.digits))
length -= 1
result = ''.join(final)
return result
length = int(raw_input("How long will this password be? "))
print digit_password(length)
It always give me the invalid syntax error when I call the function, specifically the "digit_password" name. It worked in sublime text, but it wont work here in IDLE. Does anyone know why this is happening?
Im using the python 3.6.4 shell if that is relevant.
You have no brackets around the print call. Python 3 needs print to be constructed as print(item)
.
Change your last line to:
print(digit_password(length))
Ps. You might need to indent your return call.