#πŸ”’ I need help (im new)

69 messages Β· Page 1 of 1 (latest)

wraith citrus
#

im trying to get my code to respond in such a way thta if i did not enter any name, it will tell me that i did not enter any name

undone cairnBOT
#

@wraith citrus

Python help channel opened

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.

tepid galleon
wraith citrus
#

oh ok thanks

tepid galleon
#

np

wraith citrus
#

like this?

#

sorry im still tryna get used to the double == and if/else/elif

tepid galleon
# wraith citrus like this?

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

wraith citrus
#

oh aight

tawdry brook
#

makes more sense to me but there is no right and wrong only opinions

wraith citrus
#

i though it had some error with the code

wraith citrus
tepid galleon
gritty temple
#

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.

wraith citrus
#

if name: then how would it know theres a name and if its there or not

wraith citrus
#

so yeah

somber crag
#

You need to compare the input to another string

#

if name == "Horizon"

gritty temple
#

then a while loop, if true break out, if false continue

somber crag
#

this is assuming they want it to ask repeatedly

tepid galleon
#

you can do if !name:

gritty temple
#

true, and number of retries could be set... its upto OP to define.. but guess im assuming he would want it.

somber crag
#

I don't think they're concerned with empty strings right now

wraith citrus
#

ok so ive tried it, and whether i put a name or not, it just prints hello

somber crag
tepid galleon
wraith citrus
#

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?

somber crag
#

if name == True and if name are not equivalent

somber crag
wraith citrus
#

like

#

a random assortment of letters or giberish would do

somber crag
#

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

wraith citrus
#

then what should i use to check if the user left it empty

gritty temple
#

if name: for anything entered,
if not name: for nothing entered,
if name and not name == "something": ie, admin etc.

somber crag
#

we use else for that

#

we have 2 scenarios. You either entered a name, or you didn't

wraith citrus
#

oh this works aswell

wraith citrus
#

but i prob did a really dumb and stupid mistake

#

this is the code i just showed u guys

somber crag
#

yeah, you shouldn't be comparing to True and False here

wraith citrus
#

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

tepid galleon
#

!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")
undone cairnBOT
gritty temple
#

that usage would be to build flags to use for other things

wraith citrus
gritty temple
#

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

wraith citrus
#

Alr, damn bro, didn't expect u to put in so much effort, appreciated fr bro

#

Thanks for your time

gritty temple
#

πŸ™‚ enjoying morning coffee before work..

undone cairnBOT
#
Python help channel closed for inactivity

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.