gpt4 book ai didi

python - 尝试输入字符串时出现名称错误

转载 作者:行者123 更新时间:2023-11-28 19:49:21 26 4
gpt4 key购买 nike

<分区>

import pickle
import os
import time

class Person():
def __init__(self, number, address):
self.number = number
self.address = address


def save():
with open('mydict.pickle', 'wb') as f:
pickle.dump(mydict, f)

mydict = {}
mydict['Avi'] = ['347-000-0000', 'Oceanview']
mydict['Alan'] = ['347-000-0000', 'Brighton']
mydict['Frank'] = ['718-000-0000', 'Brighton']

print('add a name to the database.')
name = input('Name:')
number = input('Digits:')
address = input('Address:')
mydict[name] = [number, address]

-------------------------------------------------------

错误:如果我尝试向数据库中添加名称,则会出现名称错误。 NameError:名称“alan”未定义。奇怪的是字符串不起作用,但数字可以。抱歉,如果我的问题不清楚。

Traceback (most recent call last):
File "C:/Python33/ss", line 21, in <module>
name = input('Name:')
File "<string>", line 1, in <module>
NameError: name 'alan' is not defined
>>>

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com