0

I am helping a friend with some code for a school helping bot, but I've run into a problem. On the last line, where it says: if helpselect == ('*****'): , I am trying to add multiple conditions in one line of code so that the specific line of code activates when they type math or math. HELP

import time 
print('Hello, my name is CareBot and I am here to help!') 
time.sleep(3) 
name = input('Please input your name: ') 
print('Nice to meet you, %s. I am a bot that can lead you to resources to help out with school subjects!' % name) 
time.sleep(2) 
print('Now, what subject can I help you with?') 
helpselect = input('Please input a subject: ') 
if helpselect == ('*****'):
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214

2 Answers2

1
if helpselect in {"math", "english"}:
    print("You selected math or english")

Something like that? (You said "when they type math or math", which is redundant.)

etnguyen03
  • 580
  • 4
  • 19
  • I meant like, math (lowercase M) or Math (Capital M). But yes, it worked. THANK YOU SO MUCH – Graham Lewis Dec 09 '20 at 14:53
  • 1
    @GrahamLewis If you want to do case-insensitive comparison, you can convert `helpselect` to lowercase or uppercase and then compare against `math` or `MATH` accordingly. – thefourtheye Dec 09 '20 at 15:00
0

If you're just trying to check if the person typed a certain subject then I might create a set of strings. When you check if something is in a set of strings you are checking whether or not the word you typed is one of the words in the set of strings.

setofstrings = ["math", "english", "science"]

if helpselect in setofstrings:

or perhaps you want to do this.

if helpselect == "math" or helpselect == "english":
 

If you're trying to check if there are any math symbols in a line of code. What I would do is create a string called mathsymbols.

mathsymbols = "+-*/"

Then check and see if the input contains any math symbols by doing this line of code. This checks if what you typed any individual character in the string mathsymbols.

if helpselect in mathsymbols:

I would want learn sets, strings, the "in" operator, "and", "or", etc.