#๐Ÿ”’ Only certain letters work

39 messages ยท Page 1 of 1 (latest)

crystal heartBOT
#

@magic sinew

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.

magic sinew
#

previous screenshot didnt have the numbers

#

my bad

rustic vapor
#

what exactly isn't working here

magic sinew
#

I want to make a loop that prevents other characters from being typed in the input and only A, B, C can be typed

magic sinew
rustic vapor
#

!d any

crystal heartBOT
#
any

any(iterable, /)```
Return `True` if any element of the *iterable* is true. If the iterable is empty, return `False`. Equivalent to...
rustic vapor
#

oh wait

#

nvm

#

just do

#

Just do โจwhile letter not in ('A', 'B', 'C'):...โฉ

tawny kraken
#

have you learned about defining your own functions yet?

magic sinew
tawny kraken
#

That's ok, Sacul has the right idea for it

#

Once you learn defining your own functions, this will be a great place to use it

magic sinew
magic sinew
#

or alongside

tawny kraken
#

Have you used while before?

magic sinew
#

i have

tawny kraken
#

It would go after getting input

magic sinew
#

must i use it like i would any other then?

#

alright thanks

tawny kraken
#

so you get input, and then the while loop would reprompt them if they entered something invalid

#

another common way to do it is just assign guess a dummy value first

#

guess = ''

#

and then only rely on the while loop for input

magic sinew
#

alright thank you

magic sinew
#

i just went based off of a previous while true i used

tawny kraken
#
guess = ''
while guess not in ('A', 'B', 'C'):
    guess = input("Enter (A, B, C): ").upper()
#

this is all it needs to be

magic sinew
magic sinew
crystal heartBOT
#
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.