今天第一学期开学第一天,本以为第一周会讲些理论之类的,结果理论的一带而过,老师让我们一定要预习才行,进度很紧张,讲的也很快。那下面就跟大家分享一下我的上课内容!
先在官网下载,之后就可以用IDLE编程了
直接上代码:
3+6
"python is really cool"
name="teacher"
"hi there"+name 用加号
print("hi there",name)注意用逗号
图片是输出效果,可以自己练习
![](https://img.haomeiwen.com/i16502768/67c8e5047923a8ba.png)
print("A",end='') #end means 为末尾end传递一个空字符串
print("B",end='')#这样print函数不会在字符串末尾添加一个换行符
print("C",end='')#而是添加一个空字符串
print("D",end='')
print("E",end='')
print("F",end='')
print()
print("X")
print("Y")
print("Z")
输出效果:
ABCDEF
X
Y
Z
name=input("Enter your name:")
print(name)
输出Enter your name,然后可以输入姓名,我这里随便写了2个字母qw
Enter your name:qw
qw 显示出qw
number=input("Enter the number:")
先让你输入一个数字 Enter the number:12
number+"6"#要加双引号,否则输出就会出错
显示出126,+表示连接,并不是求和
输入2个整数类型数字,之后输出他们的和
number=int(input("Enter your number:")) #int表示整数类型的定义
number1=int(input("Enter your number:"))
print("sum: "number+number1)
price=2.39
bill=10
change=bill-price
print(round(change,2)) #round的作用是只取小数点后两位数字
7.61
输出宽*高
width=int(input("Enter the width"))
height=int(input("Enter the height"))
area=width*height
print("The are is",area,"square units")
定义两个整数类型的输入数字
base=int(input("Enter the width"))
height1=int(input("Enter the height"))
area=base*height1*0.5 结果如果有小数点,小数点后的数字正常显示
print("The area of a triangle:",area)
最后是今天的作业
radius=float(input("Enter your number:"))
are=3.14*radius**2
print("The area is",area)
name=input("Enter your name")
age=int(input("Enter your age"))
print("name",name,"age",age)
网友评论