• 关于上回的练习解答
  • 关于上节内容的回顾
  • 练习题
  • 赋值运算符

关于上回的练习解答



请利用以上所学知识1,运用加减乘除计算出四个数字的24点,并打印。





关于上节内容的回顾

abs(x)->取绝对值

int(x)->取整数

float(x)->取浮点数







练习题



abs("1")能正常输出吗?如果不能的话请说出理由。



赋值运算符


1-1:python也允许我们同时为多个变量赋值(包括为多个变量赋不同类型的值),例如:


a = b = c = 3  #三个变量赋同样的值  
d, e, f = -3, 3.3, 'u3v3'  #三个变量赋不同类型的值


1-2:赋值运算的种类



# -*- coding: UTF-8 -*-

a = 1
b = 2
c = 3

c = a + b
print ("Line 1 - Value of c is ", c)

c += a
print ("Line 2 - Value of c is ", c )

c *= a
print ("Line 3 - Value of c is ", c )

c /= a 
print ("Line 4 - Value of c is ", c )

c  = 2
c %= a
print ("Line 5 - Value of c is ", c)

c **= a
print ("Line 6 - Value of c is ", c)

c //= a
print ("Line 7 - Value of c is ", c)



以上输出结果如下:

Line 1 - Value of c is  3
Line 2 - Value of c is  4
Line 3 - Value of c is  4
Line 4 - Value of c is  4.0
Line 5 - Value of c is  0
Line 6 - Value of c is  0
Line 7 - Value of c is  0
right