01/10/2018, 12:24
Khắc phục lỗi name '' is not defined trên python
# -*- coding: utf-8 -*-
import math
global a,b,c,d
def f(x): return a*math.pow(x,3)+b*math.pow(x,2)+c*x+d
def zzz(gha = float(input("> Gioi han A: ")), ghb = float(input("> Gioi han B: ")), saiso=(ghb-gha)/math.pow(2,20)):
gh=(gha+ghb)/2
if(f(gh)==0 or math.fabs(gha-ghb) < saiso ): return gh
if f(gha)*f(gh)<0: return zzz(gha,gh)
else: return zzz(gh,ghb)
print """
***********************************************************
**CHƯƠNG TRÌNH GIẢI HÀM SỐ BẰNG PHƯƠNG PHÁP TÍNH GẦN ĐÚNG**
***********************************************************
"""
print "Nhập tham số:"
a = float(input("> A:"))
b = float(input("> B:"))
c = float(input("> C:"))
d = float(input("> D:"))
print "Nhap gioi han:"
print zzz()
[/quote]
Đây là đoạn code em viết dùng để giải phương trình gần đúng, khi em biên dịch thì xuất hiện lỗi name ‘ghb’ is not defined, vậy nên khắc phục như thế nào ạ, em xin cảm ơn
Bài liên quan
Lỗi ở dòng nào? Bạn up code và tên lỗi mà không up vị trí lỗi thì không ai giúp được bạn đâu.
raceback (most recent call last):
File “helloworld.py”, line 8, in
def zzz(gha = float(input("> Gioi han A: “)), ghb = float(input(”> Gioi han B: ")), saiso=(ghb-gha)/math.pow(2,20)):
NameError: name ‘ghb’ is not defined
dạ lỗi đây anh
Cần gì phải khổ sở khai báo thế này. Cứ viết tách ra.