weight = input() while weight != 'Q' and weight != 'q': #输入Q 跟q强制退出 try: float(weight) #浮点数float except ValueError: print("数值有误") weight = input() continue weight_list_earth = [float(weight) + w*0.5 for w in range(10) ] weight_list_moon = [w * 0.165 for w in weight_list_earth ] print("earth:",["%.2f"% w for w in weight_list_earth ]) # 打印中 “%.2f” 小数点后面余两位 print("moon:",["%.2f"% w for w in weight_list_moon ]) weight = input()