 掌握 Python 代码规范、代码调试。  掌握分支语句、循环语句的使用。  掌握 turtle 库的使用。

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

实验一

1. 实验目的

 掌握 Python 代码规范、代码调试。
 掌握分支语句、循环语句的使用。
 掌握 turtle 库的使用。

2. 实验要求

 独立完成实验内容,每道题对应一个 python 文件,务必注意题号和文件对应;提


交时务必注意文件夹命名要求。
 实验报告(简单要求如下):
1) 附上每道题的问题描述;
2) 附上每道题的解题思路;
3) 附上每道题的源代码;
4) 附上每道题的运行结果。

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

print(sum()) # printing out the value of the sum


20. 参考资料

 《Python 编程-从入门到实践》

 《Python 语言程序设计基础(第 2 版)》

 网络资源

21. 评分标准

 A——完成每道题,解题思路、源代码可读性很好,运行结果正确;
 B——完成每道题,解题思路、源代码可读性较好,运行结果正确;
 C——完成每道题,解题思路、源代码可读性较好,运行结果错误;
 D——完成每道题,解题思路、源代码可读性差,运行结果错误;
 E——抄袭。

You might also like