当前位置: 首页 > news >正文

python again_收藏!最全从Python小白到大牛,要走的路这里都有(初级篇)

收藏!长文!从Python小白到大牛,要走的路这里都有面向项目的学习是学习编码的最佳方法。Python是当今最需求的语言,为了帮助您学习它,以下是一些您可以探索的最重要的Python项目:Python游戏Python图像编程CIFAR10在Python中使用TensorFlow

开始看吧,和从开始到放弃说再见

俗话说的好,没吃过猪肉还没见过猪跑?Python虽然对大多数小白来说,可能是从入门到放弃的过程。探究起来,可能初入门的同学没见到过Python美丽的全景,一直埋头写hello world太多了,丧失了对Python的爱才是放弃的主要原因吧。

在本文中,将用真实的代码给你展示从小白到大牛Python项目之旅。只要你敢看,我就敢写。开始吧!

50666b2fc99f0a6d006fc8fa9aa02ac4.png

只要你敢看,就敢让你成大牛

您将学习如何按以下顺序创建这些Python项目:

Python简介如何使用Python创建项目?我们可以用Python进行哪些项目?Python初学者项目:使用Python的Hangman游戏中级Python项目:在Python中数据可视化高级Python项目:使用Python进行机器学习结论下面就开始这次从小白的大牛的Python代码盛宴。

Python简介

1841e9dcd79e2412a76fc6c54d6b5348.png

Python是一种高级的,面向对象的,解释性的编程语言,已经引起了全世界的关注。Stack Overflow发现其38.8%的用户主要在其项目中使用Python。Python又名为Guido Van Rossum的开发人员创建。

Python一直很容易学习和掌握。它非常适合初学者,并且语法非常易于阅读和遵循。这无疑使我们所有人都开心,令人惊奇的是python在全球拥有数百万快乐的学习者!

根据该网站的调查,Python的流行度在2018年超过了C#–就像2017年超过了PHP。在GitHub平台上,Python超过了Java,成为第二大使用的编程语言,与2017年相比,Python发出的拉取请求多40%在2016年。

这使 Python认证成为最受欢迎的编程认证之一。

适用于初学者的Python项目| Python专案范例

27028c2be7eddecbf4cffd061974a3dd.png

如何使用Python创建项目?

这个问题的答案非常简单明了。这一切都始于学习Python的基础知识和所有基础知识。基本上,这是一个衡量指标,可以了解您使用Python的舒适程度。

下一步的主要步骤是查看基本的简单代码,以熟悉代码中的语法和逻辑流程。这是非常重要的一步,也为以后的发展奠定了坚实的基础。

现实生活中的Python?

在此之后,您绝对应该查看python在现实生活中的用途。这将在找出为什么首先要学习Python的过程中扮演重要角色。

如果不是这种情况,那么您将了解项目,并可以为项目实施某些策略,您可以考虑自己开始。

其次肯定是要研究可以解决当前Python知识的项目。深入研究Python将有助于您在每个阶段进行自我评估。

项目基本上用于解决眼前的问题。如果您喜欢为各种简单和复杂的问题提供解决方案,那么您绝对应该考虑从事Python项目。

在完成几个项目后,您将比精通python更近一步。这很重要,因为您将能够自发地将所学到的内容简单地编写为自己编写计算器程序,直至帮助实现人工智能。

我们可以用Python进行哪些项目?

我们可以根据学习者的技能水平将Python项目分为初学者,中级和高级项目。

Python入门级项目

Python子手游戏与Python使用Pygame的蛇游戏使用Python的科学计算器使用Python Flask的产品目标网页使用Python的URL缩短器Python中级项目

使用Python进行网页爬取探索性数据分析在Python中使用Kivy的Pong游戏使用Python Flask / Django Web框架的登录系统泰坦尼克号数据的生存预测Python高级项目

