Posts by Solkarped • 2,428 points
218 posts
-
1
votes3
answers195
viewsA: List without negative number
If you are using the Python 3.8 or higher, you can use Assignment Expressions to assemble your code. This way the code would be: numero = [[], []] while (n := int(input('Valor: '))) > -1: if n %…
-
0
votes4
answers975
viewsA: Return a list from another list in Python
To resolve this issue we can use the following code: def maiores(lis, n): maiores_numeros = list() for c in lis: if c >= n: maiores_numeros.append(c) return maiores_numeros valores =…
-
1
votes2
answers272
viewsA: Function that compares characters from a string and returns true or false
Another way to resolve this issue is: def first_and_last(message): if len(message) != 0: if message[0] == message[-1]: return True return False return True palavra = input('Digite uma palavra: ')…
-
0
votes2
answers154
viewsA: Repeat Structures in Python
Another way to resolve this issue is: # uri 1101 while True: M, N = list(map(int, input().split())) if M <= 0 or N <= 0: break else: menor = min(M, N) maior = max(M, N) soma = 0 for c in…
-
2
votes3
answers575
viewsA: Construct a program to read positive integer n and print all primes in the range [2, n]
Faced with a practical situation and aiming at a better efficiency of the code it would be interesting to organize the logic of the question as follows: Capture the value of n; Calculate all the…
-
0
votes4
answers21246
viewsA: Doubt average with Python 3.5
Another way to resolve the issue is as follows: notas = list(map(float, input('Digite as notas das provas: ').split())) ac = list(map(float, input('Digite as notas das atividades: ').split()))…
-
1
votes5
answers322
viewsA: Python how to print output
There are some ways for you to resolve this issue. 1st form of resolution: In this form you implement a loop for, iterate over the list l and displays each element of the list with the aid of end='…
-
2
votes3
answers5527
viewsA: List in Python with non-repeated values without using set function?
To resolve this issue we can use the following code: from itertools import chain a = [1, 2, 3] b = [3, 4, 5] c = list() for item in chain(a, b): if item not in c: c.append(item) c.sort()…
-
0
votes3
answers425
viewsA: How to define a function that calculates the lowest speed?
To resolve this issue we can use the following script: def velocidade_media(ve, ac, te): velocidades_kmh = list() for v, a, t in zip(ve, ac, te): velo = (v + (a * t)) velocidades_kmh.append(velo)…
-
0
votes2
answers86
views -
0
votes3
answers4032
viewsA: Python, even and odd number counting
From what I understand, you want to implement a script that contains a function that is able to count the number pares and ímpares from a given list. Due to the fact that there are some errors in…
-
0
votes2
answers46
viewsA: Unrecognised error
From what I understand you want to implement a function that returns both to Arithmetic Mean as to the Standard Deviation values. To solve this question you can use the following algorithm: from…
-
1
votes3
answers193
viewsA: Take values less than or equal to 500 from the list - Python
From what I understand, you want to implement an algorithm that takes all the values menores ou iguais 500 from a given list and calculate your Arithmetic Mean. Well, you no need to create another…
-
0
votes2
answers151
viewsA: How to simplify this code in Python?
From what I understand you want to implement an algorithm that is able to split a list into N sublists. To solve this question we can use the following algorithm: def group(lis, n): return…
-
0
votes3
answers227
viewsA: Lambda python function
If your intention is to implement a function lambda to verify the maior element of any list with N elements, you can use the following algorithm... from functools import reduce lista = list(map(int,…
-
0
votes2
answers313
viewsA: Fill list and finish python loop
From what I understand you want to add names inside a list until you decide parar. For this, you can use the following algorithm: cont = 0 elementos = list() while True: cont += 1…
-
0
votes7
answers1969
viewsA: How to remove repeated numbers from a python list
To resolve this issue we must follow the following steps: Capture the values; Store them in a list; Pass this list as argument to the function remove_repetidos(); Remove the repeated values; Display…
-
1
votes2
answers1540
viewsA: Transforming vectors into a Matrix
Imagine you have multiple vectors SAME-LENGTH - vectors that have the same number of elements - and want to mount a "matriz" with these vectors. In this case, you can use the algorithm shown below.…
-
0
votes1
answer72
viewsA: How can I write a loop to calculate each value of a list that is not predefined
To solve this question you can use the following algorithm: import numpy as np m = int(input('Digite o número de linhas: ')) n = int(input('Digite o número de colunas: ')) lista = list() for i in…
-
0
votes2
answers912
viewsA: How to display an upper triangular matrix?
The subtype matriz triangular is only applicable to square matrices. Thus, any triangular matrix - upper or lower - will necessarily always be a square matrix. According to this definition a matrix…
-
1
votes2
answers1152
viewsA: Square Matrix in Python 3
This question refers to the number problem 1557, of the site Uri Online Judge of the category Beginners. See here the entirety of the statement. As it is possible to notice the first paragraph of…
-
0
votes3
answers529
viewsA: Product between scalar and array
If you wish to resolve this issue using the library numpy, can use the following algorithm... import numpy as np a = np.array([0.4850045, 0.45512111]) b = np.array([-0.03116616]) prod = (a * b)…
-
1
votes3
answers1952
viewsA: Sum of the main diagonal of a matrix in Python
To resolve this issue we must: Capture the matrix elements; Assemble such a matrix; Calculate the sum of the main diagonal; Display the created matrix; Display the sum of the main diagonal widgets.…
-
0
votes4
answers3471
viewsA: Matrix generator in Python
One of the correct ways to assemble a two-dimensional matrix in python is by using the algorithm shown below. Note also that in this algorithm I used the library numpy which must be installed…
-
1
votes3
answers176
viewsA: Doubt exercise with lists
One of the correct ways to solve this issue is to use the following algorithm... def quantidade_positivos(numeros): cont = 0 for x in numeros: if x > 0: cont += 1 print(f'\033[32mA quantidade de…
-
0
votes4
answers65
viewsA: I cannot print a list(vector)
Another interesting way to implement a converter decimal for binário is: print('=' * 68) print(f'\033[34m{"Conversor Decimal para Binário":^68}\033[m') print('=' * 68) cont = 0 while True: cont += 1…
-
0
votes2
answers201
viewsA: Matrix in python
When we are working with matrices we must know the number of linhas and also the number of colunas. If your intention is to assemble an array you can use the following algorithm below. Note that, in…
-
0
votes2
answers140
viewsA: How to verify if a poetic composition is a tautograma?
As I understand it, the questioner is trying to implement an algorithm that checks whether or not a word sequence is a tautograma. Well. First of all we must define what is tautograma. Tautograma is…
-
0
votes3
answers1384
viewsA: Problem with Python matrices
Note: We can only operate diagonals of a matrix if it is SQUARE. In other words, it only makes sense to speak in diagonals if the number of rows in the matrix is igual to the number of columns.…
-
0
votes4
answers457
views -
0
votes2
answers2091
viewsA: Remove Repeated Integers List in Python
If you just want to remove the repeated integers from the cited list, you can use the following algorithm... lista = [1, 2, 3, 3, 3, 4, 5, 6, 6, 7, 8] nova_lista = list() for c in lista: if c not in…
-
0
votes2
answers9159
viewsA: Read multiple numbers on the same line with raw_input
To resolve this issue we can use the following code... x = list(map(float, input('Digite os valores "A", "B" e "C": ').split())) triangulo = ((x[0] * x[2]) / 2) print("TRIANGULO:", "%.3f" %…
-
0
votes5
answers115
viewsA: Browse lists of different sizes
From what I understand, you’re willing to go through both lists simultaneously and add up the corresponding values of the two list, index by index. For this you should realize that there are three…
-
0
votes3
answers110
viewsA: Bubble Sort algorithm error in Python
If you wish sort out values it makes no sense to capture strings. So it is more convenient to directly capture the numerical value. I realized that the values you are working on are integer, so I…
-
0
votes4
answers573
viewsA: how to create a list of multiples of numbers of 3, from another list of numbers?
For you to create a new lista, containing the multiples of 3, contained initially in another list, you can use the following algorithm... meus_numeros = [1, 56, 342, 12, 781, 23, 43, 45, 123, 567]…
-
2
votes3
answers269
viewsA: How to Restart a Python Program?
You need to implement a loop loop. In this case, the best way is to use the while. For this issue I implemented the following algorithm... while True: a_1 = float(input('Primeiro Termo: ')) a_2 =…
-
0
votes3
answers380
views -
0
votes7
answers7922
viewsA: Convert an array of floats to integer
The method array class numpy supports in all 6 types of parameters. Among these parameters we have the dtype. This, in turn, serves to identify the type of data desired for the object array. See…
-
2
votes3
answers133
viewsA: Round Decimal
You can use list comprehension. In this case the answer would be... lista = [2.23453, 2.34543, 2.457755] lista_1 = [round(item, 2) for item in lista] print(lista_1) In this case, the items on the…
-
0
votes1
answer43
viewsA: In this program, I wanted it to include in the final list the even numbers of the first list and the odd numbers of the second, why doesn’t this happen?(python)
What’s happening in your question is that you’re removing, precisely the elements you wish to display. When you do... for elementos in lista_1: if elementos % 2 == 0: lista_1.remove(elementos) ...…
-
-1
votes1
answer452
viewsQ: How to make the columns of the Floyd Triangle perfectly symmetrical?
I’m developing an algorithm to form and display a Triângulo de Floyd with n lines. The code is just below: n = int(input(f'Digite o número de linhas: ')) m = 1 for c in range(1, n + 1): for i in…
-
1
votes3
answers381
viewsA: How to create expression that returns 1,12,123,1234 in Python
If you want to generalize this question to the point of power especificar the number of lines in this triangle, you can use the following algorithm... # Capturando e tratando a quantidade de linhas:…
-
0
votes3
answers1508
viewsA: Python Vector Fill 3
You can use the following algorithm... entrada = list(map(float, input().split())) print(f'\033[32mO resultado é: {entrada}') See how the algorithm works on repl it.. Note that when we run this…
-
0
votes2
answers659
viewsA: Problem with float python (Uri 1098)
This issue refers to the number challenge 1098, whose title is Sequence IJ 4 made available by Uri Online Judge. See here the entirety of the statement. To solve this issue we must develop an…
-
0
votes2
answers418
viewsA: Browse 2D list in Python
You can display all items of a sublist in a single row, i.e., use a row to display all items of a sublist. For this you can use the following algorithm... lista = [[10, 20, 30, 40], [50, 60, 70,…
-
0
votes3
answers613
viewsA: Show python position of prime only
To solve this question we must read and store a total of ten values in a vector. Then check which of them are primes and then display the value and position of said prime. For this we can use the…
-
1
votes3
answers2675
viewsA: Is it possible to include more than one variable per input in Python?
If your intention is to capture multiple values from one input(), you can use one of the command lines listed below: Example 1: valores = list(map(int, input('Digite todos os valores: ).split()))…
-
0
votes2
answers2053
viewsA: Eoferror: EOF when Ading a line
This question which has as its title Colchão, was initially made available by OBI 2012 and subsequently made available by Uri Online Judge, with the same title, Colchão, and with the numbering 2409…
-
0
votes9
answers23719
viewsA: Inverting sequence (PYTHON 3)
From what I understand, the number 0 shall not be counted or entered in the list. In this case, the 0 will only function as flag stop, that is, when the value is entered "0", normal program flow…
-
1
votes3
answers304
viewsA: What is the difference between the modules Math and cmath?
I created this diagram to display more clearly and objectively the hierarchical distribution of the numerical sets. As we can observe each numerical set is represented by a certain letter, i.e.: N -…