#π I need help (im new)
69 messages Β· Page 1 of 1 (latest)
@wraith citrus
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.
you do not need to do
if {name} == True:
you can do
if name == True:
or just
if name:
oh ok thanks
np
yep it is right, but you would need to also put something after that if, because if the condition is true, the program won't know what to do next
oh aight
makes more sense to me but there is no right and wrong only opinions
i though it had some error with the code
i want to maake it so that if there is a name entered, it will respond with another text
well yeah, the only error is that it does not know what to do after, also the way you described your intention probably you want to check for if name != True
im assuming you want a while loop, so it checks as if true/else block to print nothing entered... however a name persay would be hard to verify if its a real name and not letters making any garbage or word.
if name: then how would it know theres a name and if its there or not
my goal here is just to make a simple system to check whether the user ( me ) has entered anything whether it be giberish or a real one
so yeah
then a while loop, if true break out, if false continue
this is assuming they want it to ask repeatedly
you can do if !name:
true, and number of retries could be set... its upto OP to define.. but guess im assuming he would want it.
They want to know if the name is a specific name
I don't think they're concerned with empty strings right now
ok so ive tried it, and whether i put a name or not, it just prints hello
This is all you need
the initial comment of the post was trying to check if there is any name
any way i can make it so that if theres no name, it will just print the "enter a name"?
and then use that name?
if name == True and if name are not equivalent
What name are you expecting the user to enter?
any
like
a random assortment of letters or giberish would do
technically if name is checking the length of the string. If it's a length of greater than 0, it's valid
so if name will work, and so will if len(name) > 0
you can use else to handle the invalid name
then what should i use to check if the user left it empty
if name: for anything entered,
if not name: for nothing entered,
if name and not name == "something": ie, admin etc.
if name:
print(f"You entered {name}")
else:
print("You did not enter a name")
we use else for that
we have 2 scenarios. You either entered a name, or you didn't
oh this works aswell
yea thanks
but i prob did a really dumb and stupid mistake
this is the code i just showed u guys
yeah, you shouldn't be comparing to True and False here
exactly
oh ya
and also
the 2nd line
i though there was smth wrong in the code, that was printing hello
and that was it
!e
Or you could only do this if you want to check if they did not enter any names
name = ""
if not name:
print("You did not enter any names")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
You did not enter any names
that usage would be to build flags to use for other things
oh yea it works, thanks
what does that mean, srry u might need to dumb it down abit im quite new
u_name = False
u_pass = False
while not u_name and not u_pass:
username = input()
if username:
u_name = True
print('blah')
else:
print('enter a username')
continue
userpass = input()
if userpass:
u_pass = True
print('blah')
else:
print('must enter a pass')
continue
if u_name and u_pass:
break
else:
continue
im on phone, but thats simple logic that can be refined for each
like it gets weird, but you can do a lot of different things to keep asking for a username and subsequent inputs..
probably best to throw each into its own little function, but flags allow you to track that a variable was input and verified with a true/false flag so that you can use them accumilative to pass conditions
so if all flags met, continue to next step.. else restart the whole thing or restart each input.. also restart each input X amount of retries then error out etc
Alr, damn bro, didn't expect u to put in so much effort, appreciated fr bro
Thanks for your time
π enjoying morning coffee before work..
This help channel has been closed. 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.