赞
踩
- >>> from xpinyin import Pinyin
- >>> p = Pinyin()
- >>>
- >>> # 获取中文字符串的对应拼音
- >>> p.get_pinyin("小甲鱼")
- 'xiao-jia-yu'
- >>>
- >>> # 显示声调
- >>> p.get_pinyin("小甲鱼", tone_marks="marks")
- 'xiǎo-jiǎ-yú'
- >>>
- >>> # 将声调用显示为数字1、2、3、4
- >>> p.get_pinyin("小甲鱼", tone_marks="numbers")
- 'xiao3-jia3-yu2'
- >>>
- >>> # 移除分隔符
- >>> p.get_pinyin("小甲鱼", "")
- 'xiaojiayu'
- >>>
- >>> # 指定分隔符
- >>> p.get_pinyin("小甲鱼", "^")
- 'xiao^jia^yu'
- >>>
- >>> # 获取拼音第一个字母
- >>> p.get_initial("小")
- 'X'
- >>> p.get_initials("小甲鱼")
- 'X-J-Y'
- >>> p.get_initials("小甲鱼", "")
- 'XJY'
- >>> p.get_initials("小甲鱼", "^")
- 'X^J^Y'
- >>>
- >>> # 获取声母(包含翘舌音)
- >>> p.get_initials("上海自来水来自海上", with_retroflex=True)
- 'SH-H-Z-L-SH-L-Z-H-SH'
- >>>
- >>> # 多音字组合
- >>> p.get_pinyins("模型", tone_marks="marks")
- ['mó-xíng', 'mú-xíng']
- >>> p.get_pinyins("模样", tone_marks="marks")
- ['mó-yáng', 'mó-yàng', 'mó-xiàng', 'mú-yáng', 'mú-yàng', 'mú-xiàng']
- from xpinyin import Pinyin
- # 创建一个输入字符串的函数
- def get_input():
- s = input("请输入一段话:")
- if len(s) == 1:
- s = input("字数太少,请重新输入:")
- return s
- # 创建一个获取拼音的函数
- def get_pinyin(s):
- p = Pinyin()
- s = p.get_pinyin(s)
- return s
- # 创建一个判断回文数的函数
- def check_py(s):
- l = s.split("-")
- print(l)
- for i in range(len(l) // 2):
- if l[i] != l[-i-1]:
- return False
- else:
- return True
- # 调用函数 穿参
- s = get_input()
- w = get_pinyin(s)
- if check_py(w):
- print(f"{s}是回文数。")
- else:
- print(f"{s}不是回文数。")
- def print_s (s):
- print("栈:")
- for each in s[::-1]:
- print(each)
- # push
- def push_s(s,v):
- s.append(v)
- # pop
- def pop_s():
- if len(s) == 0 :
- return 0
- else:
- return s.pop()
-
- s = []
- op = ''
- while op != "exit":
- op = input("请输入指令:")
- if op =="push":
- v = input("请输入需要放入栈中的值:")
- push_s(s,v)
- print_s(s)
- if op =="pop":
- v = pop_s()
- if len(s) == 0 :
- print("栈已空~")
- else:
- print(v)
- print_s(s)
- if op == "top":
- if len(s) == 0:
- print("栈已空")
- else:
- print(s[-1])
- else :
- print("程序已退出~")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。