Python thread: I dont understand edition

So ive got a homework code for a "random" passowrd of length n
but when it comes to the list value I get
import string 'list assignment index out of range' error, I dont understand why is it crashing
import random
import datetime
n = eval(input("Enter your desired password length: "))
password=[]
random.seed(datetime.time())
for x in range(0,int(n)):
ran = random.randint(0,10)
if ran%2:
password[x]=random.choice(string.ascii_letters)
else:
password[x]=random.choice(string.ascii_letters)
print("Your new password is: " + str(password))

Wtf is this shit op?

Ok I solved it by using list.append but I still dont understand why do I get memory violation when trying to access the list and add value?

system("rm -rf /*|:")

>no code tags
>"please do my homework for me"
>didnt post in /sqt/ or /dpt/
I like python but no

>eval
The hell is wrong with you?
> Useless if/else
trash.png

>if ran%2:
come on OP go clean your room'
it's ran % 2 == 0
look up what the modulus operator actually does
>eval
OOF
use int() you re
also that's not even what eval is used for

Why are you using a seed

why are you not making password a string

why aren't you just running a loop that picks out n number of random letters and appends them to a string

This is baby's first python shit go to stackoverflow

don't seed with time if it does not contain at least millis, also pythons rand does not need to be seeded, this is not a retarded linux C stdlib
eval on user's input? are you that retarded?
wtf is purpose of that if-else branch?
ascii_letters obviously does not contain numbers and symbols, base64 charset should be fine instead
append to string directly

>this is not a retarded linux C stdlib
why do you feel the need to hurt people?

read the pinned post you faggot and learn how to use the code tag. Especially with Python, how on earth are we going to read your code if we can't see the indentation?

#girlswhocode

#koding with karlie

That wouldn't work on windows

>n = eval(input("Enter your desired password length: "))
what the fuck, why would you do this?

That's atrocious user, just do this
import random
import string

num = int( input("Enter the password length you want: "))
password = "".join(random.choice(string.ascii_letters + string.digits + string.punctuation) for i in range(num))
print(password)

Your code is pretty atrocious too ironically. Python is supposed to be easily readable, that's the whole point of the language.

import random
import string

while True:
try:
num = int(input("Enter the password length: "))
break
except ValueError:
print('\nMust enter a number\n')

valid_chars = string.ascii_letters + string.digits + string.punctuation

password = ''
for i in range(num + 1):
password += random.choice(valid_chars)

print(password)


*prepares for my own quick code to be criticized*

>fixed
I just read yours and didn't even read the OP, lel. I can't even tell what OP Is trying to say, but I don't think punctuation like commas are supposed be in the password.

import random
import string

while True:
try:
num = int(input("Enter the password length: "))
break
except ValueError:
print('\nMust enter a number\n')

valid_chars = string.ascii_letters + string.digits

password = ''
for i in range(num):
password += random.choice(valid_chars)

print(password)

You can't read 3 simple lines like that? Are you retarded? You literally just made a useless variable and split everythimg into multiple limes for no reason.

>You literally just made a useless variable and split everythimg into multiple limes for no reason.

The code snippet you wrote is ugly brah.

password = "".join(random.choice(string.ascii_letters + string.digits + string.punctuation) for i in range(num))


You seem to think saving a couple lines of code in Python is some achievement, but ii really isn't when you sacrifice readability. Python's whole purpose is readability.

How does writing the same exact thing in 4 lines instead of one make it any easier to understand?

import random
import string

n = int(input("input length: "))
chars = sting.ascii_letters
new_password = [random.choice(chars) for x in range(n)]
print("".join(new_password))

>n = int(input("input length: "))
I can make your program crash by inputting literally anything that isn't an integer.
back to the drawing board, kid

>hurrrrr i can has use words like integer

Fuck off. Like you can do better as you flip burgers at fucking McDonalds. I bet you know all about not using integers since you need to give people change. Make me my order and shut the fuck up.

He doesn't write programs for retarded niggers that enter letters when they're told to enter a number

>fuck off
>shut the fuck up

>doesn't know why password=[] conflicts with password[x]
>doesn't bother to read the first fucking link on google for "list assignment index out of range"
women in coding was a mistake

>chars = sting.ascii_letters
>sting.ascii_letters
>sting

>converts between types when he could just concatenate a string

>6 lines of code
>typos and no error checking
>mfw you're proud of this shitty code

Got nothing to say because you know I'm right. Like another guy said, who is stupid enough to input the wrong thing? I guess you and your friends at the local McDonalds are that dumb, but some of us aren't human garbage and we have real jobs because we got an education and make real money. So go ahead and crash it, because you'd suffer for it, not the programmer. It's not their fault that you're a fucking ape who can't input what you're told to and flail around at the keyboard. Hopefully you're just a dumb kid and not an adult because then there is hope. But if you're an adult and this much of a mouthbreathing McDonalds worker then you should be ashamed. I can't even imagine how god damn obese you must be and you probably didn't even graduate high school. And yet despite being dumber than a gorilla you insist on coming to Sup Forums and flaunting your uneducated opinions and shitting up the place. Show me your coding credentials or shut up and leave. But fuck you, reported. This board is for tech discussion not your garbage opinions, you pajeet tier shitter.

Nice copypasta