Advertisement
osmarks

Untitled

Feb 22nd, 2021
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import math
  4.  
  5. # test primality using trial division
  6. def is_prime(n):
  7.     # 1 is not prime but will be considered one by the test
  8.     if n < 2: return False
  9.     # range's upper bound is exclusive, so add 1 to the number which must be checked up to
  10.     # if n is composite/not prime, it must have a factor <= than its square root, so only check factors up to there
  11.     for factor in range(2, math.ceil(math.sqrt(n)) + 1):
  12.         # if factor is a divisor, it cannot be prime
  13.         if n % factor == 0: return False
  14.     return True
  15.  
  16. p, q, end = map(int, input("Game config: ").split(" "))
  17.  
  18. for i in range(1, end + 1):
  19.     # Game logic
  20.     # if p divides i AND q divides i, print FizzBuzz
  21.     # if p divides i but q doesn't, print Fizz
  22.     # if q divides i but p doesn't, print Buzz
  23.     # if i is prime, print OOPS!
  24.     # otherwise just print the number
  25.     if i % p == 0 and i % q == 0: print("FizzBuzz")
  26.     elif i % p == 0: print("Fizz")
  27.     elif i % q == 0: print("Buzz")
  28.     elif is_prime(i): print("OOPS!")
  29.     else: print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement