Posts by Marco Raad • 43 points
6 posts
-
0
votes5
answers312
viewsQ: Make a function that calculates the following sum:
S = 10/1! - 9/2! + 8/3! ... - 1/10! def soma(): fat = 1 somar = 0.0 for i in range(1, 11): fat *= i for k in range(i, 0, -1): somar += k/fat return round(somar, 2) I arrived at this code but the…
-
2
votes1
answer74
viewsQ: Make a function called soma_h to compute and return the value H with N terms where N is integer and given with input
I made the code but I don’t know why the output is 1. def soma_h(n): soma = 0 for i in range(1, n+1): soma = soma + float(1//i) return round(soma, 2) Note: H = 1 + 1/2 + 1/3 ... + 1/n…
pythonasked Marco Raad 43 -
5
votes3
answers515
viewsQ: Sum of factorial in a specific range
I need to add the factors from 1 to 10, but I have not found the best way to implement this function. def soma_fatorial(): resultado = 1 for i in range(1, 11): resultado = resultado * i return…
pythonasked Marco Raad 43 -
-2
votes1
answer491
viewsQ: Two dice game in Python
I couldn’t do a function that simulates a two-dice game and counts how many times the dice were played until repeated numbers come out. def dados(): dado1 = [random.randint(1,6)] dado2 =…
pythonasked Marco Raad 43 -
1
votes4
answers406
viewsQ: Return the missing element from a list of integer numbers
Make a function called missing that, given a list with N 1 integers numbered from 1 to N, finds out which integer of this range is missing. I can’t find a code that covers any list of integers. def…
pythonasked Marco Raad 43 -
-1
votes4
answers975
viewsQ: Return a list from another list in Python
Given a list of integers and an integer n, returns another list, which contains all the numbers in the original list larger than n. I am unable to return the list I need. from typing import List def…
pythonasked Marco Raad 43