## [Solved] Python 2.7.14 ,code not working [duplicate]

Introduction Solution Try this, n = int(input(“enter any number”)) for i in range(1,n+1): print i, Use Indentation.

## [Solved] Given a tuple t of strings, compute the tuple consisting of all strings in t containing the character @

After a couple of tryouts I just achieved to solve it: tuple_1 = (‘asdf@’, ‘asdf’) tuple_2 = () for elem in [item for item in tuple_1 if ‘@’ in item]: tuple_2 = tuple_2 + (elem,) print tuple_2 I hope this is what you need! I’m voting you up, since it was a little bit of … Read more

## [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] Why is len(file.read()) giving me a value of zero?

Files act like a long tape in a casette; you can read the file but by the time you are done you have passed the tape all the way to the end. Reading again won’t give you the data again. As such your second function tried to read data from a file that is already … 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] How can I calculate a list modulo a numer in python?

Even though it’s a homework question, you can do it as: [a%10 for a in l] 1 solved How can I calculate a list modulo a numer in python?

## [Solved] IndexError: list index out of range error [duplicate]

You are parsing XML that doesn’t have child nodes for that specific slidename[a] element. You probably want to skip that one. You are not using Python loops to their full potential. There is no need to loop over indices when you can loop directly over the list itself: for a in tagname: try: print a.childNodes[0].nodeValue … Read more

## [Solved] python program doesn’t work

The str.find finds the index of the item. You need to use str.count. def ex4(str4): someLetter = str4[ :1] return str4.count(someLetter) print ex4(“mldtmgm”) solved python program doesn’t work

## [Solved] Sub-process in Python execute two task? [closed]

import subprocess subprocess.Popen([‘xterm’, ‘-hold’, ‘-e’, ‘nmap -sV 74.125.130.100’]) this is more easy to execute solved Sub-process in Python execute two task? [closed]

## [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