学习python的笔记
最近一个月需要突击编程和算法基础。虽然考试用的是c/c++鉴于python在工作中的强大用处,
所以先用python学下。等把思路理顺再突击下往年的真题。
环境为win10 64Bit+vscode
上来就是下马威:缩进时候tab和space不能混用。哪怕tab是四个空格宽度,手动敲四下空格也不可以!会报告
IndentationError: unindent does not match any outer indentation level
以下是正确的。统统用了tab缩进
#coding:utf-8
def func1():
row=1
while row<5:
col=1
while col<=3:
print(col,end=" ")
col+=1
print()
row+=1
if __name__=='__main__':
func1()
输出为
1 2 3
1 2 3
1 2 3
1 2 3
本帖最后由 yzhkpli 于 2024-10-1 11:52 编辑
99乘法表
def multiply_9by9():
rows=1
while rows<=9:
cols=1
while cols<=rows:
#print(rows,"*",cols,"=",rows*cols,end="")
print("%d*%d=%d" % (rows,cols,rows*cols),end=" ")
cols+=1
rows+=1
print()
3-练习:办公室分配
需求
一个学校,三间办公室,现在有8位老师等待工位分配
[‘yuan1’,’ma2’,’zhagn3’,’li4’,’xiong5’,’feng6’,’cao7’,’liu8’]
请完成:随机分配
2打印办公室信息(每间办公室的人数,分别是谁)
以下是教程的程序
import random
def assigenment():
l_teacher=['yuan1','ma2','zhagn3','li4','xiong5','feng6','cao7','liu8']
l_room=[[],[],[]]
for teacher in l_teacher:
room_id=random.randint(0,len(l_room)-1)
l_room.append(teacher)
print(f"{room_id} room {teacher}\n")
for i in l_room:
print(i)
页:
[1]