Oct-26-2018, 07:59 AM
#'abcdefghijklmnopqrstuvwxyz0123456789'I am very new to Python or programing. I'm writing code for a password generator. I don't know how to make this line valid or part of the code with the #?
#'abcdefghijklmnopqrstuvwxyz0123456789'I am very new to Python or programing. I'm writing code for a password generator. I don't know how to make this line valid or part of the code with the #?
#
indicates that everything after it on the same line is a comment and is ignored by the interpreter. The only exception is when it is at the very top of the script in which case it may actually be an instruction to the interpreter (e.g. shebang, define source code encoding)#password generator print("Hello, world!") import string import random while True: try length = int(input)('How long would you like your password to be?:' )) break except ValueError: print('value must be ') continue chars -string.ascii_letters + string.digits #'abcdefghijklmnopqrstuvwxyz0123456789 new_passsword = '' num = 0 while num < length num += 1 new_passsword+= random.choice(chars) print(new_passsword)This was one of our labs. These were my instructions.
n
using a while
loop and random.choice
, this will be a string of random characters.n
.chars = string.ascii_letters + string.digitsthe comment is there just for that - to show/comment what chars would be. Normally one would put it on the previous line, e.g.
chars = string.ascii_letters + string.digits # 'abcdefghijklmnopqrstuvwxyz0123456789Note that you have also problems with the indentation of the body of the while loop as well with the try/except. Try to fix these yourself