1.阿拉伯数字转为大写
![result](https://i-blog.csdnimg.cn/blog_migrate/2a88aee0e6be27e1c8e6a72989b7b3b4.png)
chinese_dict = {
0: '零',1: '壹',2: '贰',3: '叁',4: '肆',5: '伍',6: '陆',7: '柒',8: '捌',9: '玖'
}
unit_list = ['', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿','拾', '佰', '仟', '兆']
def transform(number):
if number == 0:
return '零'
chinese_number = ''
number_str = str(number)
for i, digit in enumerate(number_str):
digit = int(digit)
if digit != 0:
chinese_number += chinese_dict[digit] + unit_list[len(number_str) - i - 1]
else:
if chinese_number[-1] != '零' and (i < len(number_str) - 1 and int(number_str[i+1]) != 0):
chinese_number += chinese_dict[digit]
return chinese_number
if __name__=="__main__":
ind = int(input("请输入一个数字:\t"))
print(transform(ind))
2.好友管理系统
![result2](https://i-blog.csdnimg.cn/blog_migrate/fdc3d98ca9327c9cd5181e88ff49f0ff.png)
friends=[]
def funFri(inIndex):
if inIndex==1:
name=input("请输入要添加的好友名称:\t")
zeng(name)
elif inIndex==2:
name = input("请输入要删除好友姓名:\t")
shan(name)
print("好友删除成功")
elif inIndex==3:
name = input("请输入要添加备注的好友姓名:\t")
beizhu=input("请输入要添加的备注:\t")
addbeizhu(name,beizhu)
elif inIndex==4:
cha()
else:
inIndex==5
def ifExist(name):
for i in range(len(friends)):
if friends[i].get("name") == name:
return i
return None
def zeng(name):
if ifExist(name!=None):
print("好友名称存在,好友添加失败")
else:
friends.append({"name":name})
print("好友添加成功")
def shan(name):
ind=ifExist(name)
if ind!=None:
friends.pop(ind)
else:
print("没有该好友,无需删除")
def addbeizhu(name,beizhu):
ind=ifExist(name)
if(ind!=None):
friends[ind]['beizhu']=beizhu
else:
print("没有改好友,添加备注失败")
def cha():
for i in range(len(friends)):
beizhu=friends[i].get("beizhu")
if beizhu:
print(friends[i].get("name") + '\t' + beizhu)
else:
print(friends[i].get("name"))
def main():
print("欢迎使用好友系统")
print("1. 添加好友\t2. 删除好友\t3. 备注好友\t4. 展示好友\t5. 退出")
inIndex=int(input("请输入您的选项:\t"))
while(inIndex!=5):
funFri(inIndex)
inIndex = int(input("请输入您的选项:\t"))
if __name__=="__main__":
main()