python基礎練習題:它是負零(-0)?【難度:1級】--景越Python編程實例訓練營,不同難度Python習題,適合自學Python的新手進階

python基礎練習題:它是負零(-0)?【難度:1級】:

存在兩個零:+0(或只是0)和-0.

編寫返回TRUE;如果輸入數目是-O;否則返回FALSE的函數(TRUE;和FALSE用於Python).

在JavaScript /打字稿/ CoffeeScript的輸入將是一個數.

在Python / Java的/ C / NASM /哈斯克爾/輸入將是一個浮子.

編程目標:

def is_negative_zero(n):
    pass


測試樣例:

@test.describe('Basic Tests')
def basic_tests():
    @test.it('should return true for -0.0 and false for all other numbers')
    def basic_test_case():
        test.assert_equals(is_negative_zero(-0.0), True)
        test.assert_equals(is_negative_zero(-(float("inf"))), False)
        test.assert_equals(is_negative_zero(-5.0), False)
        test.assert_equals(is_negative_zero(-4.0), False)
        test.assert_equals(is_negative_zero(-3.0), False)
        test.assert_equals(is_negative_zero(-1.0), False)
        test.assert_equals(is_negative_zero(0.0), False)
        test.assert_equals(is_negative_zero(1.0), False)
        test.assert_equals(is_negative_zero(2.0), False)
        test.assert_equals(is_negative_zero(3.0), False)
        test.assert_equals(is_negative_zero(4.0), False)
        test.assert_equals(is_negative_zero(5.0), False)
        test.assert_equals(is_negative_zero(float("inf")), False)


最佳答案(多種解法):

點擊查看答案

更多關聯題目:

交流討論:

Python基礎訓練營景越Python基礎訓練營QQ羣
在這裏插入圖片描述
歡迎各位同學加羣討論,一起學習,共同成長!

免責申明:

本博客所有編程題目及答案均收集自互聯網,主要用於供網友學習參考,如有侵犯你的權益請聯繫管理員及時刪除,謝謝
題目收集至https://www.codewars.com/
https://www.codewars.com/kata/is-it-negative-zero-0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章