Professional Documents
Culture Documents
掌握 Python 代码规范、代码调试。 掌握分支语句、循环语句的使用。 掌握 turtle 库的使用。
掌握 Python 代码规范、代码调试。 掌握分支语句、循环语句的使用。 掌握 turtle 库的使用。
掌握 Python 代码规范、代码调试。 掌握分支语句、循环语句的使用。 掌握 turtle 库的使用。
1. 实验目的
掌握 Python 代码规范、代码调试。
掌握分支语句、循环语句的使用。
掌握 turtle 库的使用。
2. 实验要求
3. 实验内容
(Q1)
4. # list of all the numbers
5. numbers = [37, 12, 5, 42, 8, 3]
6.
7. defining a list of even number even []
8. declaring a list of odd numbers odd[]
9. Checking the whether the length of the list is greater than 0
10. while len(numbers) > 0:
11. number = numbers.pop()
12. if number % 2 == 0: # check whether the number can be divided by 2
13. even.append(number) # if the division is possible, then the number
is even
14.
15. else:
16. odd.append(number) # otherwise the number is odd
17.
18. print("even:", even) # print out all the even numbers in the list
19. print("odd:", odd) # print out all the odd numbers in the list above
(Q2)
score = int(input("请输入一个分数:")) # asking the user to input his score
if 100 >= score >= 90: # if the score is between 100 and 90 , the grade will be
A
print("A")
else:
if 90 > score >= 80: # if the score is between 80and 90 , the grade will be
B
print("B")
else:
if 80 > score >= 70:# if the score is between 70 amd 80 , thegrade will
be C
print("C")
else:
if 70 > score >= 0: # and if the score is less than 70, the grade will
be D
print("D")
(Q3)
def sum(): # defining sum
sum = 0 # sum initialize to zero
for n in range(10,100000): # using for loop to set the range of n between
10 and 10000
sum = sum + n # incrementing sum by n
return sum # returning the value of sum
《Python 编程-从入门到实践》
网络资源
21. 评分标准
A——完成每道题,解题思路、源代码可读性很好,运行结果正确;
B——完成每道题,解题思路、源代码可读性较好,运行结果正确;
C——完成每道题,解题思路、源代码可读性较好,运行结果错误;
D——完成每道题,解题思路、源代码可读性差,运行结果错误;
E——抄袭。