How to use complex_numbers method in hypothesis

Best Python code snippet using hypothesis

asign2.py

Source:asign2.py Github

copy

Full Screen

1def print_list(complex_numbers):2 for x in range (0, len(complex_numbers)):3 x = int(x)4 if complex_numbers[x]["imag"] > 0:5 print(str(complex_numbers[x]["real"]) + " + "+ str(complex_numbers[x]["imag"]) + "i")6 elif complex_numbers[x]["imag"] == 0:7 print(str(complex_numbers[x]["real"]))8 else:9 print(str(complex_numbers[x]["real"]) + str(complex_numbers[x]["imag"]) + "i")10 if len(complex_numbers) == 0:11 print("There does not exist a sequence with the given property")12def print_menu():13 print("Please select an operation:")14 print("1. Print the entire list of numbers")15 print("2. Print the longest sequence of numbers having the same modulus")16 print("3. Print the longest sequence that consists of real numbers")17 18def calculate_modulus(x, y):19 '''20 Function that calculates the modulus of a given complex number( x + yi)21 Input: x, y - integers22 Precondition: x - the real part23 y - the imaginary part24 Output : r - the modulus of the number25 Postcondition : r - float26 '''27 import math28 x = int(x)29 y = int(y)30 r = math.sqrt(x * x + y * y)31 r = float(r)32 return r33def determine_numbers_with_same_modulus(complex_numbers):34 '''35 Function that determines the longest sequence with the given property36 Input : complex_numbers - the complex numbers retained as dictionaries37 Precondition : -38 Output : seq2 - the longest sequence with the given property39 Postcondition : -40 '''41 seq2 =[]42 ma = 043 poz = 044 m = calculate_modulus(complex_numbers[0]["real"], complex_numbers[0]["imag"])45 for x in range (0, len(complex_numbers)):46 cnt = 147 y = x48 n = calculate_modulus(complex_numbers[y]["real"], complex_numbers[y]["imag"])49 while y < len(complex_numbers) and m == n:50 n = calculate_modulus(complex_numbers[y]["real"], complex_numbers[y]["imag"])51 cnt += 152 y += 153 if ma < cnt:54 ma = cnt55 poz = x56 m = n57 x = y58 for x in range (poz, poz + ma - 1):59 seq2.append({ "real" : complex_numbers[x]["real"], "imag" : complex_numbers[x]["imag"]})60 return seq261def determine_real_numbers(complex_numbers):62 '''63 Function for determining the longest sequence of real numbers64 Input : complex_numbers - list of complex numbers retained as dictionares65 Precondition : -66 Output : seq2 - the longest sequence with the given property67 Postcondition : -68 '''69 cnt = 070 ma = 071 poz = 072 seq2 = []73 for x in range (0, len(complex_numbers)):74 cnt = 075 y = x76 while y < len(complex_numbers) and not complex_numbers[y]["imag"]:77 cnt += 178 y += 179 if ma < cnt:80 ma = cnt81 poz = x82 if not cnt:83 print("There are no real numbers")84 else:85 for x in range (poz, poz + ma):86 seq2.append({ "real" : complex_numbers[x]["real"], "imag" : complex_numbers[x]["imag"]})87 return seq288def read_numbers():89 complex_numbers = [{ "real" : 1, "imag" : 2}, { "real" : 5, "imag" : 12}, { "real" : -6, "imag" : 8}, { "real" : 4, "imag" : -3}, { "real" : -7, "imag" : 0}, { "real" : 1, "imag" : 9}, { "real" : 6, "imag" : -8}, { "real" : 3, "imag" : 4}, { "real" : 6, "imag" : 8}, { "real" : 20, "imag" : 21}]90 print("Please write the complex numbers:")91 while True:92 try:93 x = input("The real part of the complex number:")94 #if x == "exit":95 #break96 y = input("The imaginary part of the complex number:")97 if y == "exit" or x == "exit":98 break99 x = int(x)100 y = int(y)101 complex_numbers.append({ "real" : x, "imag" : y})102 except ValueError as a:103 print("invalid input!")104 105 return complex_numbers106def ui_sequence1(complex_numbers):107 print_list(complex_numbers)108def ui_sequence2(complex_numbers):109 complex_numbers = determine_numbers_with_same_modulus(complex_numbers)110 print_list(complex_numbers)111def ui_sequence3(complex_numbers):112 complex_numbers = determine_real_numbers(complex_numbers)113 print_list(complex_numbers)114 115def run():116 complex_numbers = read_numbers()117 print_menu()118 while True:119 x = input("Please give a valid command:")120 if x == "exit":121 return122 if x == "1":123 ui_sequence1(complex_numbers)124 if x == "2":125 ui_sequence2(complex_numbers)126 if x == "3":127 ui_sequence3(complex_numbers)128 129def test_modulus():130 assert calculate_modulus(3, 4) == 5131 assert calculate_modulus(0, 0) == 0132 assert calculate_modulus(6, 8) == 10133 assert calculate_modulus(12, 5) == 13134test_modulus()...