使用OpenCV Python进行面罩检测使用Python进行语音识别使用Python进行文字转语音Python中的聊天机器人使用Selenium的Web浏览器自动化让我们从检查Python项目的第一级开始。

Python初学者项目:使用Python的猜词游戏

我们可以考虑的最好的初学者项目是Hangman游戏。我敢肯定,阅读此Python Projects博客的大多数人在您生命中的某个时间点都曾玩过猜词。简单地说,这里的主要目标是创建一个“猜词”游戏。听起来很简单,但是您需要注意某些关键事项。

用户需要能够输入字母猜测。还应该对可以使用的猜测次数设置一个限制。继续将剩余的次数通知用户。这意味着您将需要一种获取单词以进行猜测的方法。让我们保持简单,并使用文本文件作为输入。文本文件包含我们必须猜测的单词。

您还将需要一些函数来检查用户是否实际输入了单个字母,检查输入的字母是否在隐藏的单词中(如果是,显示了多少次),打印字母,以及一个计数器变量来限制猜测。

d740fa5f8f028599f16ec15911ec2b7d.png

Python基础起步

Python项目要记住的关键概念:

随机变数布尔型输入输出整数串长度打印代码:

Hangman

from string import ascii_lowercasefrom words import get_random_word def get_num_attempts(): """Get user-inputted number of incorrect attempts for the game.""" while True: num_attempts = input( 'How many incorrect attempts do you want? [1-25] ') try: num_attempts = int(num_attempts) if 1 <= num_attempts <= 25: return num_attempts else: print('{0} is not between 1 and 25'.format(num_attempts)) except ValueError: print('{0} is not an integer between 1 and 25'.format( num_attempts)) def get_min_word_length(): """Get user-inputted minimum word length for the game.""" while True: min_word_length = input( 'What minimum word length do you want? [4-16] ') try: min_word_length = int(min_word_length) if 4 <= min_word_length <= 16: return min_word_length else: print('{0} is not between 4 and 16'.format(min_word_length)) except ValueError: print('{0} is not an integer between 4 and 16'.format( min_word_length)) def get_display_word(word, idxs): """Get the word suitable for display.""" if len(word) != len(idxs): raise ValueError('Word length and indices length are not the same') displayed_word = ''.join( [letter if idxs[i] else '*' for i, letter in enumerate(word)]) return displayed_word.strip() def get_next_letter(remaining_letters): """Get the user-inputted next letter.""" if len(remaining_letters) == 0: raise ValueError('There are no remaining letters') while True: next_letter = input('Choose the next letter: ').lower() if len(next_letter) != 1: print('{0} is not a single character'.format(next_letter)) elif next_letter not in ascii_lowercase: print('{0} is not a letter'.format(next_letter)) elif next_letter not in remaining_letters: print('{0} has been guessed before'.format(next_letter)) else: remaining_letters.remove(next_letter) return next_letter def play_hangman(): """Play a game of hangman. At the end of the game, returns if the player wants to retry. """ # Let player specify difficulty print('Starting a game of Hangman...') attempts_remaining = get_num_attempts() min_word_length = get_min_word_length() # Randomly select a word print('Selecting a word...') word = get_random_word(min_word_length) print() # Initialize game state variables idxs = [letter not in ascii_lowercase for letter in word] remaining_letters = set(ascii_lowercase) wrong_letters = [] word_solved = False # Main game loop while attempts_remaining > 0 and not word_solved: # Print current game state print('Word: {0}'.format(get_display_word(word, idxs))) print('Attempts Remaining: {0}'.format(attempts_remaining)) print('Previous Guesses: {0}'.format(' '.join(wrong_letters))) # Get player's next letter guess next_letter = get_next_letter(remaining_letters) # Check if letter guess is in word if next_letter in word: # Guessed correctly print('{0} is in the word!'.format(next_letter)) # Reveal matching letters for i in range(len(word)): if word[i] == next_letter: idxs[i] = True else: # Guessed incorrectly print('{0} is NOT in the word!'.format(next_letter)) # Decrement num of attempts left and append guess to wrong guesses attempts_remaining -= 1 wrong_letters.append(next_letter) # Check if word is completely solved if False not in idxs: word_solved = True print() # The game is over: reveal the word print('The word is {0}'.format(word)) # Notify player of victory or defeat if word_solved: print('Congratulations! You won!') else: print('Try again next time!') # Ask player if he/she wants to try again try_again = input('Would you like to try again? [y/Y] ') return try_again.lower() == 'y' if __name__ == '__main__': while play_hangman(): print()

