Python入门之基础语法

Python入门之基础语法

  1. 行与缩进
#有错误的函数1
def wrong1():
    print("wrong1")
    print("这里有一个错误缩进")
    
#有错误的函数2
def wrong2():
    print("wrong2")
    if False:
        print("这个不应该输出")
        print("这个也不应该输出")

#有错误的函数3
def wrong3():
    print("wrong3") 
    print("hello world")


#这里是调用三个函数的代码
#不要修改
if __name__ == '__main__':

    wrong1()
    wrong2()
    wrong3()

2.标识符与保留字

import keyword

if __name__ == '__main__':
    #错误1
    str1 = "string"
    print(str1)

    #错误2
    l1024 = 1024
    print(l1024)

    #错误3
    float_1 = 1.024
    print(float_1)

    #错误3
    False1 = False
    print(False1)


    #在此处输出保留关键字
    print(keyword.kwlist)
    print("end")

    

    

  1. 标识符与保留字注释
if __name__ == '__main__':


    #以下是要修改的代码

    print(1)
 #   print(2)
    print(3)
  #  print(4)
    print(5)
  #  print(6)

    
    print("hello world")
 #   print("这个不应该输出")

#    print(1)
 #   print(2)
    print(3)
    print(4)

  1. 输入输出
if __name__ == "__main__":
    a = int(input())
    b = int(input())
# ********** Begin ********** #
c = a + b
d = a - b
e = a * b
f = a / b
print("%d + %d = %d"%(a,b,c))   
print("%d - %d = %d"%(a,b,d))   
print("%d * %d = %d"%(a,b,e))     
print("%d / %d = %.6f"%(a,b,f))     
# ********** End ********** #


你可能感兴趣的:(educoder,python)