Full Screen

Full Screen

Complex numbers.py

Source:Complex numbers.py Github

copy

Full Screen

1def show_menu():2 print("welcome to Complex numbers calculator :)\n")3 print("1-jam \n")4 print("2-tafrigh \n")5 print("3-zarb \n")6 print("4-taghsim \n")7 print("5-exit \n")8########################################## GET NUMBER ##################################################9def Get_complex_Number():10 real = int(input('lotfan ghesmat real adad ra vared konid :'))11 image = int(input('lotfan ghesmat imagee adad ra vared konid :'))12 return real , image13############################################ CLASS COMPLEX ##########################################14class Complex_numbers :15 def __init__ (self, re=0, im=0):16 self.real = re17 self.img = im18 def __add__(self, other):19 result=Complex_numbers()20 result.real = self.real + other.real21 result.img = self.img + other.img22 return result23 def __sub__(self, other):24 result=Complex_numbers()25 result.real = self.real - other.real26 result.img = self.img - other.img27 return result28 def __mul__(self, other):29 result=Complex_numbers()30 result.real = self.real * other.real - self.img * other.img31 result.img = self.img * other.real + self.real * other.real32 return result33 def __truediv__(self, other):34 divisor = (other.real**2 + other.img**2)35 return Complex_numbers((self.real * other.real - self.img * other.img)/divisor , (self.img * other.real + self.real * other.img)/divisor)36 def show(self):37 print(str( self.real , self.img , "j" ,"\n" ))38 39 def __str__(self):40 if self.img >=0 :41 return str(self.real) + " + " + str(self.img) + "j"42 else :43 return str(self.real) + " - " + str(abs(self.img)) + "j"44####################################### MAIN #############################################################45while True :46 show_menu()47 gozine = ''48 try:49 gozine = int(input('lotfan gozine mored nazar ra vared konid : '))50 except:51 print('ebarat vared shode motabar nist ، lotfan shomare gozine ra vared konid : ')52 53 if gozine == 1:54 print("\n Complex_numbers 1 \n")55 r1 , i1 = Get_complex_Number()56 num1 = Complex_numbers(r1 , i1)57 print("\n Complex_numbers 2 \n")58 r2 , i2 = Get_complex_Number()59 num2 = Complex_numbers(r2 , i2)60 print("hasel : " , num1+num2 , "\n")61 elif gozine == 2:62 print("\n Complex_numbers 1 \n")63 r1 , i1 = Get_complex_Number()64 num1 = Complex_numbers(r1 , i1)65 print("\n Complex_numbers 2 \n")66 r1 , i1 = Get_complex_Number()67 num2 = Complex_numbers(r1 , i1)68 print("hasel : " , num1-num2 , "\n")69 70 elif gozine == 3:71 print("\n Complex_numbers 1 \n")72 r1 , i1 = Get_complex_Number()73 num1 = Complex_numbers(r1 , i1)74 print("\n Complex_numbers 2 \n")75 r1 , i1 = Get_complex_Number()76 num2 = Complex_numbers(r1 , i1)77 print("hasel : " , num1*num2 , "\n")78 elif gozine == 4:79 print("\n Complex_numbers 1 \n")80 r1 , i1 = Get_complex_Number()81 num1 = Complex_numbers(r1 , i1)82 print("\n Complex_numbers 2 \n")83 r1 , i1 = Get_complex_Number()84 num2 = Complex_numbers(r1 , i1)85 print("hasel : " , num1/num2 , "\n")86 elif gozine == 5:87 break 88 else : 89 print("lotfan adadi bein 1 - 5 vared konid \n ")90 input("\nPress ENTER to continue...\n") ...

Full Screen

Full Screen

sortcomplex.py

Source:sortcomplex.py Github

copy

Full Screen

1import numpy as np2np.random.seed(42)3complex_numbers = np.random.random(5) + 1j * np.random.random(5)4print "Complex numbers\n", complex_numbers...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful