What am I doing wrong in python?

This is my code… IDK what I am doing wrong (I just began coding like 3 months ago)

print("what passwords do you want to use? [please reply with soci, pers or buis for social media, personal or buisness respectively]")

1 == int(input('please enter'))

if 1== "soci":
   import random
   import string
   total = string.ascii_letters
   length = 8
   password = "".join(random.sample(total, length))

print("Low level password. Commonly used for social media")

print(password)

if 1== "pers":
   import random
   import string
   total = string.ascii_letters + string.digits
   length = 10
   password = "".join(random.sample(total, length))

print("Medium level password. Used for personal use")

print(password)

if 1== "buis":
    import random
    import string
    total = string.ascii_letters + string.digits + string.punctuation
    length = 12
    password = "".join(random.sample(total, length))

print("high level password used for buisness")

print(password)

oh and BTW this is my first time here so hi!

What is the problem? Are you getting any error? What do you expect/want to happen, what happens instead?

2 Likes

Hi @MagentaLolXD !

Welcome to the forum!

I agree with @sanity that it is important to tell people what issues you are experiencing and what you are looking to achieve .

Could you walk us through the logic behind your code?

Because there are certain parts that confuse me on what you are trying to do.

1 Like

Hello there! i am actually trying to make a password maker as googles dosent give those many options… . What I want to do right now is to make it so that the user can choose their password but I am unable to get how… and I am also getting this error:

Re: Hello there!
I have only started python about 3 months ago from my school textbook… I am also using IDLE Shell to code it

you are asking for the strings soci pers or busi, none of those can be converted to an int, so you get that error

1 Like

hmm… tried replacing int with str and now its doing nothing when I type the options…

what’s your code now?

1 Like

You should be getting an error message for these print statements here

You only defined password in the if statements.
You are going to have to change those print statement and move them inside the if blocks.

But also, these print statements would print no matter what the user picked.

You are going to need to move those to their respective if blocks as well

1 Like

This is what happened now… nothing is happening

print("what passwords do you want to use? [please reply with soci, pers or buis for social media, personal or buisness respectively]")

1 == input('please enter')

if 1== "soci":
   import random
   import string
   total = string.ascii_letters
   length = 8
   password = "".join(random.sample(total, length))
   print("Low level password. Commonly used for social media")
   print(password)

if 1== "pers":
   import random
   import string
   total = string.ascii_letters + string.digits
   length = 10
   password = "".join(random.sample(total, length))
   print("Medium level password. Used for personal use")
   print(password)

if 1== "buis":
   import random
   import string
   total = string.ascii_letters + string.digits + string.punctuation
   length = 12
   password = "".join(random.sample(total, length))
   print("high level password used for buisness")
   print(password)

What’s going on with this line here?

Are you trying to say 1 equals the user input?
If so, why?

Isn’t user input a string?

1 Like

I used it as a placeholder…
Now that you informed me, I am going to change that line to something else
Thank you!

Re: I used it as a placeholder…
I tried using it as a string and this happened:

you are not storing the value received from input there, maybe you want to assign the value to the variable instead of checking the value of the variable against user input?

2 Likes

I’m sorry I did not understand
Can you please explain in layman’s terms if possible?

If you want to assign a value to a variable then you need to write something like this.

1 = input('please enter')

one = sign is assignment
Two == signs mean equals.

If you want to store the user input into a variable you have to use = for assignment.

But while we are talking about variable names, 1 is not that descriptive.
You want to use variable names that describe what the variable is .

Something more appropriate would be user_input.

user_input = input('please enter')

That clearly says what the variable is.

1 Like

YES!!!
Thank you a lot!

Thanks for taking time and replying and helping!

1 Like

So basically I have made a code which generates passwords from low-level to high-level and I need help looping it so the user can make more passwords again and again

#gives caution
print("⚠️⚠️⚠️Please read the below text⚠️⚠️⚠️")

#asks user which password he wants to use
print("what passwords do you want to use? [please reply with low, mid or high for social media, personal or buisness respectively]")

#asks for the input
userinput = input('please enter')

#social media password
if userinput == "low":                                        #"low" user input
   import random                                              #imports of random(to randomise) and string(to group the letters)
   import string
   total = string.ascii_letters + string.digits               #total
   length = 8                                                 #determines the length
   password = "".join(random.sample(total, length))           #brings it all together
   print("Low level password. Commonly used for social media")#prints class
   print(password)                                            #prints password

else:
    print("INVALID")                                          #Shows that the users code is invalid

#personal use input
if userinput == "mid":                                       #"mid" user input
   import random
   import string
   total = string.ascii_letters + string.digits
   length = 10
   password = "".join(random.sample(total, length))
   print("Medium level password. Used for personal use")
   print(password)

else:
    print("INVALID")

#buisness input
if userinput == "high":                                       #"high" user input
   import random
   import string
   total = string.ascii_letters + string.digits + string.punctuation
   length = 12
   password = "".join(random.sample(total, length))
   print("high level password used for buisness")
   print(password)

else:
    print("INVALID")

check this