#๐Ÿ”’ small problem

20 messages ยท Page 1 of 1 (latest)

drowsy belfry
#

okay i have it set title and split names for my program but i get an error if someone just uses only a first name, how do i fix that while keeping my code the same for they choose to put first and last

chrome ironBOT
#

@drowsy belfry

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.

junior aurora
drowsy belfry
#

yes one second sir ill post

junior aurora
#

it could also be done without if, but you wouldn't do first, last = name.split()

#

instead just do full_name = name.split()

#

and then when displaying their name to them, you can use full_name[0]

drowsy belfry
#

i used if here

#

but not sure how to use if in the name setting

junior aurora
#

Have a read of what I just wrote above

drowsy belfry
#

okay

#

word

#

let me try that thank you

junior aurora
#

it's generally not a good idea to use multiple assignment when you can't guarantee the length of the data

drowsy belfry
#

okay good to now

#

appreciate the help

indigo copper
# drowsy belfry

in this specific case, where your actions are the same, but the context changes (like calling print each time, but with a different string).

you could make use of a dictionary. mapping each number to a sentence.

chrome ironBOT
#
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.