python FizzBu​​zz.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python FizzBu​​zz.py相关的知识,希望对你有一定的参考价值。

import unittest
import random

class TestFizzBuzz(unittest.TestCase):

  @staticmethod
  def fizz_buzz(value=None):
    value = value if value is not None else random.randint(0, 100) # - случайное целое число N, A ≤ N ≤ B.
    result_dict = {0: value, 1: "fizz", 2: "buzz", 3:"fizzbuzz"}

    tmp = 0
    if value % 3 == 0:
      tmp += 1
    if value % 5 == 0:
      tmp += 2

    print(value, result_dict[tmp])
    return result_dict[tmp]

  def test_print_integer(self):
      self.assertEqual(TestFizzBuzz.fizz_buzz(11), 11)

  def test_print_fizz(self):
      self.assertEqual(TestFizzBuzz.fizz_buzz(9), "fizz")

  def test_print_buzz(self):
      self.assertEqual(TestFizzBuzz.fizz_buzz(25), "buzz")

  def test_print_fizzbuzz(self):
      self.assertEqual(TestFizzBuzz.fizz_buzz(15), "fizzbuzz")

if __name__ == '__main__':
    # unittest.main()

    for i in range(1, 101):
      TestFizzBuzz.fizz_buzz(i)

以上是关于python FizzBu​​zz.py的主要内容,如果未能解决你的问题,请参考以下文章

FizzBu​​zz 使用三元条件运算符

javascript FizzBu​​zz

javascript FizzBu​​zz

javascript FizzBu​​zz

markdown FizzBu​​zz

html FizzBu​​zz