{"id":21694,"date":"2022-01-27T10:25:00","date_gmt":"2022-01-27T09:25:00","guid":{"rendered":"https:\/\/firmbee.com\/?p=21694"},"modified":"2022-02-09T13:07:22","modified_gmt":"2022-02-09T12:07:22","slug":"python-applications","status":"publish","type":"post","link":"https:\/\/firmbee.com\/python-applications","title":{"rendered":"Python applications in practice. Part 11 Python Course from Beginner to Advanced in 11 blog posts"},"content":{"rendered":"<p><strong>In this article will help the reader use the learning from all the previous blogs to make a mini-project. You&#8217;ll discover <a href=\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\" target=\"_blank\" rel=\"noopener\">Python <\/a>applications in practice. We will be using Visual Studio Code as our code editor. If you have not installed Visual Studio Code, the instructions are given in the first blog.<\/strong><\/p>\r\n\r\n\r\n<h2>Python applications in practice &#8211; creating a guessing numbers game<\/h2>\r\n<p>This mini-project will be exciting to learn on how we can use functions and most of the other things which we learned in the previous blogs. This mini-project game generates a random number from 1 to 1000 or if you want it to be easy you can decrease the range and the user who is playing the game must guess the number. Sounds exciting, doesn&#8217;t it? What will make it more exciting is that we can give the user some cues if he guesses the number wrong so that they can guess the number correctly.<\/p>\r\n\r\n<h3>Let\u2019s make a blueprint for the game with Python applications in practice.<\/h3>\r\n\r\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/firmbee.com\/wp-content\/uploads\/Pythonn-800x1000.png\" alt=\"Python_applications\" width=\"800\" height=\"1000\" class=\"alignnone size-medium wp-image-21709 img-fluid\" title=\"\" srcset=\"https:\/\/firmbee.com\/wp-content\/uploads\/Pythonn-800x1000.png 800w, https:\/\/firmbee.com\/wp-content\/uploads\/Pythonn-900x1125.png 900w, https:\/\/firmbee.com\/wp-content\/uploads\/Pythonn.png 1200w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/>\r\n\r\n<h3>Intro command line<\/h3>\r\n\r\n<p>In the intro command line, we will ask the user to guess a number. We will ask his name and age. Then we will ask him if he wants to play the game or not. Let\u2019s do this in the code.<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n# Intro Panel Command line\r\n \r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nprint(f&quot;Hello {name}&quot;)\r\n<\/pre>\r\n\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nOutput:\r\nWelcome to the guessnum\r\nHello john\r\n<\/pre>\r\n\r\n<p>As can be seen we first introduced our game to the user and then we asked the user their name. we greeted them using the saved name. Now let\u2019s ask the user the age.<\/p>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\n \r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nprint(f&quot;Hello {name}&quot;)\r\n<\/pre>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nOutput:\r\nWelcome to the guessnum\r\nHello john\r\n<\/pre>\r\n\r\n<p>In here we are seeing fstring, this is alternative to format, if we write f followed by a string, we can use our stored variables inside the \u201c{}\u201d directly.<\/p>\r\n\r\n<p>Now we can see most of the intro panel. Now let\u2019s ask the user if he wants to play the game and if he wants to play the game, lets ask him to guess a number and we can say if its right or not. But before asking the user to guess the number, we must have the number of the program ready. Let\u2019s see how it is done in code.<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\n \r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nchoice=input(f&quot;Hello {name}, would you like to play the game? y\/n&quot;)\r\n \r\nif choice==&quot;y&quot;:\r\n    pass\r\nelse:\r\n    print(&quot;exiting&quot;)\r\n    exit\r\n \r\n<\/pre>\r\n\r\n<p>Now we are making another prompt which will ask the user, whether he wants to play the game, and we will be using the conditionals which we learned in the previous blogs to continue if he says yes and if it&#8217;s no, to exit the game. Now let\u2019s continue expanding our game and ask the user for the number, but before that let&#8217;s make our code select a random number.\r\n<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\nimport random\r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nchoice=input(f&quot;Hello {name}, would you like to play the game? y\/n&quot;)\r\n \r\nif choice==&quot;y&quot;:\r\n    number=int(random.randint(1,5))\r\n    guess=int(input(&quot;Please input your guess&quot;))\r\n    print(f&quot;your guess is {guess}&quot;)\r\nelse:\r\n    print(&quot;exiting&quot;)\r\n    exit\r\n \r\n \r\n<\/pre>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nOutput:\r\nWelcome to the guessnum\r\nyour guess is 2\r\n<\/pre>\r\n<p>Now we added an import known as random which selects a random number from a given range. The function is random.randint(start,end). Then we are asking our user to guess the number and we are printing our users guess.<\/p>\r\n\r\n<p>Let\u2019s also print our program\u2019s guess.<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\nimport random\r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nchoice=input(f&quot;Hello {name}, would you like to play the game? y\/n&quot;)\r\n \r\nif choice==&quot;y&quot;:\r\n    number=int(random.randint(1,5))\r\n    guess=int(input(&quot;Please input your guess&quot;))\r\n    print(f&quot;your guess is {guess} and program's guess is {number}&quot;)\r\nelse:\r\n    print(&quot;exiting&quot;)\r\n    exit\r\n \r\n \r\n\r\n<\/pre>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\noutput:\r\nWelcome to the guessnum\r\nyour guess is 2 and the program's guess is 5\r\n<\/pre>\r\n\r\n\r\n<p>So, we can see that we are almost halfway, we have the guess of the program and the guess of the user. Now we can just compare and print if the user is correct or not.<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\nimport random\r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nchoice=input(f&quot;Hello {name}, would you like to play the game? y\/n&quot;)\r\n \r\nif choice==&quot;y&quot;:\r\n    number=int(random.randint(1,5))\r\n    guess=int(input(&quot;Please input your guess&quot;))\r\n \r\n    if guess==number:\r\n        print(&quot;you guessed it right!!!&quot;)\r\n \r\n   \r\n \r\n    print(f&quot;your guess is {guess} and program's guess is {number}. Sorry!!! your guess is wrong&quot;)\r\n \r\nelse:\r\n    print(&quot;exiting&quot;)\r\n    exit\r\n \r\n \r\n<\/pre>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\noutput:\r\nWelcome to the guessnum\r\nyour guess is 2 and the program's guess is 1. Sorry!!! your guess is wrong\r\n<\/pre>\r\n<p>As you can see, I have guessed wrong maybe you can guess it right. This game can be made more interesting by adding the score factor. Now let\u2019s code for the score factor.<\/p>\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n# Intro Panel Command line\r\nimport random\r\nprint(&quot;Welcome to the guessnum&quot;)\r\n \r\nname=input(&quot;what is your name?&quot;)\r\nage=int(input(f&quot;Hello {name}, what is your age?&quot;))\r\nchoice=input(f&quot;Hello {name}, would you like to play the game? y\/n&quot;)\r\ncorrect=0\r\n \r\n \r\n   \r\n \r\nwhile(choice==&quot;y&quot;):\r\n    number=int(random.randint(1,5))\r\n    guess=int(input(&quot;Please input your guess&quot;))\r\n \r\n    if guess==number:\r\n        print(&quot;you guessed it right!!!&quot;)\r\n        correct+=1\r\n        choice=input(f&quot;Hello {name}, would you like to continue the game? y\/n&quot;)\r\n           \r\n \r\n   \r\n   \r\n \r\n    print(f&quot;your guess is {guess} and program's guess is {number}. Sorry!!! your guess is wrong&quot;)\r\n    choice=input(f&quot;Hello {name}, would you like to continue the game? y\/n&quot;)\r\n       \r\n \r\n \r\nelse:\r\n    print(f&quot;your score is {correct}&quot;)\r\n    print(&quot;exiting&quot;)\r\n    exit\r\n \r\n \r\n\r\n<\/pre>\r\n\r\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\noutput:\r\nWelcome to the guessnum\r\nyour guess is 1 and program's guess is 5.\r\nSorry!!! your guess is wrong your guess is 2 and program's guess is 3.\r\nSorry!!! your guess is wrong your guess is 3 and program's guess is 2.\r\nSorry!!! your guess is wrong your guess is 4 and program's guess is 3.\r\nSorry!!! your guess is wrong your guess is 1 and program's guess is 2.\r\nSorry!!! your guess is wrong your guess is 2 and program's guess is 5.\r\nSorry!!! your guess is wrong your guess is 3 and program's guess is 4.\r\nSorry!!! your guess is wrong your guess is 3 and program's guess is 2.\r\nSorry!!! your guess is wrong your guess is 3 and program's guess is 5.\r\nSorry!!! your guess is wrong your guess is 4 and program's guess is 2.\r\nSorry!!! your guess is wrong your guess is 3 and program's guess is 1.\r\nSorry!!! your guess is wrong your guess is 4 and program's guess is 5.\r\nSorry!!! your guess is wrong your guess is 2 and program's guess is 2.\r\nyou guessed it right!!!\r\nSorry!!! your guess is wrong your score is 1 exiting\r\n<\/pre>\r\n\r\n<p>As you can see, we utilized while loops and we used a new variable called correct, which is giving us the score of the user. Which we are printing to the output.<\/p>\r\n\r\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/firmbee.com\/wp-content\/uploads\/Python_applications-800x200.png\" alt=\"Python_applications\" width=\"800\" height=\"200\" class=\"alignnone size-medium wp-image-21704 img-fluid\" title=\"\" srcset=\"https:\/\/firmbee.com\/wp-content\/uploads\/Python_applications-800x200.png 800w, https:\/\/firmbee.com\/wp-content\/uploads\/Python_applications-900x225.png 900w, https:\/\/firmbee.com\/wp-content\/uploads\/Python_applications.png 1200w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/>\r\n\r\n<p><strong>You may also like our <a href=\"https:\/\/firmbee.com\/blog\/javascript-course\/\" target=\"_blank\" rel=\"noopener\">JavaScript Course from Beginner to Advanced.<\/strong><\/p><\/a>\r\n\r\n\r\nCongratulations! Now you know how to put Python applications in practice, and you officially finished the course: Python Course from Beginner to Advanced in 11 blog posts\r\n\r\n","protected":false},"excerpt":{"rendered":"In this article will help the reader use the learning from all the previous blogs to make a mini-project. You&#8217;ll discover Python applications in practice. [&hellip;]","protected":false},"author":8,"featured_media":21700,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[491,1],"tags":[],"class_list":["post-21694","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-course","category-other"],"acf":{"faq":null,"seria_wpisow":"Python Course From Beginner to Advanced in 11 blog posts","tytul_w_serii":"Python applications in practice. Part 11 Python Course from Beginner to Advanced in 11 blog posts","":"","naglowek_spisu_tresci":"","spis-tresci-lista":null},"_links":{"self":[{"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/posts\/21694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/comments?post=21694"}],"version-history":[{"count":12,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/posts\/21694\/revisions"}],"predecessor-version":[{"id":22629,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/posts\/21694\/revisions\/22629"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/media\/21700"}],"wp:attachment":[{"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/media?parent=21694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/categories?post=21694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/firmbee.com\/wp-json\/wp\/v2\/tags?post=21694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}