Posts by Solkarped • 2,428 points
218 posts
-
0
votes2
answers114
viewsA: Does anyone know how to create this program?
From what I understand you want to implement a code in Python that is able to assemble two lists - class A and class B - storing the grades of their respective students, in addition to putting…
-
0
votes2
answers66
viewsA: Receive items from an ordered list in a variable - Python
Another way to get the result desired by the questioner is by using the combination of the function map() with the expression lambda. In this way the following code can be implemented: num = [2, 5,…
-
0
votes4
answers140
viewsA: How to print more than a maximum number of a list
From what I understand you want to implement an algorithm that is able to capture the name of 5 students, storing them within a list and capturing the notes of these 5 students, storing them within…
-
1
votes1
answer107
viewsA: I can’t solve the issue of distance between friends
This question refers to the problem Distance between friends made available by OBI 2019 and. subsequently, made available by the website URI Online Judge with the same title and numbering 3050 of…
python-3.xanswered Solkarped 2,428 -
0
votes2
answers105
viewsA: How can I turn a string into a float?
Another interesting way to resolve this issue is by using the following code: h = ["3,5", "4,3", "8,9"] m = [round(50 / float(i.replace(',', '.')), 2) for i in h] print(m) Note that when we execute…
-
1
votes2
answers376
viewsA: python search
First, the binary search algorithm only works satisfactorily if the list is orderly. Secondly, I realized that you are trying to implement an algorithm of iterative binary search. Well, to implement…
-
3
votes5
answers1031
viewsA: Check that all items in the list are equal
Another way to resolve this issue is by using function with the help of conversion from list to set. This way the code will be: def valores_iguais(lis): if len(set(lis)) == 1: return True return…
-
1
votes2
answers104
viewsA: python vectors, help out?
In this issue you need to follow a well-defined logic. This logic should follow the following steps: Implement a vector with 20 elements; Mount another vector with only positive values of the first…
-
1
votes1
answer43
viewsA: How do I print the output in different lines in this code?
To solve this issue you can use the following code: def divisores(n): for i in range(1, (n // 2) + 1): if n % i == 0: yield i num = int(input()) for j in divisores(num): print(j) According to the…
python-3.xanswered Solkarped 2,428 -
1
votes2
answers52
viewsA: I can’t write a specific number count inside a list
I noticed that your list consists of strings. This way, you must count the string of 5, that is to count how many times the string "5" appears. Therefore, the only thing you have to move is in the…
python-3.xanswered Solkarped 2,428 -
2
votes2
answers1486
viewsA: How to remove square brackets and commas when printing a list in Python?
To display the results without brackets and comma, simply implement a repeat loop displaying the results on the same line, using the espaço as separator. In this case the code would be: numeros =…
-
1
votes1
answer26
viewsA: How do I use line breaking in the answer?
You can capture the values and then implement a repeat loop to display the result. The code would stand: n1 = int(input()) n2 = int(input()) n3 = int(input()) n0 = sorted((n1, n2, n3)) for c in n0:…
python-3.xanswered Solkarped 2,428 -
0
votes3
answers464
viewsA: Identify amount of upper and lower case letters in a string
Another interesting way to resolve this issue is to implement the following code: def forma_letras(v): upper = lower = 0 for d in v: if d.isupper(): upper += 1 else: lower += 1 if upper >= lower:…
-
0
votes1
answer93
viewsA: Very long broken values not being recognized within If, in Python
If, your intention is to implement a code that allows the insertion of only values numerical, of the kind float and are in the closed interval [0, 180] you should pay attention to your decision…
-
3
votes1
answer281
viewsA: How to sort a list in Python
To resolve this issue you can implement the sorting algorithm Bubble Sort. To implement Bubble Sort on this issue we must: Capture the values that will mount the list; Sort these values; Display the…
-
0
votes2
answers51
viewsA: Python- I need to make an application that receives float values and organize them without using . Sort
Another way to solve this question is by using the sort algorithm shell_sort. To implement this algorithm we must: Capture values that will be mounted in the list; Sort the values from that list;…
-
1
votes4
answers36247
viewsA: List files from a Python folder
If your intention is to list only the files of a particular directory you can: Inform the directory path; Request the display of the files in this directory. For this you can use the following code:…
-
1
votes5
answers1328
viewsA: How to create folders in python desktop
To create a folder inside the Desktop we should use the following logic: Specify the name of the folder we want to create on the Desktop; Access the Desktop; Check if the desired folder already…
-
2
votes2
answers104
viewsA: Python - Declaration of a variable in Try
One of the possible ways to resolve this issue is: while True: try: a = int(input('Introduza o primeiro número: ')) break except ValueError: print('Introduza um número inteiro!') while True: try: b…
-
0
votes3
answers1399
viewsA: Python Range - Numbers in descending order
From what I understand, you want to implement a code that is able to display the N first numbers pairs in reverse order. Another way to resolve this issue is: n = int(input('Digite um número: ')) i…
-
3
votes3
answers341
viewsA: Sort a list based on two different criteria using Sorted
To resolve this issue you can use the following code: listaqq = [(4, 2), (5, 2), (7, 3), (9, 4), (6, 4)] print(sorted(listaqq, key=lambda c: (-c[1], c[0]))) Note that in this code the lambda…
-
1
votes2
answers81
viewsA: Insert the values of an N-size vector into the same Python line
From what I understand, you want to implement a code that is able to assemble two vectors of the same size and a third vector, in which each of its elements is the product of the elements of the…
-
2
votes4
answers265
viewsA: Check if delta is less than zero (Bhaskara’s formula)
To resolve this issue you should pay attention to some things, such as: Knowing how to capture the values of coefficients; Calculate the value of delta and, also, the roots; Correctly display…
-
4
votes2
answers2710
viewsA: Convert decimal to binary - python
I know the previous answer already answers sufficiently the question. However, I solved the issue with a new outfit. The code is: valor = input('Insira um valor a ser criptografado: ') for c in…
-
4
votes2
answers275
viewsA: How to write a program that fills a 10-position vector with random integers between 0 and 20?
To answer this question you can use the following code: import numpy as np v = np.random.randint(0, 21, 10) print(v) Note that the vector v will be mounted with 10 values belonging to the closed…
-
1
votes3
answers166
viewsA: how to find the indexes of an item that repeats in a list in Python
To resolve this issue you will need to implement a repeat loop and scroll through such list with the help of enumerate function(). Following this logic we can implement the following code: l = [1,…
-
0
votes5
answers789
viewsA: List comprehension with conditional
From what I understand you want to implement a list comprehension in which you can count the number of times the value "10" I repeated in that list. Well, to resolve this issue we can use the…
-
0
votes5
answers29639
viewsA: How to convert an int number to string in python?
To resolve this issue is enough: Capture numeric value as string; Reverse this string; Display the reverted value. With this logic we can implement the following code: print(input('Digite um número…
-
0
votes1
answer24
viewsA: How to display elements of specific sizes belonging to a list using lambda and filter functions?
To resolve this issue, just use the following code: lstNomes = ["casa", "google", "escola"] lstFiltro = list(filter(lambda x: len(x) <= 5, lstNomes)) print(lstFiltro) Observation 1: How you want…
-
1
votes5
answers312
viewsA: Make a function that calculates the following sum:
To resolve this issue you can implement two functions. One of them to calculate the factorial of the number and another to produce the summation of values. OBSERVATION 1: Observe the layout of the…
-
2
votes1
answer74
viewsA: Make a function called soma_h to compute and return the value H with N terms where N is integer and given with input
What you need is to implement a function to calculate the sum of the inverses of the first positive INTEGERS. def soma_h(n): soma = 0 for c in range(1, n + 1): inverso = (1/c) soma += inverso return…
-
0
votes9
answers17879
viewsA: How to identify if a string is a palindrome?
One of the ways to check whether a word is palindromic is: palavra = input('Digite uma palavra: ').lower().strip().replace(' ', '') if palavra == palavra[::-1]: print('É palíndromo') else:…
-
1
votes2
answers639
viewsA: Generate random numbers in 2d numpy array without repeating Python
From what I understand, you want to implement an array in which all your values are missing repeated. Note that when we are working with matrices we have to make clear the number of rows and…
-
6
votes3
answers515
viewsA: Sum of factorial in a specific range
The factorial of a number n, for definition is the product of all numbers starting with n until 1. Well, to calculate the factorial of a number we can use the following code: def fatorial(n): prod =…
-
1
votes2
answers172
viewsA: Intersection between lists without repeating elements
Another interesting way to resolve this issue is the following: from itertools import chain A = [int(x) for x in input('Valores de "A": ').split()] B = [int(x) for x in input('Valores de "B":…
-
0
votes2
answers168
viewsA: Would you like to make a code that spells out the word?
For you to spell a word you can implement the following algorithm: Captures a word; Implements a loop loop loop; In each loop interaction displays the position and the referred letter; Ask if you…
-
0
votes2
answers1261
viewsA: Python URI Online Judge (1021): what’s wrong with my code?
You are receiving the message from Wrong Answer (100%) due to rounding gaps. To resolve this issue correctly, according to all the restrictions that are passed to us by the platform of URI, we…
-
0
votes3
answers1665
viewsA: multiples of 2 and 3 in python
To calculate the multiples of two values you can use the following code: m = int(input('Digite o primeiro número: ')) n = int(input('Digite o segundo número: ')) q = int(input(f'Desejas calcular…
-
0
votes6
answers14517
viewsA: How to define the largest prime number within a given number?
From what I understand from your statement, you want to implement a code that is able to display the greater prime number less than or equal to the number "n". To resolve this issue you can use the…
-
1
votes2
answers157
viewsA: How to optimize this code?
This question refers to the number problem 1089 of the category AD-HOC of the site URI. See here the entirety of the statement. Well, in order to solve this problem we only need to use the following…
-
0
votes2
answers30
viewsA: Doubt called function by loop
To solve this issue you can use the following code: def somaimpostos(taxa, cust): return (1 + taxa/100)*cust while True: taxa_imposto = 10 custo = float(input('Qual o custo do produto? '))…
-
0
votes3
answers693
viewsA: I can’t make the sum of the first 100 prime numbers, where am I wrong?
To resolve this issue I implemented the following code: # Este programa calcula a soma dos "n" primeiros números primos. def soma_primos(n): li = 2 primos = list() while len(primos) < n: if…
-
0
votes2
answers693
viewsA: How to generate a range from A to B-1 in Python?
From what I understand you want to implement a code that is able to verify if a certain number is cousin. According to the definition, prime numbers sane: natural numbers greater than 1 that have…
-
0
votes2
answers52
viewsA: I have the following problem on my tuple
From what I understand, you want to implement a code that is able to perform conversions of temperatures and print their values with 4 decimal places. Well, when we are working with temperature…
-
0
votes4
answers2542
viewsA: Access list element within Python list
From what I understand you want to implement a script that is able to display only the first of the ordered pair contained in each sublists of a particular list. Well, to implement a code that is…
-
4
votes4
answers406
viewsA: Return the missing element from a list of integer numbers
To verify ALL the numbers that may be missing from a list whichever, just use the code below. NOTE: This code may include any lists of integers - increasing, decreasing, alternating, with positive…
-
1
votes3
answers169
viewsA: Doubt about Python data output
To print the natural numbers starting at "1" and going up to "20", one below the other, just use the following algorithm: x = 1 while x < 21: print(x) x += 1 or for c in range(1, 21): print(c)…
-
0
votes2
answers1329
viewsA: Change size of Plot area
For starters, your code won’t run anywhere. Why? Because it has numerous errors - did not import the library, did not list the points, etc. Faced with these problems, I decided to implement a…
-
4
votes3
answers155
viewsA: How do I remove the last "," that appears in the print?
To solve this problem we must devise a strategy so that we can print a comma after each value, except the last one. One of the ways we can build the following strategy is by using the following…
-
4
votes3
answers351
viewsA: How to access the key, by value, in python dictionary?
From what I understand, you want to implement a script that is able to mount a dicionário containing nome and altura of 10 people and then display the name of the tallest person. Well, you can use…