Created
April 19, 2024 18:07
-
-
Save Yuhtin/829b5eb750ac09ff06011ea60352c7a0 to your computer and use it in GitHub Desktop.
Print sorted and unduplicated numbers with variable range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def requestNumbers(): | |
str = input('Digite os números iniciais: ') | |
splitted = str.split(' ') | |
number1 = float(splitted[0]) | |
number2 = float(splitted[1]) | |
return [ number1, number2 ] | |
def preencher(): | |
valores = [] | |
i = 0 | |
while True: | |
str2 = input(f"Digite o número[{i + 1}]: ") | |
if (str2 == ""): return valores | |
if " " in str2: | |
str2 = str2.split(' ')[0] | |
valores.append(float(str2)) | |
i += 1 | |
initialNumbers = requestNumbers() | |
number1 = initialNumbers[0] | |
number2 = initialNumbers[1] | |
valores = preencher() | |
print(f'Número 1: {number1}') | |
print(f'Número 2: {number2}') | |
ordered = sorted(valores) | |
notRepeated = [] | |
for i in range(len(ordered)): | |
if i >= len(ordered) - 1 or ordered[i] != ordered[i+1]: | |
notRepeated.append(ordered[i]) | |
print(f'Menor do que o número {number1}:') | |
for number in notRepeated: | |
if number < number1: | |
print(number) | |
print() | |
print() | |
print(f'Maior ou igual do que o número {number1} e menor do que o número {number2}:') | |
for number in notRepeated: | |
if number >= number1 and number < number2: | |
print(number) | |
print() | |
print() | |
print(f'Maior do que o número {number2}:') | |
for number in notRepeated: | |
if number > number2: | |
print(number) | |
print() | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment