回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对编码有点陌生</p>
<p>这是我的代码和我的错误</p>
<pre><code>supplier_105 = {
"city": "Port Bradley",
"contact_firstname": "Brittany",
"contact_lastname": "Costa",
"contact_title": "Mrs",
"country": "Australia",
"email": "brittany8706.costa@gmail.com",
"notes": "",
"phone": "(08) 6939 8022",
"postcode": "3880",
"state": "Costa",
"street_address": "6/81 Heather Rosebowl",
"supplier_id": 105,
"supplier_name": "Rodriguez, Carter and Johnson"
}
# Write your code here
# 1. Define the class here
class Supplier:
def __init__(self, city, contact_firstname,contact_lastname,contact_title,country,email,notes,phone,postcode,state,street_address,supplier_id,supplier_name):
print("Initialiser called")
self.city = city
self.contact_firstname = contact_firstname
self.contact_lastname = contact_lastname
self.contact_title = contact_title
self.country = country
self.email = email
self.notes= notes
self.phone = phone
self.postcode = postcode
self.state = state
self.street_address = street_address
self.supplier_id = supplier_id
self.supplier_name = supplier_name
def get_state(self):
return "The state is {} and the postcode is {}".format(self.state, self.postcode)
print(Supplier_105.supplier_name)
# 2. Instantiate the class
Supplier_105 = Supplier("Port Bradley","Brittany","Costa","Mrs","Australia","brittany8706.costa@gmail.com","","(08) 6939 8022","3880","Costa","6/81 Heather Rosebowl","105","Rodriguez, Carter and Johnson")
# 3. Call its methods here
print(Supplier_105.get_state())
</code></pre>
<p><strong>错误</strong></p>
<pre><code>NameError Traceback (most recent call last)
<ipython-input-3-70798f9ef411> in <module>
39 return "{} is {} years old".format(self.state, self.postcode)
40
---> 41 print(Supplier_105.supplier_name)
42
43 # 2. Instantiate the class
NameError: name 'Supplier_105' is not defined
</code></pre>
<p>我正在尝试使用方法/函数将州和邮政编码格式化为“州和邮政编码”,但它不起作用。我还试图将实例变量中的邮政编码设置为传递的参数值</p>
<p>在此方面的任何帮助都将不胜感激<;三,</p>