Created
March 26, 2011 22:16
-
-
Save symtkn/888688 to your computer and use it in GitHub Desktop.
karmaşık sayıların mutlak değerinin hesablanması&doctest&string girildiğinde verilen hata mesajı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
#!/usr/bin/env python | |
import math,doctest | |
def mutlak(sayi): | |
""" | |
>>> mutlak(3+4j) | |
5.0 | |
>>> mutlak(-9) | |
9 | |
>>> mutlak(-17.5) | |
17.5 | |
>>> mutlak(6) | |
6 | |
>>> mutlak(4j) | |
4.0 | |
>>> mutlak(58.0) | |
58.0 | |
""" | |
if type(sayi) == type(""): print "Yanl veri girdiniz" | |
elif type(sayi) == type(1+2j): print math.sqrt(sayi.real**2+sayi.imag**2) | |
elif type(sayi) == type(1): | |
if sayi < 0 : print -sayi | |
elif sayi >= 0 : print sayi | |
elif type(sayi) == type(1.0): | |
if sayi < 0 : print -sayi | |
elif sayi >= 0 : print sayi | |
doctest.testmod() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment