-
2017/12/16, 18:50 #1
سورس برنامه حل معادلات درجه دو به زبان پایتون
با سلام
در خواست سورس برنامه ای به زبان پایتون رو داشتم که بتونه معادلات درجه دو رو حل کنه. لطفا سورس کد خوانا روان و ساده باشه چرا که بنده تازه کار هستم.
با تشکر -
2017/12/16, 19:51 #2
با سلام
نمونه کد برای حل معادلات درجه دوم
کد:from cmath import* gozine=int(input("Baraye Dadan Rishe va Gereftane Moadele , Adad 1 va Baraye hal Moadele Adad 2 ra Vared konid .")) if gozine == 1: class moadele1 () : rishe1=0 rishe2=0 def risheha (s) : print("moadele shoma Amade Ast :" + "x^2"+"-"+S+"x"+ "+"+P) moadele1rishe = moadele1() moadele1rishe.rishe1 = int(input(" Rishe 1 ra vared konid ")) moadele1rishe.rishe2 = int(input("rishe 2 ra vared konid " )) P = moadele1rishe.rishe1 * moadele1rishe.rishe2 S = moadele1rishe.rishe1 + moadele1rishe.rishe2 P = str(P) S = str(S) print(risheha(moadele1rishe)) elif gozine ==2 : class moadele2 (): zarib_a = 0 zarib_b = 0 zarib_c = 0 def moadele2_hi (sss) : print("rishe haye shoma in ast :" + rishe_1 + " va " + rishe_2) moadele_koll=moadele2() moadele_koll.zarib_a=int(input("Lotfan Zarib A ra Vared Konid ")) moadele_koll.zarib_b=int(input("Lotfan Zarib B ra Vared Konid")) moadele_koll.zarib_c=int(input("Lotfan Zarib C ra varid Konid")) delta = ((moadele_koll.zarib_b) **2)-4*(moadele_koll.zarib_a * moadele_koll.zarib_c) if delta < 0 : print("delta nemitavand Bashad ! ") rishe_1 = (-moadele_koll.zarib_b - sqrt(delta))/(2 * moadele_koll.zarib_a) rishe_2 = (-moadele_koll.zarib_b + sqrt(delta))/(2 * moadele_koll.zarib_a) rishe_1=str(rishe_1) rishe_2=str(rishe_2) print(moadele2_hi(moadele_koll)) else : print("Faqat adad 1 ya 2 ra vared konid "