Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
# issue
#1
#'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 #?
Reply
#2
# 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)
Show us your code in python tags and explain what exactly you want to do and what's going wrong.
See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
#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.

# Lab 8: Password Generator

Let's generate a password of length n using a while loop and random.choice, this will be a string of random characters.


## Advanced

Allow the user to enter the value of n.



[//]: # (show them the 'string builder pattern', how a string is build one character at a time)
Reply
#4
line 14 should be
chars = string.ascii_letters + string.digits
the 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 # 'abcdefghijklmnopqrstuvwxyz0123456789
Note 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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020