Hello everybody I have been trying to get around the problem of checking for a tuple in raw input and I just got a tip that kind of works but it only works for the second for loop. In other words when you input and of the 'close' words python returns 'thanx for chattin' like it should but if you input any of the 'bad' words it dosnt return anything. I have no idea what the problem is so any help would be much appreciated.
Thank you.
PS I dont know why ,my postings will never indent properly but i think i have them all right. -
print 'hello'
-
def loop():
-
bit=0
-
bad=('lol','lawl','teehee','rofl','lmao','lmfao')
-
close=('close','goodbye','shutup','be quiet')
-
response=raw_input()
-
for word in bad:
-
if word in response:
-
bit=1
-
if bit:
-
print 'we dont use that language here'
-
else:
-
print 'i dont understand your gibberish'
-
break
-
break
-
for word2 in close:
-
if word2 in response:
-
bit=1
-
if bit:
-
print 'thanx for chattin'
-
else:
-
print 'i dont understand your gibberish'
-
break
-
-
-
-
loop ()
-
loop ()
4 2422
Hello everybody I have been trying to get around the problem of checking for a tuple in raw input and I just got a tip that kind of works but it only works for the second for loop. In other words when you input and of the 'close' words python returns 'thanx for chattin' like it should but if you input any of the 'bad' words it dosnt return anything. I have no idea what the problem is so any help would be much appreciated.
Thank you.
PS I dont know why ,my postings will never indent properly but i think i have them all right. -
print 'hello'
-
def loop():
-
bit=0
-
bad=('lol','lawl','teehee','rofl','lmao','lmfao')
-
close=('close','goodbye','shutup','be quiet')
-
response=raw_input()
-
for word in bad:
-
if word in response:
-
bit=1
-
if bit:
-
print 'we dont use that language here'
-
else:
-
print 'i dont understand your gibberish'
-
break
-
break
-
for word2 in close:
-
if word2 in response:
-
bit=1
-
if bit:
-
print 'thanx for chattin'
-
else:
-
print 'i dont understand your gibberish'
-
break
-
-
-
-
loop ()
-
loop ()
The in operator can be used in a very cool way, here. It will simplify your logic greatly: -
>>> bad=('lol','lawl','teehee','rofl','lmao','lmfao')
-
>>> close=('close','goodbye','shutup','be quiet')
-
>>> def CheckInputInTuple(word):
-
... if word in bad:
-
... print 'we dont use that language here'
-
... elif word in close:
-
... print 'thanx for chattin'
-
... else:
-
... print 'i dont understand your gibberish'
-
...
-
>>> def GetUserInput():
-
... word = ""
-
... while word.lower() not in close:
-
... word = raw_input("Let's chat: ")
-
... CheckInputInTuple(word.lower())
-
...
-
>>> GetUserInput()
Would "ROFL" also be considered bad?
Ok cool now could you please explain this line by line to me because I am a bit confused as to how this works. Thank you so much for your input already.
Hi ok nevermind about that last comment I figured out what it does but now there it wont work for multiple word inputs such as "lol that was funny". When that is input it brings up "I dont understand your gibberish" becuase i can only check to see if the "bad" words are in a one word raw input. Any ways to fix this problem?
thanks
bvdet 2,851
Expert Mod 2GB
Hi ok nevermind about that last comment I figured out what it does but now there it wont work for multiple word inputs such as "lol that was funny". When that is input it brings up "I dont understand your gibberish" becuase i can only check to see if the "bad" words are in a one word raw input. Any ways to fix this problem?
thanks
I modified Barton's code for phrases instead of single words. - bad = ('lol','lawl','teehee','rofl','lmao','lmfao')
-
close = ('close','goodbye','shutup','be quiet')
-
-
def CheckInputInTuple(phrase):
-
for word in phrase.split():
-
if word in bad:
-
return 1 #'we dont use that language here'
-
elif word in close:
-
return 0 #'thanx for chattin'
-
return 2 # 'i dont understand your gibberish'
-
-
def GetUserInput():
-
while True:
-
phrase = raw_input("Let's chat: ")
-
ans = CheckInputInTuple(phrase.lower())
-
if ans == 1:
-
print 'we dont use that language here'
-
elif not ans:
-
print 'thanx for chattin'
-
break
-
else:
-
print 'i dont understand your gibberish'
-
-
GetUserInput()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Thorsten Kampe |
last post by:
I found out that I am rarely using tuples and almost always lists
because of the more flexible usability of lists (methods, etc.)
To my knowledge, the only fundamental difference between tuples...
|
by: Carlos Ribeiro |
last post by:
As a side track of my latest investigations, I began to rely heavily
on generators for some stuff where I would previsouly use a more
conventional approach. Whenever I need to process a list, I'm...
|
by: adam |
last post by:
i'm working on a portion of a CMS that allows content-admins to browse
a product list, and add individual products into the taxonomy by
clicking checkboxes next to categories they might belong in....
|
by: Grasshopper |
last post by:
Hi,
I am automating Access reports to PDF using PDF Writer 6.0. I've
created a DTS package to run the reports and schedule a job to run this
DTS package. If I PC Anywhere into the server on...
|
by: Martin v. Löwis |
last post by:
I've been working on PEP 353 for some time now.
Please comment, in particular if you are using 64-bit
systems.
Regards,
Martin
PEP: 353
Title: Using ssize_t as the index type
Version:...
|
by: ckoniecny |
last post by:
I have the following two files:
File1:
11 John Doe
33 Jane Doe
55 Steve Smith
File2:
22 Joe Doe
44 Willy Widget
|
by: Selpher |
last post by:
Hi guys, I'm having trouble getting these two for loops to interact properly. The point of this program is that a number inputed by the user (we'll use 15 as an example) is supposed to display...
|
by: OBAFGKM_RNS |
last post by:
Let's say I have a Javascript function that loops over and over. In
that function i have it alternating images on a button this way:
if(var==0){
var myHTML = "<input type='button'...
|
by: ian.team.python |
last post by:
To step through a list, the python style is avoid an explicit index.
But what if the same hidden index is to be used for more than one list
for example:-
for key,value in listKeys,listValues :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |