[Solved] How do i define a printed text in python?

The best way is to define a variable, like this: a = “Printed text” print(a) And if you want to verify wih another string, use b = input() and verify with tis variable. if a == b: print(“Yes”) else: print(“No”) solved How do i define a printed text in python?

[Solved] python 3.6.1 ‘FOR LOOP’

try this, import sys for j in range (0,n): for i in range (n-j+1): sys.stdout.write(‘ ‘); for k in range (j+1): sys.stdout.write(‘#’); print() 1 solved python 3.6.1 ‘FOR LOOP’

[Solved] Project Euler # 8- Find biggest product of n adjacent digits in number. Code works only for some values of n [closed]

I think the issue has to do with you’re getting your substrings. You’re slicing a multiline string, and so some of your slices will include a newline character instead of a digit. Though your multiplication code will ignore those newlines, they still matter since they change the number of actual digits in the multiplication. If … Read more

[Solved] Sorting multiple rows as a single column using Python.

import re import csv with open(‘data.txt’) as f: data = [] for line in f: items = re.split(‘[\s]+’, line.strip()) if not line.strip().startswith(‘K1’): data.append([]) data[-1].extend([items[0]] + items[2:]) else: data[-1].extend(items[1:]) data = list(map(list, zip(*data))) with open(‘data.csv’, ‘w’) as f: writer = csv.writer(f) writer.writerows(data) And your csv data looks like this: -29-,-30-,-31-,-32-,-33-,-34-,-35-,-36-,-37- 4.2735E+05,9.2186E+05,9.4197E+05,9.4089E+05,9.4889E+05,9.5109E+05,9.6455E+05,9.4382E+05,-4.8051E+06 4.3904E+05,9.2199E+05,9.4200E+05,9.4070E+05,9.4904E+05,9.5097E+05,9.6459E+05,9.4314E+05,-2.1630E+07 4.5718E+05,9.2134E+05,9.4127E+05,9.4016E+05,9.4849E+05,9.5042E+05,9.6377E+05,9.4290E+05,-8.8415E+07 4.8817E+05,9.2164E+05,9.4106E+05,9.4026E+05,9.4857E+05,9.5052E+05,9.6384E+05,9.4317E+05,-2.3794E+08 5.4312E+05,9.2075E+05,9.4132E+05,9.4015E+05,9.4842E+05,9.5047E+05,9.6355E+05,9.4365E+05,-5.2223E+08 7.3055E+05,9.1836E+05,9.4327E+05,9.3932E+05,9.4797E+05,9.4989E+05,9.6521E+05,9.4070E+05,-1.7084E+09 … Read more

[Solved] Change color in RGB images

I have to agree with Majid Shirazi regarding the proposed solution by Quang Hong. Let’s have a look at: idx = np.where(img == (0.4, 0.4, 0.4)) Then, idx is a 3-tuple containing each a ndarray for all x-coordinates, y-coordinates, and “channel”-coordinates. From NumPy’s indexing, I can’t see a possibility to properly access/manipulate the values in … Read more

[Solved] TypeError: ‘float’ object cannot be interpreted as an index, how to solve it?

can you write in your question an example of what the values of pts[0], pts[1], pts[2] looks like? if the values are close to integers (like 1.00004 or 3.9998) you can use the round function to round the values to the nearest integer like: data = array(data, ‘f’).reshape(round(pts[2]), round(pts[1]), round(pts[0])) solved TypeError: ‘float’ object cannot … Read more

[Solved] Separate a row of strings into separate rows [closed]

Python Power Unleased : import csv,sys filename=”a.csv” with open(filename,’rb’) as csvfile: reader = csv.reader(csvfile,delimiter=”,”) try: for row in reader: if row[1].find(‘,’) == -1: line=”,”.join(row) print line else: for i in range(0,row[1].count(‘,’)+1): line = row[0]+’,’+row[1].split(‘,’)[i]+’,’+row[2].split(‘,’)[i] print line except csv.Error as e: sys.exit(‘file %s, line %d: %s’ % (filename, reader.line_num, e)) solved Separate a row of strings … Read more

[Solved] Writing to another text file and more?

import random import time adding = input(“Enter Name: “) with open(“settings.txt”, “a+”) as f: f.write(‘\n’.join(i for i in adding.split() if len(adding.split(” “))>1 else adding)) data = a.readlines() for line in data: print (line) time.sleep(10) Try this. This prompts the user for input, splits that input across whitespace (so if I enter “Adam D. Smith” it … Read more

[Solved] Python – Put new line into file at largest indent

You may want a code something like – start = 1 lines = [‘Step’ + str(start) + ‘:\n’] with open(‘file.txt’,’r’) as inF: prevspace = -1 for line in inF: lspaces = len(line) – len(line.lstrip()) if lspaces > prevspace and prevspace != -1: lines.append(‘Step’ + str(start+1) + ‘:\n’) start = start + 1 lines.append(line) prevspace = … Read more

[Solved] how get input of multiple lines

Is this what you are after? >>> d=[] >>> while(True): … s=raw_input() … if s==””:break … temp = [s] … d.append(temp) … a,b,7-6,7-6,6-3 c,d,7-4,7-6,6-2 e,f,6-4,7-6,6-2 >>> d [[‘a,b,7-6,7-6,6-3’], [‘c,d,7-4,7-6,6-2’], [‘e,f,6-4,7-6,6-2’]] This makes a list item out of the input and then appends that list to your main list d You now should be able to … Read more

[Solved] Python script counting lines in multiple text files in one directory and producing simple report

Your names dict looks like that: { ‘file1.txt’: 30, ‘file2.txt’: 26, ‘file3.txt’: 19, ‘file4.txt’: 19 } So you’d just have to start from that and follow with: from collections import defaultdict lines = defaultdict(int) for val in names.values(): lines[val] += 1 for k, v in lines.items(): print(“Files with {} lines: {}”.format(k, v)) This will print … Read more

[Solved] Run python code from a certain point

It sounds from your question like you have some lines at the beginning of a script which you do not want to process each time you run the script. That particular scenario is not really something that makes a lot of sense from a scripting point of view. Scripts are read from the top down … Read more

[Solved] Python performance [closed]

I made a great experience with Cython (Another thing than CPython…). You can make plain C code out of your program, compile it to an extension and just run it from another Python file. See this question from me for more information on building an extension including numpy: How to create a .pyd file?. Sample: … Read more