Python 只是一个需要帮助的新人
所以我刚写完这个非常基本的脚本,它只需要输入名称和值,并将它们放入字典中,然后显示出来,没什么,但我遇到了一些问题,我认为问题来自add函数,但我不确定。就像我说的我是新来的。。。所以请运行代码,给我所有的批评。。我需要它。谢谢 代码:Python 只是一个需要帮助的新人,python,python-3.4,Python,Python 3.4,所以我刚写完这个非常基本的脚本,它只需要输入名称和值,并将它们放入字典中,然后显示出来,没什么,但我遇到了一些问题,我认为问题来自add函数,但我不确定。就像我说的我是新来的。。。所以请运行代码,给我所有的批评。。我需要它。谢谢 代码: 谢谢我重新编写了您的代码并做了一些更改。首先,我使用raw_输入而不是input,因为input引用变量或类似的东西,但不返回字符串。原始输入返回一个字符串。。。因此,我更正了一些函数以避免错误,例如,当我被问及是否要输入其他名称时,我输入了“否”,他要求我输入
谢谢我重新编写了您的代码并做了一些更改。首先,我使用raw_输入而不是input,因为input引用变量或类似的东西,但不返回字符串。原始输入返回一个字符串。。。因此,我更正了一些函数以避免错误,例如,当我被问及是否要输入其他名称时,我输入了“否”,他要求我输入其他名称和分数 好的,这是你修改过的代码:
from time import sleep #To set delay time in the code or portions of the code
def dict_create():
# Creates the _info dictionary by entering the _name keys & _score values
_info={}
_info[_name]=_score
print ('\n',_subject, 'class students names and scores',_info.items())
def reject():
# Creates gateway for more() & dict() exec.
confirm=raw_input(" \nYOU WILL NO LONGER BE ABLE TO ADD MORE NAMES \n\n ['yes' to quit or 'no' to continue] :")
if confirm=='no':
print ('\nBelow are the names and scores of all students offering ' + _subject )
print ('\nProcessing...')
sleep(1)
dict_create()
_more()
elif confirm=='yes':
print ('\n',_subject, 'class students names and scores',_info.items())
quit
else:
print('\nInvalid input')
reject()
def add():
# Creates gateway for _info.dict.update...[This seems to be the problem]
_add=raw_input('\n [+] Add more names [Yes or No] :')
name=str(raw_input ('\n [+] Please input students name :'))
score=int(raw_input ('\n [+] Please input students score :'))
sleep(1)
# Update process for student.dict
repeat={}
repeat[name]=score
_info.update(repeat)
_more()
if _add=='yes':
_more()
elif _add=='no':
reject()
else:
print('\nSorry, invalid input, NOTE INPUT IS CASE SENSITIVE')
add()
def _more():
# Creates gateway for 'more' validation
more=raw_input('\n [+] Do you want add more names [yes or no] :')
if more=='no':
reject()
elif more=='yes':
add()
else:
print('\nInvalid input.Please note your input is case sensitive.')
_more()
# __init__
print('\nTHIS SCRIPTS GROUPS ALL NAMES & SCORES OF STUDENTS IN A CLASS')
_subject=raw_input('\n [+] Input subject :')
_name=raw_input('\n [+] Input students name :')
_score=float(raw_input('\n [+] input students score :'))
print ('\nProcessing...')
sleep(1)
_info={}
_info[_name]=_score
dict_create()
_more()
编辑你的标题。用它做一些有意义的事情!另外:如果您有错误,请描述这些错误,包括您希望看到的内容。
from time import sleep #To set delay time in the code or portions of the code
def dict_create():
# Creates the _info dictionary by entering the _name keys & _score values
_info={}
_info[_name]=_score
print ('\n',_subject, 'class students names and scores',_info.items())
def reject():
# Creates gateway for more() & dict() exec.
confirm=raw_input(" \nYOU WILL NO LONGER BE ABLE TO ADD MORE NAMES \n\n ['yes' to quit or 'no' to continue] :")
if confirm=='no':
print ('\nBelow are the names and scores of all students offering ' + _subject )
print ('\nProcessing...')
sleep(1)
dict_create()
_more()
elif confirm=='yes':
print ('\n',_subject, 'class students names and scores',_info.items())
quit
else:
print('\nInvalid input')
reject()
def add():
# Creates gateway for _info.dict.update...[This seems to be the problem]
_add=raw_input('\n [+] Add more names [Yes or No] :')
name=str(raw_input ('\n [+] Please input students name :'))
score=int(raw_input ('\n [+] Please input students score :'))
sleep(1)
# Update process for student.dict
repeat={}
repeat[name]=score
_info.update(repeat)
_more()
if _add=='yes':
_more()
elif _add=='no':
reject()
else:
print('\nSorry, invalid input, NOTE INPUT IS CASE SENSITIVE')
add()
def _more():
# Creates gateway for 'more' validation
more=raw_input('\n [+] Do you want add more names [yes or no] :')
if more=='no':
reject()
elif more=='yes':
add()
else:
print('\nInvalid input.Please note your input is case sensitive.')
_more()
# __init__
print('\nTHIS SCRIPTS GROUPS ALL NAMES & SCORES OF STUDENTS IN A CLASS')
_subject=raw_input('\n [+] Input subject :')
_name=raw_input('\n [+] Input students name :')
_score=float(raw_input('\n [+] input students score :'))
print ('\nProcessing...')
sleep(1)
_info={}
_info[_name]=_score
dict_create()
_more()