1、暗语转换
dict_data = { '0': 'O', '1': 'I', '2': 'Z', '3': 'E', '4': 'Y', '5': 'S', '6': 'G', '7': 'L', '8': 'B', '9': 'P',}def translate_code_word(word): ''' 转化字符串 ''' result = [] global dict_data for i in word: result.append(dict_data[i]) return resultif __name__ == '__main__': while True: word = input('请输入暗语:') if word.isdigit(): result_list = translate_code_word(word) result_string = "".join(result_list) print('转换后是:%s ' % result_string) if result_string == 'BYE': break word = input('请输入暗语:') else: print('请输入数字')
2、 人民币和卢布币值兑换
ipt = input("a.人民币 b.卢布\n请输入要转换的币种序号:")def exchange(RMB): return RMB * 9.912if ipt == "a": if __name__ == "__main__": RMB = float(input('请输入要转化的人民币,退出输入0:')) while RMB: print('{}元人民币={}俄罗斯卢布'.format(RMB,exchange(RMB))) RMB = float(input('请输入要转化的人民币,退出输入0:'))def unexchange(RUB): return RUB / 9.912if ipt == "b": if __name__ == "__main__": RUB = float(input('请输入要转化的俄罗斯卢布,退出输入0:')) while RUB: print('{}俄罗斯卢布={}元人民币'.format(RUB,unexchange(RUB))) RUB = float(input('请输入要转化的俄罗斯卢布,退出输入0:'))
sdate = (20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 21)sstar = ("摩羯座","水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", \ "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座")while True: indate = input("请输入您的生日(格式:2018:10:12):") instr= indate.split(":") year = int(instr[0]) month = int(instr[1]) date = int(instr[2]) if date >= sdate[month-1]: print("您的星座是:" + sstar[month]) else: print("您的星座是:" + sstar[month-1])
风车动漫