Compare commits
2 Commits
0a9c136d90
...
8fc93fcc0e
| Author | SHA1 | Date | |
|---|---|---|---|
| 8fc93fcc0e | |||
| 8f86474ad7 |
8
2026-03-17/2026-03-17_hw_1.py
Normal file
8
2026-03-17/2026-03-17_hw_1.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# 判断整数是否是回文数
|
||||
|
||||
n = int(input("请输入整数: "))
|
||||
sn = str(n)
|
||||
if sn == sn[::-1]:
|
||||
print("输入的是回文数")
|
||||
else:
|
||||
print("输入的不是回文数")
|
||||
18
2026-03-17/2026-03-17_hw_2.py
Normal file
18
2026-03-17/2026-03-17_hw_2.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# 物流计费系统
|
||||
|
||||
d = {"01": (13, 3), "02": (12, 2), "03": [14, 4]}
|
||||
area = input("请输入地区编号: ")
|
||||
weight = 0
|
||||
while True:
|
||||
try:
|
||||
weight = int(input("请输入重量(kg): "))
|
||||
break
|
||||
except ValueError:
|
||||
print("请输入整数...")
|
||||
if area not in d:
|
||||
print("地区编号不正确,请输入正确的地区编号")
|
||||
else:
|
||||
(p1, p2) = d[area]
|
||||
if weight < 2:
|
||||
weight = 2
|
||||
print("价格是: " + str(p1 + (weight - 2) * p2))
|
||||
7
2026-03-17/2026-03-17_hw_3.py
Normal file
7
2026-03-17/2026-03-17_hw_3.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# 九九乘法表
|
||||
|
||||
n = 9
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, i + 1):
|
||||
print(j, '*', i, '=', i * j, sep=" ", end="\t")
|
||||
print()
|
||||
BIN
2026-03-17/24计应1_杨近澜_1113_2026-03-17作业.docx
Normal file
BIN
2026-03-17/24计应1_杨近澜_1113_2026-03-17作业.docx
Normal file
Binary file not shown.
28
2026-03-24/2026-03-24_hw_1.py
Normal file
28
2026-03-24/2026-03-24_hw_1.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# 实现简单的四则运算计算器
|
||||
# 输入两个数一个运算符,输出结果
|
||||
|
||||
|
||||
def add(num1:float, num2:float) -> float:
|
||||
return num1 + num2
|
||||
def sub(num1:float, num2:float) -> float:
|
||||
return num1 - num2
|
||||
def mul(num1:float, num2:float) -> float:
|
||||
return num1 * num2
|
||||
def div(num1:float, num2:float) -> float:
|
||||
return num1 / num2
|
||||
|
||||
def main():
|
||||
a1 = float(input("请输入第一个数: "))
|
||||
a2 = float(input("请输入第二个数: "))
|
||||
s = input("请输入运算符: ")
|
||||
|
||||
if s not in ["+", "-", "*", "/"]:
|
||||
print("请输入正确的符号")
|
||||
return
|
||||
|
||||
p = {"+": add, "-": sub, "*": mul, "/": div}
|
||||
print(p[s](a1, a2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
61
2026-03-24/2026-03-24_hw_2.py
Normal file
61
2026-03-24/2026-03-24_hw_2.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# 入机猜拳
|
||||
|
||||
|
||||
import random
|
||||
|
||||
class Player:
|
||||
def __init__(self):
|
||||
self.dict_gesture = {0: '剪刀', 1: '石头', 2: '布'}
|
||||
|
||||
def gesture(self, num):
|
||||
return self.dict_gesture[num]
|
||||
|
||||
class AIPlayer(Player):
|
||||
play_data = [] # 存储玩家猜拳手势(类属性)
|
||||
|
||||
def ai_gesture(self):
|
||||
while True:
|
||||
computer = random.randint(0, 2)
|
||||
if len(self.play_data) >= 4:
|
||||
# 获取玩家出拳的最大概率
|
||||
max_prob = max(self.play_data, key=self.play_data.count)
|
||||
if max_prob == '剪刀':
|
||||
return '石头'
|
||||
elif max_prob == '石头':
|
||||
return '布'
|
||||
else:
|
||||
return '剪刀'
|
||||
else:
|
||||
return self.dict_gesture[computer]
|
||||
|
||||
class Game(Player):
|
||||
def game_judge(self):
|
||||
player_num = int(input("请输入(0剪刀、1石头、2布:)")) # 玩家输入的手势
|
||||
player = self.gesture(player_num)
|
||||
AIPlayer().play_data.append(player)
|
||||
ai_player = AIPlayer().ai_gesture()
|
||||
|
||||
if (player == '剪刀' and ai_player == '布') or \
|
||||
(player == '石头' and ai_player == '剪刀') or \
|
||||
(player == '布' and ai_player == '石头'):
|
||||
print(f"电脑出的手势是{ai_player},恭喜,你赢了!")
|
||||
elif (player == '剪刀' and ai_player == '剪刀') or \
|
||||
(player == '石头' and ai_player == '石头') or \
|
||||
(player == '布' and ai_player == '布'):
|
||||
print(f"电脑出的手势是{ai_player},打成平局了!")
|
||||
else:
|
||||
print(f"电脑出的手势是{ai_player},你输了,再接再厉!")
|
||||
|
||||
def main(self):
|
||||
self.game_judge()
|
||||
while True:
|
||||
option = input("是否继续:y/n\n")
|
||||
if option == 'y':
|
||||
self.game_judge()
|
||||
else:
|
||||
break
|
||||
|
||||
# 程序入口
|
||||
if __name__ == "__main__":
|
||||
game = Game()
|
||||
game.main()
|
||||
28
2026-03-24/2026-03-24_hw_3.py
Normal file
28
2026-03-24/2026-03-24_hw_3.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# 实现 Circle 类...
|
||||
|
||||
|
||||
import math
|
||||
|
||||
class Circle():
|
||||
radius = float(0)
|
||||
def __init__(self, radius:float) -> None:
|
||||
self.radius = radius
|
||||
|
||||
def get_peimeter(self) -> float:
|
||||
return math.pi * self.radius * 2
|
||||
|
||||
def get_area(self) -> float:
|
||||
return math.pi * (self.radius ** 2)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"radius: {self.radius}\npeimeter: {self.get_peimeter()}\narea: {self.get_area()}\n"
|
||||
|
||||
def main() -> int:
|
||||
cir1 = Circle(3.0)
|
||||
# print(str(cir1))
|
||||
print(f"cir1: peimeter: {cir1.get_peimeter()}")
|
||||
print(f"cir1: narea: {cir1.get_area()}")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第10章 错误和异常.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第10章 错误和异常.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第1章 开启Python学习之旅.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第1章 开启Python学习之旅.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第2章 数字类型与字符串.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第2章 数字类型与字符串.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第3章 流程控制.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第3章 流程控制.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第4章 列表与元组.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第4章 列表与元组.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第5章 字典和集合.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第5章 字典和集合.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第6章 函数.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第6章 函数.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第7章 类与面向对象.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第7章 类与面向对象.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第8章 模块.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第8章 模块.pptx
Normal file
Binary file not shown.
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第9章 文件与文件路径操作.pptx
Normal file
BIN
Python程序开发案例教程_黑马(第2版)-教学PPT/Python基础-第9章 文件与文件路径操作.pptx
Normal file
Binary file not shown.
Reference in New Issue
Block a user