{"id":1221,"date":"2025-09-17T06:53:05","date_gmt":"2025-09-17T06:53:05","guid":{"rendered":"https:\/\/seateklab.vn\/?p=1221"},"modified":"2025-09-17T06:53:05","modified_gmt":"2025-09-17T06:53:05","slug":"tao-number-guessing-game-bang-python-project-nho-cho-nguoi-moi-hoc","status":"publish","type":"post","link":"https:\/\/seateklab.vn\/en\/2025\/09\/17\/tao-number-guessing-game-bang-python-project-nho-cho-nguoi-moi-hoc\/","title":{"rendered":"Create a Number Guessing Game with Python \u2013 A mini project for beginners"},"content":{"rendered":"<p class=\"wp-block-paragraph\">When starting to learn programming, completing a mini-project by yourself will help you master the syntax, practice logical thinking, and gain more motivation to keep going. In this article, I will build a very familiar game with you&nbsp;<strong>Number Guessing Game<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/5948164050022883944\/2341378034040265959?hl=vi#\"><img decoding=\"async\" src=\"https:\/\/blogger.googleusercontent.com\/img\/a\/AVvXsEi1fHMcZABYDL9aQdFxkA8XJYERRn0qduZkx7eGO9voslx7SUI6NU_wpbT5XYrpTayH7854aQ0aRl5sQSLg3wsMkWHARxih0oravAKXa9frxLQE1d_T18kTR1LOSrLm5VbubgqF7UvIwBh_YOegFC70oOY527Zie6L5_tAm1Fs3FOl1LXDbNeld14i4ZpF0\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Game idea<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">How it work<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The computer will randomly choose a number between\u00a0<strong>1 to 10<\/strong>.<\/li>\n\n\n\n<li>The player enters their guess.<\/li>\n\n\n\n<li>If the guess is wrong, the program will suggest:\n<ul class=\"wp-block-list\">\n<li>\u201cToo low\u201d if the guessed number is smaller than the answer.<\/li>\n\n\n\n<li>\u201cToo high\u201d if the guessed number is larger than the answer.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>When guessed correctly, the game will announce:\u00a0<strong>\u201cYou guessed it right!!\u201d<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">With this project, you will practice:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Import and using library\u00a0<code>random<\/code>\u00a0in Python<\/li>\n\n\n\n<li>D\u00f9ng\u00a0<strong>Using while loops.<\/strong>.<\/li>\n\n\n\n<li>Applying\u00a0<strong>if\/elif\/else statements<\/strong>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Game code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Below is the simplest version of the Number Guessing Game:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\n\n# M\u00e1y ch\u1ecdn ng\u1eabu nhi\u00ean m\u1ed9t s\u1ed1 trong kho\u1ea3ng 1 \u0111\u1ebfn 10\nn = random.randrange(1, 10)\n\n# Ng\u01b0\u1eddi ch\u01a1i nh\u1eadp s\u1ed1 d\u1ef1 \u0111o\u00e1n\nguess = int(input(\"Enter any number: \"))\n\n# L\u1eb7p cho \u0111\u1ebfn khi ng\u01b0\u1eddi ch\u01a1i \u0111o\u00e1n \u0111\u00fang\nwhile n != guess:\n    if guess &lt; n:\n        print(\"Too low\")\n    elif guess &gt; n:\n        print(\"Too high!\")\n    # Cho ng\u01b0\u1eddi ch\u01a1i nh\u1eadp l\u1ea1i\n    guess = int(input(\"Enter number again: \"))\n\nprint(\"You guessed it right!!\")\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When running the program, the screen will display as follows:\"<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter any number: 2\nToo low\nEnter number again: 5\nToo low\nEnter number again: 8\nYou guessed it right!!\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the example above:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ng\u01b0\u1eddi ch\u01a1i \u0111o\u00e1n\u00a0<strong>2<\/strong>, ch\u01b0\u01a1ng tr\u00ecnh b\u00e1o \u201cToo low\u201d.<\/li>\n\n\n\n<li>\u0110o\u00e1n ti\u1ebfp\u00a0<strong>5<\/strong>, v\u1eabn th\u1ea5p h\u01a1n \u0111\u00e1p \u00e1n \u2192 \u201cToo low\u201d.<\/li>\n\n\n\n<li>\u0110o\u00e1n\u00a0<strong>8<\/strong>, matches the random number chosen by the computer \u2192 the program prints: \u201cYou guessed it right!!\u201d<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Expand<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is just a basic version. You can upgrade this game with many more interesting features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Limit the number of guesses (e.g., only 5 guesses allowed).<\/li>\n\n\n\n<li>Allow players to choose their own number range (e.g., from 1 \u2192 100).<\/li>\n\n\n\n<li>Add a replay mode after guessing correctly or running out of turns.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Khi m\u1edbi b\u1eaft \u0111\u1ea7u h\u1ecdc l\u1eadp tr\u00ecnh, vi\u1ec7c t\u1ef1 tay ho\u00e0n th\u00e0nh m\u1ed9t mini project nh\u1ecf s\u1ebd gi\u00fap anh em n\u1eafm ch\u1eafc c\u00fa ph\u00e1p, luy\u1ec7n t\u01b0 duy logic v\u00e0 c\u00f3 th\u00eam \u0111\u1ed9ng l\u1ef1c \u0111\u1ec3 ti\u1ebfp t\u1ee5c. Trong b\u00e0i vi\u1ebft n\u00e0y, m\u00ecnh s\u1ebd c\u00f9ng anh em x\u00e2y d\u1ef1ng m\u1ed9t tr\u00f2 ch\u01a1i c\u1ef1c k\u1ef3 quen thu\u1ed9c:&nbsp;Number Guessing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1221","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/posts\/1221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/comments?post=1221"}],"version-history":[{"count":0,"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/posts\/1221\/revisions"}],"wp:attachment":[{"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/media?parent=1221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/categories?post=1221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seateklab.vn\/en\/wp-json\/wp\/v2\/tags?post=1221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}