美文网首页
4、第一个Python程序

4、第一个Python程序

作者: 看远方的星 | 来源:发表于2021-04-16 15:56 被阅读0次

运行程序的两种方式:

  • 交互式运行Python语句
  • 保存源文件运行程序

一、交互式运行Python语句

超级计算器:
打开IDLE在Python shell中输入1+1,按Enter键立即看到运行结果,当计算器用可以计算2100!超级大的数都没问题

打开新世界的大门:
第一行程序代码编写
在Python shell中输入

print(“Hello World!”)

二、保存源文件运行程序

IDLE里编程的步骤
①“File->New File"打开文件编辑窗口
②输入代码
③"File->Save"保存文件
④"Run->Run Module"运行,查看结果


给自己点一份饮料:
源代码:

import random 
menu=["coffee","tea","cola","milk","water"]
print("Menu:", menu)
name=input("Your name please:")
drink=random. choice(menu)
print("Hello", name,"! Enjoy your", drink)

效果:


相关文章

网友评论

      本文标题:4、第一个Python程序

      本文链接:https://www.haomeiwen.com/subject/kbyelltx.html