+ 1

Checking multiple values in a list

name = input('Please enter your name: ') sex = input('please enter your sex. M for male, F for female :') phone = input('enter your phone number plz. follow format:973 xxx xxxx(spaces inbetween numbers): ') if sex == 'M' or sex=='m': print('HELLO Mr. ', name,',\n') else: print('HELLO Ms. ', name,',\n') if '973'or'862'or'551'or'201' in phone[0:3]: print('Based on your area code ', phone[0:3],' I can tell you are from North Jersey.') elif '732'or'908'or'848' in phone[0:3]: print('Based on your area code ', phone[0:3],' I can tell you are from Central Jersey.') elif '856'or'609'or'640' in phone[0:3]: print('Based on your area code ', phone[0:3],' I can tell you are from South Jersey.') else: print('sorry not from jersey') Can someone help me correctly write this code... i am trying to check the values in the first three values of phone

20th Sep 2019, 8:33 PM
Matin Aduko
2 Antworten
+ 3
You can just do: phone[0:3] in (‘973’, ‘862’, ‘551’, ‘201’) etc. for elif
20th Sep 2019, 9:03 PM
Rustem Sharipov
Rustem Sharipov - avatar