完成完整的温度转换程序
while True: a = input("摄氏转华氏请按1\n华氏转摄氏请按2\n") if a == ‘1‘: c = float(input(‘请输入摄氏温度:‘)) f =(c * 1.8) + 32 print(‘{:.2f}摄氏温度转为华氏温度为{:.2f}‘.format(c,f)) elif a == ‘2‘: f = float(input(‘请输入华氏温度:‘)) c = 5 / 9 * (f - 32) print(‘{:.2f}华氏温度转为摄氏温度为{:.2f}‘.format(f,c)) else: break
猜数字游戏(猜价格,猜年龄等)
num = 6 gus = -1 while (gus != num): gus =int(input(‘请输入你要猜测的数字:‘)) if (gus < num): print (‘你猜的数字太小了!‘) elif (gus > num): print(‘你猜的数字太大了!‘) else: print(‘你猜对了!‘) break
原文:https://www.cnblogs.com/Tlzlykc/p/9639629.html