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.
5 1911
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','tee hee','lawl','ro fl','lmao','lmf ao')
response=raw_in put('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".
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?
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: -
bit = 0
-
for word in bad:
-
if word in response:
-
bit = 1
-
break
-
-
if bit:
-
print "Bad language"
-
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 tuple and copy the
content of the old tuple to a new one.
But how do I do this if I only at runtime know the size of the tuple? I
wish I could pass around lists instead.. that would be so much easier, but
I'm passing "*args" and "**kwargs" around...
|
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 don't like the brackets.
|
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 (PyErr_ExceptionMatches(PyExc_TypeError))
PyErr_SetString(PyExc_TypeError,"tuple's 1st member was not an integer");
|
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
suggar:
|
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 some typical data, then transform it into a string
showing
its sub-types.
Could not a regular expression matching this string be used to check
the type signature of the data?
| |
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 and department name NAME (link DEPTNM
|
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 function, passing in a list as the input data. The function
must manipulate and operate on a copy of that list's data, without
altering the list in the calling routine.
def myFunc(listA):
listB = listA
|
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 with name "Replication_Done". This is an integer type of attribute and its initial value is 0, meaning that this tuple has not been copied into any of the 2 files.
Now whenever a tuple is copied into one of the file, the value of this...
|
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 experiments. I'm going to be using PyEPL which is based on Python. Coming from AppleScript (and having very little programming experience overall), I'm a little overwhelmed trying to get my first experiment to work. Fortunately, what I need doesn't seem like...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |