[Solved] Create a class that takes a matrix for instantiation

Start from this simple skeleton: class Matrix: def __init__(self, matrix): self.matrix = matrix def double_diagnonal_entries(self): # do calcs return self.matrix Note, that if you need to implement some basic matrix ops like addition you might consider operator overloading such as: def __add__(self, another_matrix): # do the math return sum_matrix solved Create a class that takes … Read more

[Solved] New class or new .py Python

tl;dr keep everything in one file for now, split subsequently while refactoring when the file becomes huge. Python does not force you split classes / functions into modules. We as programmers make that call for solely the purpose of readability and maintainability. While refactoring I personally look at functions with more ~40 – 50 lines … Read more

[Solved] Python raw_input to extract from dictionary

Solution while True: prompt = int(raw_input(” Enter ID of person you would like to search for: “)) if prompt > 100: print(“Please try again”) continue elif prompt < 1: displayPerson(prompt,persons) else: break print(“Terminated.”) Explanation You enter the loop and get an ID from the user. If prompt > 0: display the person Otherwise, break out … Read more

[Solved] How draw bounding box on Specfic Area using Opencv python? [closed]

Here is my Python/OpenCV code. I can get the region by a judicious choice of area thresholding. But this is not likely going to be robust for other images. Input: import cv2 import numpy as np # read image img = cv2.imread(“younas.jpg”) # convert img to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # median filter gray … Read more

[Solved] TypeError: cannot concatenate ‘str’ and ‘list’ objects. how to convert list to string [closed]

str(tuple(str(fv[“v”]).split(‘,’))) will probably give you what you want but if you give more information there is definitely a better way to write this. What does fv[‘v’] consist of? 2 solved TypeError: cannot concatenate ‘str’ and ‘list’ objects. how to convert list to string [closed]

[Solved] Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How do I do this?

Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How do I do this? solved Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How … Read more

[Solved] how to take (6+5) as a single input from user in python and display the result [closed]

Here is a simple calculator example to help get you started. while True: num1 = input(‘First Number: ‘) num2 = input(‘Second Number: ‘) op = input(‘Operator: ‘) try: num1 = int(num1) num2 = int(num2) except: print(‘Input a valid number!’) continue if op not in [‘+’, ‘-‘, ‘*’]: print(‘Invalid operator!’) continue if op == ‘+’: print(str(num1 … Read more

[Solved] Getting a none type error python 3?

In insertEnd, you’re guaranteeing you always have None for actualnode at the end of the loop: def insertEnd(self, data): self.size += 1 newnode = Node(data) actualnode = self.head # Keep going until actualnode is None while actualnode is not None: actualnode = actualnode.nextnode # Here actualnode will always be None actualnode.nextnode = newnode To fix … Read more

[Solved] ISSN Calculator in Python

IMMEDIATE PROBLEM You increment your index value before you use it; this means that on the final iteration, it’s 1 too large for the final operation. Switch the bottom two lines of your loop: index = 0 while index < 7: print(arr[index]) totalNum = int(num[index]) * arr[index] index += 1 Even better, this should be … Read more

[Solved] python string format without {}

I think this is more of a subjective question. I would argue that its ok following the principle of duck typing: If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck. If you are looping through an array of strings and they all have … Read more

[Solved] the error is ‘int’ object is not iterable, I am working on a small project in python that allows the user to input ten names and ten ages of students [closed]

for element in range(10): … input_ages = int(input(“\t\t\t\t\tNow please input their ages as well: “)) team_leader = max(input_ages) input_ages is a single integer that gets reassigned each loop iteration. max(input_ages) expects input_ages to be a list for which to find the maximum value by iterating over it. Therefore you get ‘int’ object is not iterable. … Read more