Week 3 all the quizzes
第三周所有的quiz,详细解释,答案供参考。详细
You should take it easy. 详细的解说等我闲一点了再添加上去,【官方解释】的是老师给的解释,大部分都是能看明白的。
List
Preface
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
Lecture: Control flow
Expressions and control flow quiz
question 1
The following code uses int casting. What is the difference between the value calculated with and without the int casting?
print(str(int(float("3.14"))+int(float("5.6"))))
answer : 0.74
讲解: 在代码块里运行的时候,输出结果是8。但是那是错的,正确理解是取浮点数小数点后面的数字相加,就是结果。(待更新更好的解释)
question 2
Do the following two code segments have equivalent outcome (control flow)?
ticket = 240
if speed > 0:
if speed < 40:
ticket = 0
else:
if speed > 100:
pass
else if speed <= 100:
ticket = 120
else:
pass
else:
pass
ticket = 0
if speed < 40:
ticket = 0
else if speed <= 100:
ticket = 120
if speed