Python Forum
How do you create a true/false response?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you create a true/false response?
#2
for the love of God use the format method. I would hope that schools are not teaching to write code like that.
>>> 'It is {} that {} contains dairy'.format('dairy' in input_test.lower(), menu)
'It is False that "seafood, dairy, nuts, chocolate" contains dairy'
much easier to distinguish the difference of string and variable. Or use the python3.6+ f-string
>>> is_dairy = 'dairy' in input_test.lower()
>>> f'It is {is_dairy} that {menu} contains dairy'
'It is False that "seafood, dairy, nuts, chocolate" contains dairy'
it would totally depend on what you enter at your input as to whether its true or false. If your trying to get the menu a it might look in your actual string you could just do
>>> 'dairy' in menu
True
Recommended Tutorials:
Reply


Messages In This Thread
RE: How do you create a true/false response? - by metulburr - Jan-08-2018, 01:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP - Writing code returning True or False Kokuzuma 2 2,832 Nov-01-2018, 03:37 AM
Last Post: Kokuzuma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020