明天 今天上机考试,说实话有点慌张(两小时六道题,写得完写不完心里还没点数
冲呀
话说回来今日昨天的 运势(再熬夜我是猪头系列/我必洗澡 T x T
现在开始代码阶段复习,(因为ldw老师说他考六道题,我也不知道大致分布,所以只能盲猜。有一说一,课后作业有13个,二选一我还达不到六分之一吗,别紧张……好紧张哈哈哈哈哈哈哈哈哈哈哈哈哈哈,大笑掩饰,欲盖弥彰哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈)
回顾一下作业好了
- 三角形形状判断(反正我是会的
基本的input操作& if判断 &print操作
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/10/22 10:37
# @Author : Chen Shan
# Function :Judge triangle type
a = int(input("请输入一个整数(三角形的边长a):"))
……
if ……:
print("这三条边无法构成一个三角形")
elif ……:
print("这是一个等腰三角形")
else:
print("这是一个三角形")
- 一张纸折叠多少次才可以到达珠穆朗玛峰的高度(这题果然很ldw老师,众所周知的是一张纸最多可以折叠7次orz
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/10/22 10:37
# @Author : Chen Shan
# Function : Calculate the number of times the paper is folded in half
paper_width = 0.00008
mountain_width = 8848.13
cnt = 0
while True:
……
if ……:
break
print("需要对折"+str(cnt)+"次才可以")
- 求解鸡兔同笼问题(没得问题我也会‘
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/10/22 10:37
# @Author : Chen Shan
# Function : Solve the problem of chicken and rabbit in the same cage
a = int(input("请输入一个整数(头的个数):"))
b = int(input("请输入一个整数(腿的个数):"))
hand = 0
foot = 0
for i in range(0,a+1):
if &:
print("鸡的个数是:"+……+",兔的个数是"+……)
break
else:
print("此输入无解")
- 读写多维矩阵(主要考的知识点就是读写操作吧…其实我有点忘记了毕竟我俩小时才写出一个代码我凑了
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/10/22 10:37
# @Author : Chen Shan
# Function : Read & write multidimensional matrix
# file_name:读入或写入的文件名称
# data_list:读入或写入的数据链表
# data_tpye:数据类型
# 1:int;2:float;3:string
# n:矩阵维度
def f_write(file_name,data_list,n=2,data_type=1):
f = open(file_name,'w')
if n != 2:
……
elif n == 2:
……
f.close()
def f_read(file_name,output_list=[],n=2,data_type=1):
f = open(file_name,'r')
if n != 2:
……
elif n == 2:
……
f.close()
print(output_list)
# =========== test on n=3 int =============
int_3_list=[[[1,2,2,3],[2,3,3,4]],[[1,2,2,3],[2,3,3,4]],[[1,2,2,3],[2,3,3,4]]]
f_write('int_3_test.txt',int_3_list,n=3)
int_o_3_list=[]
f_read('int_3_test.txt',int_o_3_list,n=3)
print('------------------------')
# --- test on n=3 string ---
str_3_list = [[['a','b','c'],['d','ef','g']],[['a','b','c'],['d'<