你肯定想学习的顶级Python项目(附代码)

您所在的位置:网站首页 python项目源码买了不会用 你肯定想学习的顶级Python项目(附代码)

你肯定想学习的顶级Python项目(附代码)

2022-06-12 09:04| 来源: 网络整理| 查看: 265

Python项目–Python的初级、中级和高级

在这个“Python 项目”博客中,让我们来看3个级别的Python项目,通过这三个项目您将会学习掌握Python,以及从整体上测试项目的分析、开发和处理问题的技能。

如果我说Python的学习真的很有趣,很多人都会同意的。

我们先浏览下面的主题列表,之后开始阅读这篇Python项目博客:

Python简介

如何学习Python项目?

初级Python项目:用Python玩汉格曼游戏

中级Python项目:在Python中使用图形

高级Python项目:使用Python进行机器学习

结论

我应当先向您简单介绍一下Python。

Python简介

Python是一种高级的、面向对象的、解释性的编程语言。它在世界上享有广泛关注。Stack Overflow发现38.8%的用户主要使用Python来完成项目。

Python是由一个名为Guido Van Rossum的开发人员创建的。

Python是而且一直是很容易学习和掌握的。它对初学者非常友好,语法非常简单,易于阅读和理解。这特别让我们高兴,而令人更高兴的是Python在全球拥有数百万快乐的学习者!

根据该网站的调查,在2018年,Python的人气超过了c#,就像它在2017年超过了php一样。在GitHub平台上,Python超越了Java成为第二个最常用的编程语言,在2017中比2016多获得了40%的申请。

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

如何学习Python项目?

答案相当简单直接:从学习Python的初级知识和所有基本知识开始。这是一个用于了解您使用Python舒适程度的评价指标。

下一个主要步骤是看一看基本、简单的代码,以熟悉代码中的语法和逻辑流。这是一个非常重要的步骤,有助于为以后的工作打下坚实的基础。

在这之后,您还要看看在现实生活中Python如何使用。这将成为您在开始就要学习Python的主要原因。

如果您不是刚入门Python,那么您将会学习Python项目,并对自己的项目实施一些策略。接下来一定要看看您可以利用当前关于Python的知识进行处理哪些项目。深入研究Python会帮助您在各个阶段评估自己。

项目基本上是用来解决眼下问题的。如果为各种简单或复杂的问题提供解决方案是您的特长,那么您一定要考虑学习Python的项目。

每当着手搞定几个项目之后,您距离掌握Python将更近一步。这一点很重要,因为这样您就能够自然地将所学的知识应用到项目中,从简单的程序如计算器,到辅助实现人工智能的学习。

让我们从第一级的Python项目开始学习。

https://www.edureka.co/Python-programming-certification-training初级Python项目:用Python实现《Hangman》游戏

我们能想到的最好的入门项目是《Hangman》游戏。我敢肯定读过这篇Python项目博客的大多数人都曾在生活中某个时刻玩过《Hangman》。用一句话来解释,它的主要目标是创建一个“猜词”游戏。尽管听起来很简单,但有一些关键的东西需要注意。

需要用户能够输入猜测的字母。

需要限制他们的猜测次数。

需要不停地告知用户剩余圈数。

这意味着你需要一种方法来获取一个用于猜测的单词。让我们用简单思维,使用文本文件输入。文本文件包含了我们必须猜测的单词。

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

这个Python项目中有一些关键的概念需要牢记:

随机

变量

布尔值

输入和输出

整形值

字符型值

字符串

字符串长度

打印

代码:

1. Hangman.py

