def test_add_strings(self): """ Test the addition of two strings returns the two string as one concatenated string """ result = math.add('abc', 'def') self.assertEqual(result, 'abcdef')
def a_plus_abs_b(a, b): """Return a+abs(b), but without calling abs. >>> a_plus_abs_b(2, 3) 5 >>> a_plus_abs_b(2, -3) 5 """ if b < 0: f = sub() else: f = add() return f(a, b)
import math Hello print(math.add(2, 3))
def test_add(self): result = math.add(10, 5) self.assertEqual(result, 15)
# import all import math print(math.add(1, 2)) print(math.minus(2, 1)) # import by name from math import add, minus print(add(1, 2)) print(minus(2, 1)) # import with another name import math as math1 print(math1.add(1, 2)) print(math1.minus(2, 1)) # import with another name from math import add as add1, minus as minus1 print(add1(1, 2)) print(minus1(2, 1))
def calculate(self, method, val1, val2): # 3. Control Flow Statements if method == 'add': return add(val1, val2) if method == 'substract': return substract(val1, val2)
import math x = math.add(2, 3) print(x)
print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'power' to exponentiate a number") print("Enter 'gcd' to find the greatest common denominator of two numbers") print("Enter 'hypot' to find the hypotenue of two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "add": result = math.add(num1 + num2) print (F"The result is {result}") elif user_input == "subtract": result = str(num1 - num2) print (F"The result is {result}") elif user_input == "multiply": result = str(num1 * num2) print (F"The result is {result}") elif user_input == "divide": result_whole = str(num1 // num2) result_int = str(num1 / num2) rem = str(num1 % num2) print(F"The result is {result_whole} with a remainder of {rem} OR {result_int}")
def test_math(self): print math.add(1,2)
def test_add1(self): self.assertEqual(add(-2, 3), 1)
def test_add0(self): self.assertEqual(add(1, 2), 3)
def test_add2(self): self.assertNotEqual(add('hello', 'world'), 'helloworld') self.assertFalse(add('hello', 'world'))
# 一般匯入 import math print( math.log(100, 10) ) # 計算 log(100) = 2 print( math.factorial(5) ) # 計算 5! = 120 # 一般匯入加上別名 import as import math as m print( m.add(1,3) ) print( m.subtract(1,3) ) # 匯入所有函數 from math import * print( log(100, 10) ) print( factorial(5) ) # 只匯入 log, factorial 函數 from math import log, factorial print( log(100, 10) ) print( factorial(5) ) # 一句匯入多個模組
class MovieDetails: def add(self, artistname, yearofrelease, ratings): self.artistName = artistname self.yearOfRelease = yearofrelease self.ratings = ratings def display(self): print("ArtistName is:", self.artistName) print("Year of Release is:", self.yearOfRelease) print("Rating is:", self.ratings) m = MovieDetails() m.add("Jason Statham", 2000, 9.2) m.display() #q5 class Animals: def animal_attribute(self): print("This is a base class function") class Tiger(Animals): pass t = Tiger()
def test_add(self): self.assertEqual(math.add(5, 7), 12) self.assertEqual(math.add(5), 9) self.assertEqual(math.add(), 5)
if __name__ == '__main__': print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print("Pycharm Awsome...") print('asdfajslfkjasldfj') print("Pycharm awsome...") print("%s" % "adan") alexMethod() # TODO: Insert control for unreadable character print(add(5, 7)) # TODO: refactor this part print("Pycharm Awsome...") name = "jamil" name2 = "" def hello(name): return name
def test_add(): assert_equal(add(2, 2), 4) assert_equal(add(2, 3), 5)
def test_add(num1, num2, result): assert math.add(num1, num2) == result
def test_add_floats(self): """ Test that the addition of two floats returns the correct result """ result = math.add(10.5, 2) self.assertEqual(result, 12.5)
def testAdd(self): self.result = math.add(self.a, self.b) # 결과 값이 일치 여부 확인 self.assertEqual(self.result, 31)
def test_add_integers(self): """ Test that the addition of two integers returns the correct total """ result = math.add(1, 2) self.assertEqual(result, 3)
import math x = 10 y = 20 print("Addition:" + math.add(x, y))