I was messing around with if-else statements and "while True" as well. I decided to make a simple login page with it. I wanted to know if there was an easier way to do it. I was wondering if there was a way to combine them or something to make it less lengthy. I needed several 'while True' statements or it just loops back to the beginning when ran.
#🔒 is there an optimized way to complete this task?
80 messages · Page 1 of 1 (latest)
@boreal saddle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
The code works, I was just wondering if there was an easier way to do it
first few lines here i found something
user = input("Enter Username: ")
``` the input also prints to the terminal. ill keep reading
your 3 while trues are also concerning. instead of opening a new while true within the original while, break it with
break
``` which forces the while loop to end and make your new loop from there.
it reduces indentation making code easier to read
@boreal saddle
you also had an extra while True which i didnt catch until just now but i edited my message to fix that
alright thanks
do you see what i did?
bc something telling me you are about to just copy this without asking any questions as to why which is why ive deleted it now
yea, I tried to use the break but i did it wrong i think
1 sec
after the break, do i need another while True?
sorry if you werent going to do that, but a lot of people who say alright thanks just immediately copy the message and close the chat without seeing why its done that way
but yes you would put another while true after the break with no indention
nah, i wasn't. I'm taking a course as well. I'm actually trying to learn
ill post what I have after I update it
while you edit can you send the task itself? some of these homework questions have weird catches to them
*im assuming its an assignment from the wording of the title
nah, i was just learning about if, elif and else and thought i would make something myself
alright, now that gives us more freedom
after the break, the script ends? I added the while True
can you send what you have? prob a syntax error
your indention seems off, can you please upload the whole thing? it could just be a paste error
so the break leaves the closest loop entirely. move your second loop all the way to the left. as is your program physically cannot reach the second loop
i also just finished the better way to do this once we get this working too to show you how it should be done
but only after you manage to get it working so you can learn the fundamentals
alright, i think i see what you're saying now. I'll update the three loops and post what i have. Thanks for the help by the way.
The confusing part for me was the while True statement indentations. I thought because it was in a new code block it needed to be indented past the break line
nope, the break exits the loop entirely so to start a new loop you have to make it outside the scope of the broken loop
always start new code blocks as far left as possible
more indentions = bad
ah ok
this remake ive done for you has at most 3 indentions and that 3rd indention is only returns and prints
i should prob clarify - im not using multiple while true loops like you are so if youre stuck trying to figure out how to use fewer indentions dont worry about it. as long as you understand
looks right, big question now. does it work?
it does
alright, one moment then. im having my local ai generate comments for you for this code
i tried it with the right login and the wrong login and it worked both ways
with the wrong login it looped as I wanted it to
https://paste.pythondiscord.com/Z4DA
now heres how i would do it - minus the plain text credentials but thats beyond what youre doing today
please ask me questions but hopefully the sheer amount of comments should help you (thank you my friend cody the ai)
and before you ask, no i dont use the ai to code(most of the time) i mostly use it to generate comments and documentation bc i work in a group and i get yelled at for not properly documenting XD
yea i know adding comments can be a bit tedious
so any questions on what i sent? i know its wildly different than what you made but it does the same thing using better practices (minus credentials being plain text lol)
i think i get everything except for how the authentication part works.
alright, just ask which part or do you want me to just break down the whole line?
wait nvm, authentication and authenticate are different variables
do you understand how i called the command you enter? im betting thats the farthest out there concept in there
so thats an f string. instead of ""+"" you can do f"{variable} basic text" to insert variable data without a bunch of +'s. it also does some other cool things but thats the basic function. lets you insert text
oh
the /home was just to indicate it wasnt the login portion
oh i see
with it the user being user i got confused myself and thought it didnt work until i realized what happened so i added the /home
yea, i just used user as a placeholder
i think my help channel is about to timeout lol. guess im asking again tomorrow
I'm actually taking a SQL server college course so hopefully, I would be able to learn storing data in databases and such and integrate Python into what I'm learning about SQL. (to not have passwords in plain text)
perfect, youll have it figured out in no time then
thanks for your help, and I hope your channel doesn't get timed out
it prob will my problem is kinda out there
i would help if i knew more lol
oh my bad i thought you were a master programmer here to teach me
lol
yup theres the timeout. guess im asking tomorrow, enjoy learning... while you can
yea im trying. Thanks for your help
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.