Posts by danbros • 47 points
3 posts
-
1
votes2
answers3090
viewsA: Function that returns the smallest prime number in Python
Using while (no generating expression): def maior_primo(num): while num > 2: i = 2 while True: if num % i == 0: break if i == num - 1: return num i = i + 1 num = num - 1 Using for (no generating…
-
1
votes3
answers713
viewsA: Print the largest substring of s where the letters occur in alphabetical order
A simple way to get the result is: # O(len(s)) temp = sub_s = s[0] for i in range(len(s)-1): if s[i] <= s[i+1]: temp += s[i+1] if len(temp) > len(sub_s): sub_s = temp else: temp = s[i+1]…
-
2
votes1
answer153
viewsQ: How to pass the return of a function that is a tuple as arguments to another one in Python?
I’m trying to return multiple values from one function to another with multiple parameters: def chamar_ab(): a = 1 b = 2 return a, b #tupla def soma(x, y): return x + y But using it doesn’t seem…