Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import math
- # test primality using trial division
- def is_prime(n):
- # 1 is not prime but will be considered one by the test
- if n < 2: return False
- # range's upper bound is exclusive, so add 1 to the number which must be checked up to
- # if n is composite/not prime, it must have a factor <= than its square root, so only check factors up to there
- for factor in range(2, math.ceil(math.sqrt(n)) + 1):
- # if factor is a divisor, it cannot be prime
- if n % factor == 0: return False
- return True
- p, q, end = map(int, input("Game config: ").split(" "))
- for i in range(1, end + 1):
- # Game logic
- # if p divides i AND q divides i, print FizzBuzz
- # if p divides i but q doesn't, print Fizz
- # if q divides i but p doesn't, print Buzz
- # if i is prime, print OOPS!
- # otherwise just print the number
- if i % p == 0 and i % q == 0: print("FizzBuzz")
- elif i % p == 0: print("Fizz")
- elif i % q == 0: print("Buzz")
- elif is_prime(i): print("OOPS!")
- else: print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement