[Solved] Search and replace vulgar words in a text by using a text file containing all the bad words

i found the solution , i maked the content of the txt file in a list with split method , def check_offline(text): list_pro = open(‘full-list-bad.txt’,’r’) content = list_pro.read() list_content = content.split(‘\n’) for word in list_content : if word in text : remplacement = “*” * len(word) text = text.replace(word ,remplacement) print word print remplacement return … Read more

[Solved] Oops, try again. Your function failed on the message yes. It returned ‘yes’ when it should have returned ‘Shutting down’

Couple of points: Misplaced return statement. Should be at end. if yes(): It is wrong. You want to compare function input with yes. It should be if s == ‘yes’:. Same for rest also. Since you have written function definition as def shut_down(s):, it is expecting one argument. You should pass one argument while calling … Read more

[Solved] Python – How to replace adjacent list elements with a different value

And yes , you can just pass with if/else and for loops : a = [[0,0,0,0,0], [0,1,1,0,0], [0,1,0,1,0], [0,0,1,0,0], [0,0,0,0,0]] to_replace = 1 replacement = 9 for i in range(len(a)): for x in range(len(a[i])): if a[i][x] == to_replace: for pos_x in range(i-1,i+2): for pos_y in range(x-1,x+2): try: if a[pos_x][pos_y] != to_replace: a[pos_x][pos_y] = replacement except … Read more

[Solved] python 2.7 script to add a column

Given that the question you posed doesn’t have enough information, I’ve formulated an answer that implements the rules you wrote about. Unfortunately, it’s hard to validate this because the expected output you provided doesn’t follow the rules (e.g. 133344444,3,106029,106961,12981,3_1category). I’ve also made the assumption that if an NA value is found, it should be treated … Read more

[Solved] How to split an integer into two integers that when multiplied they give the result of the first number [duplicate]

Every integer is divisible by itself and by 1. If the integer is composite, it will have at least one other pair of divisors (which may be the same, as in the case of 4, which is divisible by 1,4 and 2,2). lim = int(math.sqrt(num)) for i in range (1, lim): if num%i==0: print(i, int(num/i)) … Read more

[Solved] i need help adding the leap year functionality into my python program [closed]

Roll-your-own parser code is silly. Python has batteries included for this: import datetime repeat = True datestr = raw_input(‘Enter a date in the format MM/DD/YYYY’) while repeat: try: # Parse to datetime, then convert to date since that’s all you use date = datetime.datetime.strptime(datestr, ‘%m/%d/%Y’).date() except ValueError: pass # Handle bad dates in common code … Read more

[Solved] Switch case from PHP to python

In python there is the if …. elif …. elif….else It is the switch in other languages. But in your code you do not need a switch statement. It’s enough to use a if then else. if flagRound == floor: totalUnits = floor(totalParts / partsInUnit) else: totalUnits = ceil(totalParts / partsInUnit) 3 solved Switch case … Read more

[Solved] I have an error in my program that python detected. Plus im sure there are more errors. Please fix ^-^

This is a basic scope problem. Nonlocal variables by default have read-only access in functions, assignment to a variable with the same name as a variable outside of the function will result in a new, empty, local variable being created. Adding a global Money line at the top of each function that is supposed to … Read more