知识点一:
If a<b :
a,b=b,a
支持同时赋值
if语句块与C语言有所不同
c:if(a<b){}
知识点二:
If a==b or a==c:
两个值相等
If a==b==c:
三个值相等
知识点三:
year=int(input("pls input year:")) #使用input输入前需要声明类型
month=int(input("pls input month:"))
day=int(input("pls input day:"))
if year>0:
if month in[1,3,5,7,8,10,12]: #如果month的值为方括号中的数就可进行下一步
if i<=day<=31:
知识点四:
import random
a=random.randint(0,100)
b=random.randint(0,100)
print("The first number is :",a)
print("The second number is :",b)
c=int(input("please input the sum:"))
if c == (a+b):
print("The sum is right")
else :
print("The sum is error")
1.random 模块的 randint() 函数来生成随机数,该函数的语法为:random.randint(a,b)
2.开头需要输入import random
知识点五:
import math
import turtle
x1,y1=eval(input("pls input the center of the first circle:"))
r1=int(input("pls input the radius of the first circle:"))
x2,y2=eval(input("pls input the center of the second circle:"))
r2=int(input("pls input the radius of the second circle:"))
d = math.hypot(x1-x2,y1-y2)
turtle.penup()
turtle.goto(x1,y1-r1)
turtle.pendown()
turtle.circle(r1)
turtle.penup()
turtle.goto(x2,y2-r2)
turtle.pendown()
turtle.circle(r2)
turtle.hideturtle()
turtle.done()
1.eval是Python的一个内置函数,这个函数的作用是,返回传入字符串的表达式的 结果。想象一下变量赋值时,将等号右边的表达式写成字符串的格式,将这个字符串作为eval的参数,eval的返回值就是这个表达式的结果。
eval函数暂时还未深入了解,下一次将深入理解。
知识点六:
score = int(input("pls input an score:"))
if score<0 or score >100: #或者if not(score>=0 and score<=100)
print("invalid score")
elif score>=90.0:
print("gpa=",(90-50)/10)
elif score>=80.0:
print("gpa=",(80-50)/10)
else:
print("gpa=","cannot go abroad!")
1.Python中没有switch/case语句,用elif语句来模拟它
2.C语言中采用&&,||来表示
python中采用or,and表示