from string import ascii_lowercase from 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 ' + '-' * (bar_len - filled_len) msg = "Global step: {:>5} - [{}] {:>3}% - acc: {:.4f} - loss: {:.4f} - {:.1f} sample/sec"             print(msg.format(i_global, bar, percentage, batch_acc, batch_loss, _BATCH_SIZE / duration))    test_and_save(i_global, epoch) def test_and_save(_global_step, epoch):     global global_accuracy     global epoch_start     i = 0     predicted_class = np.zeros(shape=len(test_x), dtype=np.int)     while i < len(test_x): j = min(i + _BATCH_SIZE, len(test_x)) batch_xs = test_x[i:j, :] batch_ys = test_y[i:j, :] predicted_class[i:j] = sess.run( y_pred_cls, feed_dict={x: batch_xs, y: batch_ys, learning_rate: lr(epoch)} ) i = j correct = (np.argmax(test_y, axis=1) == predicted_class) acc = correcan()*100 correct_numbers = correct.sum() hours, rem = divmod(time() - epoch_start, 3600) minutes, seconds = divmod(rem, 60) mes = "\nEpoch {} - accuracy: {:.2f}% ({}/{}) - time: {:0>2}:{:0>2}:{:05.2f}"     print(mes.format((epoch+1), acc, correct_numbers, len(test_x), int(hours), int(minutes), seconds))  if global_accuracy != 0 and global_accuracy < acc: summary = tf.Summary(value=[ tf.Summary.Value(tag="Accuracy/test", simple_value=acc), ]) train_writer.add_summary(summary, _global_step) saver.save(sess, save_path=_SAVE_PATH, global_step=_global_step) mes = "This epoch receive better accuracy: {:.2f} > {:.2f}. Saving session..."         print(mes.format(acc, global_accuracy))         global_accuracy = acc      elif global_accuracy == 0:         global_accuracy = acc  print("###########################################################################################################") def main():     train_start = time()     for i in range(_EPOCH):         print("\nEpoch: {}/{}\n".format((i+1), _EPOCH))         train(i)     hours, rem = divmod(time() - train_start, 3600)     minutes, seconds = divmod(rem, 60)     mes = "Best accuracy pre session: {:.2f}, time: {:0>2}:{:0>2}:{:05.2f}"     print(mes.format(global_accuracy, int(hours), int(minutes), seconds)) if __name__ == "__main__":     main() sess.close()

输出:

Epoch: 60/60   Global step: 23070 - [>-----------------------------]   0% - acc: 0.9531 - loss: 1.5081 - 7045.4 sample/sec Global step: 23080 - [>-----------------------------]   3% - acc: 0.9453 - loss: 1.5159 - 7147.6 sample/sec Global step: 23090 - [=>----------------------------]   5% - acc: 0.9844 - loss: 1.4764 - 7154.6 sample/sec Global step: 23100 - [==>---------------------------]   8% - acc: 0.9297 - loss: 1.5307 - 7104.4 sample/sec Global step: 23110 - [==>---------------------------]  10% - acc: 0.9141 - loss: 1.5462 - 7091.4 sample/sec Global step: 23120 - [===>--------------------------]  13% - acc: 0.9297 - loss: 1.5314 - 7162.9 sample/sec Global step: 23130 - [====>-------------------------]  15% - acc: 0.9297 - loss: 1.5307 - 7174.8 sample/sec Global step: 23140 - [=====>------------------------]  18% - acc: 0.9375 - loss: 1.5231 - 7140.0 sample/sec Global step: 23150 - [=====>------------------------]  20% - acc: 0.9297 - loss: 1.5301 - 7152.8 sample/sec Global step: 23160 - [======>-----------------------]  23% - acc: 0.9531 - loss: 1.5080 - 7112.3 sample/sec Global step: 23170 - [=======>----------------------]  26% - acc: 0.9609 - loss: 1.5000 - 7154.0 sample/sec Global step: 23180 - [========>---------------------]  28% - acc: 0.9531 - loss: 1.5074 - 6862.2 sample/sec Global step: 23190 - [========>---------------------]  31% - acc: 0.9609 - loss: 1.4993 - 7134.5 sample/sec Global step: 23200 - [=========>--------------------]  33% - acc: 0.9609 - loss: 1.4995 - 7166.0 sample/sec Global step: 23210 - [==========>-------------------]  36% - acc: 0.9375 - loss: 1.5231 - 7116.7 sample/sec Global step: 23220 - [===========>------------------]  38% - acc: 0.9453 - loss: 1.5153 - 7134.1 sample/sec Global step: 23230 - [===========>------------------]  41% - acc: 0.9375 - loss: 1.5233 - 7074.5 sample/sec Global step: 23240 - [============>-----------------]  43% - acc: 0.9219 - loss: 1.5387 - 7176.9 sample/sec Global step: 23250 - [=============>----------------]  46% - acc: 0.8828 - loss: 1.5769 - 7144.1 sample/sec Global step: 23260 - [==============>---------------]  49% - acc: 0.9219 - loss: 1.5383 - 7059.7 sample/sec Global step: 23270 - [==============>---------------]  51% - acc: 0.8984 - loss: 1.5618 - 6638.6 sample/sec Global step: 23280 - [===============>--------------]  54% - acc: 0.9453 - loss: 1.5151 - 7035.7 sample/sec Global step: 23290 - [================>-------------]  56% -acc: 0.9609 - loss: 1.4996 - 7129.0 sample/sec Global step: 23300 - [=================>------------]  59% - acc: 0.9609 - loss: 1.4997 - 7075.4 sample/sec Global step: 23310 - [=================>------------]  61% - acc: 0.8750 - loss: 1.5842 - 7117.8 sample/sec Global step: 23320 - [==================>-----------]  64% - acc: 0.9141 - loss: 1.5463 - 7157.2 sample/sec Global step: 23330 - [===================>----------]  66% - acc:0.9062 - loss: 1.5549 - 7169.3 sample/sec Global step: 23340 - [====================>---------]  69% - acc: 0.9219 - loss: 1.5389 - 7164.4 sample/sec Global step: 23350 - [====================>---------]  72% - acc: 0.9609 - loss: 1.5002 - 7135.4 sample/sec Global step: 23360 - [=====================>--------]  74% - acc: 0.9766 - loss: 1.4842 - 7124.2 sample/sec Global step: 23370 - [======================>-------]  77% - acc: 0.9375 - loss: 1.5231 - 7168.5 sample/sec Global step: 23380 - [======================>-------]  79% - acc: 0.8906 - loss: 1.5695 - 7175.2 sample/sec Global step: 23390 - [=======================>------]  82% - acc: 0.9375 - loss: 1.5225 - 7132.1 sample/sec Global step: 23400 - [========================>-----]  84% - acc: 0.9844 - loss: 1.4768 - 7100.1 sample/sec Global step: 23410 - [=========================>----]  87% - acc: 0.9766 - loss: 1.4840 - 7172.0 sample/sec Global step: 23420 - [==========================>---]  90% - acc: 0.9062 - loss: 1.5542 - 7122.1 sample/sec Global step: 23430 - [==========================>---]  92% - acc:0.9297 - loss: 1.5313 - 7145.3 sample/sec Global step: 23440 - [===========================>--]  95% - acc: 0.9297 - loss: 1.5301 - 7133.3 sample/sec Global step: 23450 - [============================>-]  97% - acc: 0.9375 - loss: 1.5231 - 7135.7 sample/sec Global step: 23460 - [=============================>] 100% - acc: 0.9250 - loss: 1.5362 - 10297.5 sample/sec   Epoch 60 - accuracy: 78.81% (7881/10000) This epoch receive better accuracy: 78.81 > 78.78. Saving session...

