Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Here is what I currently have, which is not working:
if "Forwarder" not in shp_name or "T_" not in shp_name or "Grad" not in shp_name:
I've also tried:
if ("Forwarder", "T_", "Grad") not in shp_name:
Samples of the input would be "DS_Forwarder_1" or "DS_Harvester_1". The script proceeds directly to else as it's unable to identify any of the above substrings in the primary string.
Try using the any built in.
if any(s in shp_name for s in ("Forwarder", "T_", "Grad")):
...
This will be true if any of the given strings are present in shp_name. You can use if not any(... if you want False when one of the strings is present.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 days ago.
Improve this question
The whitespace should be replaced with a 'dollar' sign.
Keep the punctuation marks unchanged.
Note: Convert the given input sentence into lowercase before encrypting.
The final output should be lowercase.
input = Hello World
expected_output = svool$dliow
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 months ago.
Improve this question
I am trying to write a simple function that takes a list of number passed as an argument and prints how many positive number is in the list.
I can't seem to figure out what is wrong with the code here. Can someone please explain this.
You should return add instead of num. And you should initialize add outside the for loop.
lst = [1,2,3,4,-4,-3,-2,-1]
def count_positives(lst):
return sum(i > 0 for i in lst)
print(count_positives(lst))
the program above will print 4
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
When I try to input evet, it does not work. However, when typing Evet, my code runs perfectly. Is there a way to have the code work regardless of the capitalization?
question = input("Oyunu Oynamak İstermisin [Evet/Hayır] ")
Based on your title, it would seem that your best bet is using lower() or upper().
question = input("Oyunu Oynamak İstermisin [Evet/Hayır] ")
if question.lower() == "yes":
. . .
. . .
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm hoping this is a simple stupid problem. But we have an in-house program that is no longer working. The program is not able to pass the data which is supposed to be contained in a variable using var_name+="".
The variable seemingly contains nothing. when I try to print the contents of this variable to either a string or text doc, we get nothing. The variable in question here is "allData".
The contents of this variable need to be passed to our fax appliance.
def sendFax(destOrg, destFax, cliName, casenum, attachments, errEAddr, comment, destName):
creds=requests.auth.HTTPBasicAuth(user,password)
#OVERRIDE OUTBOUND FAX NUMBER FOR TESTING
destFax='716-631-9804'
print("faxes will be sent to "+destFax)
return
allData=''
allData+='<schedule_fax>\n'
allData+='<cover_page>\n'
allData+='<url>'+prepXMLString(coverPage)+'</url>\n'
allData+='<enabled>true</enabled>\n'
allData+='<subject>'+prepXMLString(cliName)+' - case # '+str(casenum)+'</subject>\n'
allData+='<comments>'+prepXMLString(comment)+'</comments>\n'
allData+='</cover_page>\n'
allData+='<sender>\n'
allData+='<name>'+prepXMLString(webAddr)+'</name>\n'
allData+='<organization>'+prepXMLString(ourOrg)+'</organization>\n'
allData+='<phone_number>'+prepXMLString(ourPhonenum)+'</phone_number>\n'
allData+='<fax_number>'+prepXMLString(ourFaxnum)+'</fax_number>\n'
allData+='<email_address>'+prepXMLString(errEAddr)+'</email_address>\n'
allData+='</sender>\n'
allData+='<recipient>\n'
allData+='<name>'+prepXMLString(destName)+'</name>\n'
allData+='<organization>'+prepXMLString(destOrg)+'</organization>\n'
allData+='<fax_number>'+destFax+'</fax_number>\n'
allData+='</recipient>\n'
That is all screwed up. You're returning on the line with the return keyword which is why nothing is being returned.
You should do all of the concatenation and then return.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm trying to replace the substring 'gta' with substring 'cat'. But the condition is that 'gta' immediately has to be followed by substring 'dog'.
Example: 'gtagtadogcat' would become 'gtacatdogcat'
The part I'm struggling with is trying to write the program to find 'gta' and validate that 'dog' is behind it and if true, change 'gta' to 'cat'.
>>> 'gtagtadogcat'.replace('gta'+'dog', 'cat'+'dog')
'gtacatdogcat'
old_string = 'gtagtadogcat'
print(old_string.replace('gtacat','dogcat'))
output: gtagtadogcat
You could use regex:
re.sub('gta(dog)', r'cat\1', 'gtagtadogcat')
Output:
'gtacatdogcat'
*Edit: You would not need a forloop if you put in the whole string. Here is an example:
re.sub('gta(dog)', r'cat\1', 'gtagtadogcat_moretextgta_lastgtadog')
Output:
'gtacatdogcat_moretextgta_lastcatdog'