找回密码
 立即注册
查看: 455|回复: 2

学习python的笔记

[复制链接]
  • 打卡等级:常住居民III
  • 打卡总天数:180
  • 最近打卡:2025-06-18 09:19:13

32

主题

149

回帖

1153

积分

金牌会员

积分
1153
发表于 2024-10-1 11:36:38 | 显示全部楼层 |阅读模式
最近一个月需要突击编程和算法基础。虽然考试用的是c/c++
鉴于python在工作中的强大用处,
所以先用python学下。等把思路理顺再突击下往年的真题。

环境为win10 64Bit+vscode
上来就是下马威:缩进时候tab和space不能混用。哪怕tab是四个空格宽度,手动敲四下空格也不可以!会报告

IndentationError: unindent does not match any outer indentation level



以下是正确的。统统用了tab缩进


  1. #coding:utf-8
  2. def func1():
  3.    row=1
  4.    while row<5:
  5.       col=1
  6.       while col<=3:
  7.          print(col,end=" ")
  8.          col+=1
  9.       print()
  10.       row+=1
  11. if __name__=='__main__':
  12.    func1()
复制代码

输出为
  1. 1 2 3
  2. 1 2 3
  3. 1 2 3
  4. 1 2 3
复制代码




回复

使用道具 举报 送花

  • 打卡等级:常住居民III
  • 打卡总天数:180
  • 最近打卡:2025-06-18 09:19:13

32

主题

149

回帖

1153

积分

金牌会员

积分
1153
发表于 2024-10-1 11:48:48 | 显示全部楼层
本帖最后由 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()       
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:常住居民III
  • 打卡总天数:180
  • 最近打卡:2025-06-18 09:19:13

32

主题

149

回帖

1153

积分

金牌会员

积分
1153
发表于 2024-10-1 13:39:46 | 显示全部楼层
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[room_id].append(teacher)
                print(f"{room_id} room {teacher}\n")

        for i in l_room:
                print(i)
               
回复 支持 反对

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-6-19 00:28 , Processed in 0.122094 second(s), 57 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表