print(d.get(n[i]),end=" ")#a b c
print(d.get(n[i]),end="dddd")#addddbddddcdddd
print(d.get(n[i]),end="")#abc
不是说怎么不换行吗 ,就加一个end=“”就行,“中间加什么就会补齐什么”
list[i].sort()#[1,2,3,4,5]
list[i].sort(reverse=True)#[5,4,3,2,1]
list.sort()
"""[['1'], ['10', '13', '15', '16'], ['10', '14'], ['10', '21'], ['11', '21'], ['12', '13', '21', '23'], ['12', '14', '21', '23'], ['15', '16', '17', '19', '22', '4'], ['17', '18', '19', '22', '4'], ['2'], ['20', '22'], ['20', '5'], ['3'], ['6'], ['7', '8', '9']]
"""
排序的用法,升序,降序,二维不规则数组排序,可以看出,排序的规则是[0][0][0]从小到大
def tem(*a):
p=0
a[p]#控制台显示[1,2,10]而不是1
def tem1(a)
p=0
a[p]#1
对于指针还是要慎用,毕竟a就万物皆可传
list=[[1],[2],[3],[20,5],[6],
[7,8,9],[21,10],[21,11],[21,23,12,13],[21,23,12,14],
[10,15,16,13],[10,14],[22,15,16,19,4],[22,18,19,4],[22,20],
[22,15,16,17,19],[22,18,17,19]]
name=[21,21,22,22,23,23,24,24,"金钱豹","虎","长颈鹿","斑马","鸵鸟","企鹅","信天翁","鸵鸟","企鹅"]
d={
1 :"有毛发",
2 :"产奶",
3 :"有羽毛",
4 :"不会飞",
5 :"会下蛋",
6 :"吃肉",
7 :"有犬齿",
8 :"有爪",
9 :"眼盯前方",
10:"有蹄",
11:"反刍",
12:"黄褐色",
13:"有斑点",
14:"有黑色条纹",
15:"长脖",
16:"长腿",
17:"不会飞",
18:"会游泳",
19:"黑白二色",
20:"善飞",
21:"哺乳类",
22:"鸟类",
23:"食肉类",
24:"蹄类",
}
def find_next(a):
tem=0
str1=""
listTem=[]
while tem< len(list):
if len(list[tem]) <= len(a):
p=0
q=0
count=0
while p< len(a) and q< len(list[tem]):
if a[p]==list[tem][q]:
p+=1
q+=1
count+=1
elif a[p]<list[tem][q]:
p+=1
else:q+=1
if count==len(list[tem]):
tttt=0
ttttt=0
for tt in range(len(a)):
if str(a[tt])==str(name[tem]):
tttt=1
break
for tt in range(len(listTem)):
if str(listTem[tt])==str(name[tem]):
tttt=1
break
if tttt==0:
listTem.append(name[tem])
for g in range(len(list[tem])):
if g< len(list[tem])-1:
str1=str1+d.get(list[tem][g])+","
else:
str1=str1+d.get(list[tem][g])
if tem<8:
str1=str1+"->"+d.get(name[tem])
else:str1=str1+"->"+name[tem]
print(str1)
str1=""
tem+=1
return listTem
print("输入对应条件前面的数字:")
print('''
*****************************************************
*1:有毛发 2:产奶 3:有羽毛 4:不会飞 5:会下蛋 *
*6:吃肉 7:有犬齿 8:有爪 9:眼盯前方 10:有蹄 *
*11:反刍 12:黄褐色 13:有斑点 14:有黑色条纹 15:长脖 *
*16:长腿 17:不会飞 18:会游泳 19:黑白二色 20:善飞 *
*21:哺乳类 22:鸟类 23:食肉类 24:蹄类 *
******************************************************
****************当输入数字0时!程序结束*******************
''')
j=0
while j< len(list):
list[j].sort()
j+=1
i=int(input("请输入:"))
a=1
n=[]
while i!=0:
n.append(i)
i=int(input("请输入:"))
a=a+1
n.sort()
length=0
print("前提条件为:")
s=""
""""""
i=0
while i <len(n):
print(d.get(n[i]),end=" ")
i+=1
tem=[]
print("\n推理过程如下:")
while length!= len(n):
length=len(n)
tem=find_next(n)
n=n+tem
tem=[]
这是我写的产生式系统
结果如下:
输入对应条件前面的数字:
*****************************************************
*1:有毛发 2:产奶 3:有羽毛 4:不会飞 5:会下蛋 *
*6:吃肉 7:有犬齿 8:有爪 9:眼盯前方 10:有蹄 *
*11:反刍 12:黄褐色 13:有斑点 14:有黑色条纹 15:长脖 *
*16:长腿 17:不会飞 18:会游泳 19:黑白二色 20:善飞 *
*21:哺乳类 22:鸟类 23:食肉类 24:蹄类 *
******************************************************
****************当输入数字0时!程序结束*******************
请输入:13
请输入:15
请输入:16
请输入:2
请输入:10
请输入:21
请输入:24
请输入:0
前提条件为:
产奶 有蹄 有斑点 长脖 长腿 哺乳类 蹄类
推理过程如下:
有蹄,有斑点,长脖,长腿->长颈鹿