|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 一次芳 于 2018-5-26 15:34 编辑
我的源程序:
names=['mother','teacher','student','father']
identity=input("please entry your identity:")
if identity not in names:
print("unidentifiable, systen not record your identity")
else:
for name in names:
if identity==name:
print("you are a "+identity.title()+",today you should clean honse.")
elif identity==name:
print("you are a "+identity.title()+",today you should standy.")
elif identity==name:
print("you are a "+identity.title()+",today you should teach your student.")
else:
print("you are a "+identity.title()+",today you should work.")
我的运行结果:
please entry your identity:student
you are a Student,today you should work.
you are a Student,today you should work.
you are a Student,today you should clean honse.
you are a Student,today you should work.
问题:不是应该输出 you are a Student,today you should standy
万能的鱼友帮个忙
本帖最后由 thexiosi 于 2018-5-26 14:55 编辑
hi 原因如下
- names=['mother','teacher','student','father']
- identity=input("please entry your identity:")
- if identity not in names:
- print("unidentifiable, systen not record your identity")
- else:
- #for name in names:# here 此处用for循环,引发逻辑混乱。需要进行修正
- print(identity)
- if identity==names[0]:
- print("you are a "+identity.title()+",today you should clean honse.")
- elif identity==names[2]:
- print("you are a "+identity.title()+",today you should standy.")
- elif identity==names[1]:
- print("you are a "+identity.title()+",today you should teach your student.")
- else:
- print("you are a "+identity.title()+",today you should work.")
复制代码
please entry your identity:student
student
you are a Student,today you should standy.
|
|