20241114《Python程序设计》实验一报告
20241114 2024-2025-2《Python程序设计》实验一报告
课程:《Python程序设计》
班级: 2411班
姓名: 陈飞达
学号:20241114
实验教师:王志强
实验日期:2024年3月12日
必修/选修: 公选课
一.实验内容
1.熟悉Python开发环境;
2.练习Python运行、调试技能;(编写书中的程序,并进行调试分析,要有过程)
3.编写程序,练习变量和类型、字符串、对象、缩进和注释等;(编写一个猜数字和一个剪刀石头布的游戏)
4.掌握git技能
二. 实验过程及结果
第一步:看懂UI布局
第二步:正常编写两个程序,代码如下:
石头剪刀布:
print("""
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
游戏时间到——————快来玩游戏吧!
今天的游戏是——————剪刀石头布!
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
@游戏名称:游戏——剪刀石头布
@作者:Fida1214
@日期:2025/3/12
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
""")
import random
while True:
print("请出石头、剪刀或布")
random_choice = random.randint(1, 3)
user_choice = str(input("请输入你的选择,放心,我不会偷看的。"))
if user_choice == "石头":
user_choice = int(1)
elif user_choice == "剪刀":
user_choice = int(2)
elif user_choice == "布":
user_choice = int(3)
if random_choice == user_choice:
print("可恶,是你赢了!不玩了不玩了!")
break
else:
print("哈哈,笨蛋输喽!再来一局!")
猜数字:
level = int(input("请输入你的CR(挑战等级):1 = fresh;2 = medium;3 = difficult。"))
if level == 1:
level = 20
elif level == 2:
level = 50
elif level == 3:
level = 100
import random
print("There is a number between 1 and 100,please enter the number")
random_number = random.randint(1, level)
while True:
input_number = int(input("Please input your number: "))
if input_number == random_number:
print("You win!")
break
elif input_number > random_number:
print("You lose!It is too high!")
elif input_number < random_number:
print("You lose!It is too low!")
运行结果举例:
第三步:设置断点debug调试。
第四步:安装PyInstaller并用PyInstaller命令打包。
使用下面指令安装:
pip install pyinstaller
打包后打开过程如下:
第五步:使用git上传到Gitee上。
相应举例:
附:Gitee仓库链接:
https://gitee.com/fida1214/python-programming-assignment/blob/master/Homework2.py
https://gitee.com/fida1214/python-programming-assignment/blob/master/Homework3.py
三. 实验过程中遇到的问题和解决过程
- 问题1:打包完成后,没有找到相应的位置打开。
- 问题1解决方案:询问老师,在总文件夹中的"dist"文件夹中找到。
- 问题2:打包后如何运行,相应的指令不会打。
- 问题2解决方案:从CSDN上找到了相应的博客,成功解决。
其他(感悟、思考等)
python这门语言的全能型令我惊叹,应该说不愧是面向对象的编程语言,虽然有很多不了解的点,而且目前学会的功能相对较少,但相信在老师和众多的大佬的博客的帮助下,一切都能迎刃而解,未来,一定能完成自己理想中的程序————一个游戏!