python学习No.1-2020/3/18

大学上了四年,第一次在csdn中写blog,这次学习的是python,第一次学,第一次写,算是给自己错误代码做个记录

1.python与c不同,if之后不用{},需要用:,然后和他是一个代码块的代码。要和他首行缩进一样的单位,一般是四格。例如

a=1
b=2
if a<b:
    print("a is less than b")
    print("a is definitely less than b")
print("not sure if a is less than b")

空了相同格数
2.特别注意空格问题

a=3
b=4
if a<b:
    print("c is less than d")
elif  c==d:
    print("c is eauql to f")
else c>d:
    print("c is greater than f")

报错

File “”, line 3
if a<b:
SyntaxError: invalid character in identifier

系找原因发现:
1.if a<b: 是用中文打的,不是用英文。
遇到 SyntaxError: invalid character in identifier考虑1.空格 2.中英文问题

else c>d:

报错:

invalid syntax

语法错误
当这个if clause完成后,else后边只有一种情况,不存在后边在加 c>d:,应该直接为else: python逻辑性很强,省去了人们在去思考其他情况的精力。
3.无elseif 只有elif 或者
else :
if
4.

expected an indented block

少代码缩进块
5,

File “”, line 9
else:
^SyntaxError: invalid syntax

name="YK"
height_m = 2
weight_kg = 90
bmi=weight_kg /(height_m ** 2)
print("bmi:") 
print(bmi)
if (bmi>23):
    print("YK is overweight")
    else:
        print("YK is normai")

错因:if else成对使用,并且在py中其一对一定要缩进一致

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值