学员闯关手册:https://aicarrier.feishu.cn/wiki/ZcgkwqteZi9s4ZkYr0Gcayg1n1g?open_in_browser=true
课程视频:https://www.bilibili.com/video/BV1mS421X7h4/
课程文档:https://github.com/InternLM/Tutorial/tree/camp3/docs/L0/Python
关卡作业:https://github.com/InternLM/Tutorial/blob/camp3/docs/L0/Python/task.md
开发机平台:https://studio.intern-ai.org.cn/
开发机平台介绍:https://aicarrier.feishu.cn/wiki/GQ1Qwxb3UiQuewk8BVLcuyiEnHe
(截图显示在(作业)第三期书生·浦语大模型实战营(十一卷王场)–书生入门岛通关第2关Python 基础知识)
Python实现wordcount
import string
def wordcount(text):
# Removing punctuation and converting text to lowercase
cleaned_text = text.translate(str.maketrans('', '', string.punctuation)).lower()
# Splitting the text into words
words = cleaned_text.split()
# Counting the occurrences of each word
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
text = """
Got this panda plush toy for my daughter's birthday,
who loves it and takes it everywhere. It's soft and
super cute, and its face has a friendly look. It's
a bit small for what I paid though. I think there
might be other options that are bigger for the
same price. It arrived a day earlier than expected,
so I got to play with it myself before I gave it
to her.
"""
wordcount=wordcount(text)
print(wordcount)
使用本地Vscode连接InternStudio开发机
开发机–》SSH连接–》登录命令复制
电脑端VSCODE–》扩展页面图标–》SSH搜索和安装
电脑端VSCODE–》远程连接图标–》SSH±-》输入框中输入SSH key配置,回车–》默认配置–》连接–》lunix(注意如果本地电脑没有设置私钥,需要粘贴复制SSH连接中的密码到电脑端VSCODE)
电脑端VSCODE–》文件夹–》ROOT
使用Vscode进行Python debug的流程
VSCODE连接远程开发机—>打开远程文件夹—>新建文件python_debug_tutorial.py—>点击断点—》点击VSCode侧边栏的“Run and Debug”(运行和调试)—》然后点击“运行和调试”按钮,或者按F5键----》弹出框中依次选python debugger,仅python文件,—》查看变量,单步执行代码
def add_numbers(a,b,c):
sum = 0#这里其实覆盖了python自带的sum方法。
sum +=a
sum +=b
sum +=c
print("The sum is ",sum)
if __name__ =='__main__':
x,y,z = 1,2,3
result = add_numbers(x,y,z)#图中代码这里写成1,2,3了
print("The result of sum is ",result)
debug面板各按钮功能介绍:
1: continue: 继续运行到下一个断点
2: step over:跳过,可以理解为运行当前行代码,不进入具体的函数或者方法。
3: step into: 进入函数或者方法。如果当行代码存在函数或者方法时,进入代码该函数或者方法。如果当行代码没有函数或者方法,则等价于step over。
4: step out:退出函数或者方法, 返回上一层。
5: restart:重新启动debug
6: stop:终止debug