第1章 程序设计基本方法
来自CloudWiki
程序设计语言
Python语言概述
1)最小程序:
>>> print("hello world") hello world
Python开发环境配置
Python程序的运行方式:
2)交互式(将程序写在交互式环境中执行)
>>> a=100 >>> a=1+1 >>> print(a)
2
3)文件式(将程序写在文件中执行) 在IDLE菜单中选择File ->NEW File ,就可以新建python文件
文件保存之后,选择RUN -> RUN MODEL ,就可以运行python文件
#判断输入整数是否在[0,100]之间 num = eval(input("请输入一个整数:")) if num >100 or num <0 : #判断[0,100] print("输入整数小于0或大于100") else: print("输入整数在0和100之间")
程序的基本编写方法
输入、输出和处理
Python程序的特点
- 通用性
- 语法简洁
- 生态高产
from turtle import * color('red','red') begin_fill() for i in range(5): fd(200) rt(144) end_fill() done()
import turtle colors = ['red','orange','yellow','green','blue','indigo','purple'] for i in range(7): c=colors[i] turtle.color(c,c) turtle.begin_fill() turtle.rt(360/7) turtle.circle(50) turtle.end_fill() turtle.done()