2. Words.py

"""Function to fetch words.""" import random WORDLIST = 'wordlist.txt' def get_random_word(min_word_length): """Get a random word from the wordlist using no extra memory.""" num_words_processed = 0 curr_word = None with open(WORDLIST, 'r') as f: for word in f: if '(' in word or ')' in word: continue word = word.strip().lower() if len(word) < min_word_length: continue num_words_processed += 1 if random.randint(1, num_words_processed) == 1: curr_word = word return curr_word输出如下:

e68b1ca7b6eabfe672d4dff1c7a6b413.png

后续

目前,了解了如何处理诸如Hangman之类的初学者项目,对其进行一些增强,然后开始下一个中级Python项目。

收藏!从Python小白到大牛,要走的路这里都有(中级篇)

收藏!从Python小白到大牛,要走的路这里都有(高级篇)

相关文章:

  • .Net Core缓存组件(MemoryCache)源码解析
  • php 函数变量 前加,php在函数和变量前面加上@和$符号的区别详解
  • 凸函数与简森不等式(Jensen's inequality)
  • php date参数n,总结PHP date()参数列表
  • 小程序自定义函数—数字千位转换
  • tp3.2.3php环境要求,TP3.2.3开发手册
  • 控件模板
  • php 热点,PHP+jQuery实现中国地图热点数据统计展示效果
  • phpspy.php,一款php后门 phpspy的情况
  • Appium 之处理首次启动手机App时的系统权限弹框
  • 体对角线 matlab,Matlab计算结果显示求不出精确解
  • 数据库ACID操作---事务四原则
  • php html转pdf 简书,Laravel Html 导出 PDF 方案 ----- wkhtmltopdf laravel-snappy
  • aps.net的身份证背景图片
  • matlab怎么画lnx图像,inx图像(lnx的图像函数)
  • Android系统模拟器绘制实现概述
  • CAP 一致性协议及应用解析
  • Consul Config 使用Git做版本控制的实现
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • js中的正则表达式入门
  • Mocha测试初探
  • Python socket服务器端、客户端传送信息
  • SpriteKit 技巧之添加背景图片
  • Vue实战(四)登录/注册页的实现
  • 看域名解析域名安全对SEO的影响
  • 每天一个设计模式之命令模式
  • 模仿 Go Sort 排序接口实现的自定义排序
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 用Python写一份独特的元宵节祝福
  • 第二十章:异步和文件I/O.(二十三)
  • 回归生活:清理微信公众号
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #Ubuntu(修改root信息)
  • (26)4.7 字符函数和字符串函数
  • (4)Elastix图像配准:3D图像
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • (分类)KNN算法- 参数调优
  • (附源码)springboot车辆管理系统 毕业设计 031034
  • (三)mysql_MYSQL(三)
  • (转)Unity3DUnity3D在android下调试
  • .htaccess配置常用技巧
  • .naturalWidth 和naturalHeight属性,
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • .NET Core使用NPOI导出复杂,美观的Excel详解
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .Net面试题4
  • [ArcPy百科]第三节: Geometry信息中的空间参考解析
  • [BUG] Authentication Error
  • [BZOJ]4817: [Sdoi2017]树点涂色
  • [c#基础]DataTable的Select方法
  • [C++]打开新世界的大门之C++入门
  • [flume$2]记录一个写自定义Flume拦截器遇到的错误
  • [HEOI2013]ALO