python学习1.0

知识点一:

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表示

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值