1、打开桌面的pycharm程序;
2、依次点击file > New Project新建一个代码目录;
3、然后新建一个名为“temperature”的程序并点击保存;
4、如图示输入如下代码:"""摄氏度和华氏度以及开氏度相互转换"""fl锾攒揉敫ag = int ( input("你想转换哪2种温度?【1.摄氏度转华氏度;2.华氏度转摄氏度;3.摄氏度转开氏度;请输入数字选择:flag= 】") )if flag == 1: centigrade = float( input("请输入摄氏温度 centigrade = ") ) fahrenheit_degree = centigrade * 1.8 + 32 print( "摄氏%0.2f度等于华氏%0.2f度"%(centigrade,fahrenheit_degree) )elif flag == 2: fahrenheit_degree = float( input("请输入华氏温度 fahrenheit_degree = ") ) centigrade = ( fahrenheit_degree - 32 ) / 1.8 print( "华氏%0.2f度等于摄氏%0.2f度"%(fahrenheit_degree,centigrade) )else: centigrade = float( input("请输入摄氏温度 centigrade = ") ) kelvin_degree = centigrade + 273.15 print( "摄氏%0.2f度等于开氏%0.2f度"%(centigrade,kelvin_degree) )
5、将鼠标移动至该代码的标签页并右键找到如图示选项:
6、点击运行程序 Run “temperature”,可以看到弹出交互终端等待用户输入;
7、输入内容按下回车,可以看到成功转换温度。