473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem Checking for Tuple in Raw Input

Hi everyone i was just makeing myself a little spelling bee program and this problem came up that tells me the <string> needs to be left as an operand. I dont know how to fix this problem so any help you could give me would be much appreciated. Thank you
Code:(python)


Expand|Select|Wrap|Line Numbers
  1. print 'please spell correctly'
  2. def loop():
  3.     bad=('lol','teehee','lawl','rofl','lmao','lmfao')
  4.     response=raw_input('please enter a laughter comment')
  5.     if bad in response:
  6.         print 'we dont use that language here'
  7.     else:
  8.         print 'i dont understand your gibberish'
  9.  
  10. loop ()
PS All my indentation is correct i just couldnt get this posting to indent my code block.
Oct 19 '07 #1
5 1896
ilikepython
844 Expert 512MB
Hi everyone i was just makeing myself a little spelling bee program and this problem came up that tells me the <string> needs to be left as an operand. I dont know how to fix this problem so any help you could give me would be much appreciated. Thank you
Code:(python)



print 'please spell correctly'
def loop():
bad=('lol','teehee','lawl','rofl','lmao','lmfao')
response=raw_input('please enter a laughter comment')
if bad in response:
print 'we dont use that language here'
else:
print 'i dont understand your gibberish'

loop ()

PS All my indentation is correct i just couldnt get this posting to indent my code block.
Instead of "bad in response" try "response in bad".
Oct 20 '07 #2
Yeah sorry I tried that and that works exept that it will only work for one word answers. YOu cant have it find the word in a sentence for example. Any other ideas out there?
Oct 20 '07 #3
ilikepython
844 Expert 512MB
Yeah sorry I tried that and that works exept that it will only work for one word answers. YOu cant have it find the word in a sentence for example. Any other ideas out there?
You could try something like this:
Expand|Select|Wrap|Line Numbers
  1. bit = 0
  2. for word in bad:
  3.     if word in response:
  4.         bit = 1
  5.         break
  6.  
  7. if bit:
  8.     print "Bad language"
  9.  
Oct 20 '07 #4
Ok thank you for your help. I will definetly try using this code you gave. I was also wondering WHY python dosnt make this work properly when i have it like i did originally. It seems like the logic is sound. Thank you for any explanations you could give to further my understanding of Python. Any other suggestions beside the ones already given will be much appreciated. Thank you again.
Oct 20 '07 #5
ilikepython
844 Expert 512MB
Ok thank you for your help. I will definetly try using this code you gave. I was also wondering WHY python dosnt make this work properly when i have it like i did originally. It seems like the logic is sound. Thank you for any explanations you could give to further my understanding of Python. Any other suggestions beside the ones already given will be much appreciated. Thank you again.
The reason why it didn't work your original way, is because you were testing to see if a tuple (it doens't make a difference what it contains) is in a string. You need to test individually for every string in the tuple if it is found in the user input.
Oct 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Carlo v. Dango | last post by:
Hello there. I have a function which as an argument takes a tuple and either returns that tuple or a mutated version of it. The problem is that tuples are imutable, hence I have to create a new...
68
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I...
1
by: Jon Perez | last post by:
I want to retrieve a value from a tuple and convert it to a C type. Is the following idiom okay? if (!( ( tmp_pyobj=PyTuple_GetItem(tuple,1) ) && ( c_int=PyInt_AsLong(tmp_pyobj) ) )) { if...
12
by: Kay Schluehr | last post by:
Hi all, thanks for Your attention ! I think my proposal was more in mind of Rons modified exec than Pythons lambda. When George proposed his unpacking behavoir for list-comps as a pack of...
0
by: Paddy | last post by:
Hi, I read a blog entry by GVR on interfaces in which he mentioned that you had to be able to state the type signature of, say, a function. That got me thinking along the lines of: If you have...
5
by: PHPBABY3 | last post by:
Hi, 1. I have two SQL tables. I will call them employees and departments: EMP: LAST_NAME, FIRST_NAME, DEPTNM DEPT: NUM, NAME Input: text string FIND Output: the LAST_NAME, FIRST_NAME...
7
by: Doug Stell | last post by:
I am having a problem with the corruption of a list. It occurs only the first time that I call a function and never happens on subsequent calls. Any suggestions would be appreciated. I call the...
0
by: ppuniversal | last post by:
hello, I am making an application where I have to copy the values of some of the tuples(which are not already copied into the files) from my database in MySQL into two files.Now I have an attribute...
4
by: KHATatonic | last post by:
Hi all - first off, I apologize in advance for being a novice. Any help would be greatly appreciated. I'm a graduate student in psychology trying out a new programming language for my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.