Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 7a5a431d authored by Dorian Turba's avatar Dorian Turba
Browse files

Update FizzBuzz/spoiler_python_3:star:.py

parent e58a355e
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,18 @@ start = int(input("start:")) ...@@ -3,6 +3,18 @@ start = int(input("start:"))
end = int(input("end:")) end = int(input("end:"))
for n in range(start, end + (start < end or -1), start < end or -1): for n in range(start, end + (start < end or -1), start < end or -1):
# SPECIAL
BALROG = (n % 666 == 0)
str_n = str(n)
NARCISSE = (n == sum(int(digit) ** len(str_n) for digit in str_n if digit != '-'))
if BALROG:
print("Balrog!")
continue
elif NARCISSE:
print("Narciss")
continue
# BASIC # BASIC
MULTIPLE_3 = (n % 3 == 0) MULTIPLE_3 = (n % 3 == 0)
MULTIPLE_5 = (n % 5 == 0) MULTIPLE_5 = (n % 5 == 0)
...@@ -10,11 +22,6 @@ for n in range(start, end + (start < end or -1), start < end or -1): ...@@ -10,11 +22,6 @@ for n in range(start, end + (start < end or -1), start < end or -1):
MULTIPLE_7 = (n % 7 == 0) MULTIPLE_7 = (n % 7 == 0)
MULTIPLE_10 = (n % 10 == 0) MULTIPLE_10 = (n % 10 == 0)
# SPECIAL
BALROG = (n % 666 == 0)
str_n = str(n)
NARCISSE = (n == sum(int(digit) ** len(str_n) for digit in str_n if digit != '-'))
# First part # First part
FLASH = MULTIPLE_3 and MULTIPLE_7 FLASH = MULTIPLE_3 and MULTIPLE_7
FIZZ = MULTIPLE_3 and not FLASH FIZZ = MULTIPLE_3 and not FLASH
...@@ -25,20 +32,11 @@ for n in range(start, end + (start < end or -1), start < end or -1): ...@@ -25,20 +32,11 @@ for n in range(start, end + (start < end or -1), start < end or -1):
# Third part # Third part
BUZZ = MULTIPLE_5 BUZZ = MULTIPLE_5
if BALROG: predicate_txt_pairs = (
print("Balrog!") (FLASH, "Flash"),
continue (FIZZ, "Fizz"),
elif NARCISSE: (LIGHT, "Light"),
print("Narciss ") (BUZZ, "Buzz"),
continue )
s = "" print("".join(txt for predicate, txt in predicate_txt_pairs if predicate) or n)
if FLASH:
s += "Flash"
if FIZZ:
s += "Fizz"
if LIGHT:
s += "Light"
if BUZZ:
s += "Buzz"
print(s or n)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment