20223210 2022-2023-2 《Python程序设计》实验一报告
课程:《Python程序设计》
班级: 2232
姓名: 黄湛
学号:20223210
实验教师:王志强
实验日期:2023年3月9日
必修/选修: 公选课
(一)实验内容
- 熟悉Python开发环境
- 练习Python运行、调试技能
- 编写程序,练习变量和类型、字符串、缩进和注释等
a = 10
type(a)
<class 'int'>
b = 5
if a > b:
print("a > b")
elif a < b:
print("a < b")
else:
print("a = b")
a > b
# a = 10
c = "abcd"
# c = 20
type(c)
<class 'str'>
print(c)
abcd
d = list(range(1,10,2))
print(d)
[1, 3, 5, 7, 9]
e = (2,3,4,5,6)
type(e)
<class 'tuple'>
len(e)
5
(二)实验过程及结果
- 熟悉Pycharm等开发环境;
汉化Pycharm (File–Settings–Plugins–搜索Chinese)
- 掌握基本的Python编程技能
猜数字游戏(自选游戏难度、重复游戏)
end = 1
while end == 1:
print("Please enter the game difficulty(1~10) you selected:")
level = int(input())
import random
answer = random.randint(1, 100 * level)
print("Please enter the number you guessed:")
guess = int(input())
while guess!=answer:
if answer > guess:
print("It's too small")
else:
print("It's too big")
print("Please enter the number you guessed again:")
guess = int(input())
print("Great!")
print("Please choose whether you want to continue the game(1:Yes;0:No):")
end = int(input())
- 掌握基本的Python运行和调试技能
单步调试(添加断点–debug)
- 程序代码托管到码云(pycharm配置git–add–commit–push)
(三)实验过程中遇到的问题和解决过程
- 问题1:不知道如何将代码上传到码云
- 问题1解决方案:参照群里同学分享链接,按步骤实现为pycharm配置gitee
- 问题2:python和c语言的一些语法不同,特别是由于我有喜欢添加空格以求代码整洁便于阅读的编程习惯(例如
if(a > b)
而非if(a>b)
,for(int i = 1 ; i <= n ; ++ i)
而非for(int i=1;i<=n;++i)
),而python中并不能在if后的条件句与冒号间添加空格,经常容易导致运行错误 - 问题2解决方案:放慢写代码的速度,更细心注意语法问题
感悟与思考
与c/c++相比,python确实有容易上手之处,但其功能不可小觑。在以后的学习过程中,我应该更加注重探索与实践,深入了解掌握相关编程本领。