在测试数据集上运行网络

import numpy as np import tensorflow as tf from include.data import get_data_set from include.model import model test_x, test_y = get_data_set("test") x, y, output, y_pred_cls, global_step, learning_rate = model() _BATCH_SIZE = 128 _CLASS_SIZE = 10 _SAVE_PATH = "./tensorboard/cifar-10-v1.0.0/" saver = tf.train.Saver() sess = tf.Session() try:     print("\nTrying to restore last checkpoint ...")     last_chk_path = tf.train.latest_checkpoint(checkpoint_dir=_SAVE_PATH)     saver.restore(sess, save_path=last_chk_path)     print("Restored checkpoint from:", last_chk_path) except ValueError:     print("\nFailed to restore checkpoint. Initializing variables instead.")     sess.run(tf.global_variables_initializer()) def main():     i = 0     predicted_class = np.zeros(shape=len(test_x), dtype=np.int)     while i < len(test_x):         j = min(i + _BATCH_SIZE, len(test_x))         batch_xs = test_x[i:j, :]         batch_ys = test_y[i:j, :]         predicted_class[i:j] = sess.run(y_pred_cls, feed_dict={x: batch_xs, y: batch_ys})         i = j     correct = (np.argmax(test_y, axis=1) == predicted_class)      acc = correcan() * 100     correct_numbers = correct.sum()     print()     print("Accuracy on Test-Set: {0:.2f}% ({1} / {2})".format(acc, correct_numbers, len(test_x))) if __name__ == "__main__":     main() sess.close()

简单输出:

Trying to restore last checkpoint ... Restored checkpoint from: ./tensorboard/cifar-10-v1.0.0/-23460 Accuracy on Test-Set: 78.81% (7881 / 10000)

这难道不是一个非常有趣的用例吗?至此,我们了解了机器学习是如何工作的,开发了一个基本程序,并使用Python中的TensorFlow来实现了它。

原文标题:

Top Python Projects You Should Consider Learning

原文链接:

https://www.edureka.co/blog/python-projects/



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3