├── .gitignore ├── README.md ├── cla.md ├── finaledits.md ├── proceeds.md ├── readability ├── README-readability.txt ├── chapter1.readability.txt ├── chapter1.txt ├── chapter10.readability.txt ├── chapter10.txt ├── chapter11.readability.txt ├── chapter11.txt ├── chapter12.readability.txt ├── chapter12.txt ├── chapter13.readability.txt ├── chapter13.txt ├── chapter14.readability.txt ├── chapter14.txt ├── chapter15.readability.txt ├── chapter15.txt ├── chapter16.readability.txt ├── chapter16.txt ├── chapter17.readability.txt ├── chapter17.txt ├── chapter18.readability.txt ├── chapter18.txt ├── chapter19.readability.txt ├── chapter19.txt ├── chapter2.readability.txt ├── chapter2.txt ├── chapter20.readability.txt ├── chapter20.txt ├── chapter3.readability.txt ├── chapter3.txt ├── chapter4.readability.txt ├── chapter4.txt ├── chapter5.readability.txt ├── chapter5.txt ├── chapter6.readability.txt ├── chapter6.txt ├── chapter7.readability.txt ├── chapter7.txt ├── chapter8.readability.txt ├── chapter8.txt ├── chapter9.5.readability.txt ├── chapter9.5.txt ├── chapter9.readability.txt ├── chapter9.txt ├── combineAllTexts.py └── fullText.readability.txt ├── src ├── AISim1.py ├── AISim2.py ├── AISim3.py ├── _ISSUES.txt ├── animation.py ├── background.mid ├── baddie.png ├── bagels.py ├── buggy.py ├── bugs.py ├── cherry.png ├── cipher.py ├── coinFlips.py ├── collisionDetection.py ├── dodger.py ├── dodgerfullscreen.py ├── dragon.py ├── gameover.wav ├── guess.py ├── hangman.py ├── hangman2.py ├── hello.py ├── jokes.py ├── pickup.wav ├── player.png ├── pygameHelloWorld.py ├── pygameInput.py ├── reversi.py ├── reversi_mini.py ├── sonar.py ├── spritesAndSounds.py └── tictactoe.py ├── text ├── README.txt ├── c0.docx ├── c1.docx ├── c10.docx ├── c11.docx ├── c12.docx ├── c13.docx ├── c14.docx ├── c15.docx ├── c16.docx ├── c17.docx ├── c18.docx ├── c19.docx ├── c2.docx ├── c20.docx ├── c3.docx ├── c4.docx ├── c5.docx ├── c6.docx ├── c7.docx ├── c8.docx ├── c9.5.docx ├── c9.docx ├── chapter1.figures.txt ├── chapter1.txt ├── chapter10.figures.txt ├── chapter10.txt ├── chapter11.figures.txt ├── chapter11.txt ├── chapter12.figures.txt ├── chapter12.txt ├── chapter13.figures.txt ├── chapter13.txt ├── chapter14.figures.txt ├── chapter14.txt ├── chapter15.figures.txt ├── chapter15.txt ├── chapter16.figures.txt ├── chapter16.txt ├── chapter17.figures.txt ├── chapter17.txt ├── chapter18.figures.txt ├── chapter18.txt ├── chapter19.figures.txt ├── chapter19.txt ├── chapter2.figures.txt ├── chapter2.txt ├── chapter20.figures.txt ├── chapter20.txt ├── chapter3.figures.txt ├── chapter3.txt ├── chapter4.figures.txt ├── chapter4.txt ├── chapter5.figures.txt ├── chapter5.txt ├── chapter6.figures.txt ├── chapter6.txt ├── chapter7.figures.txt ├── chapter7.txt ├── chapter8.figures.txt ├── chapter8.txt ├── chapter9.5.figures.txt ├── chapter9.5.txt ├── chapter9.figures.txt └── chapter9.txt └── translations ├── README.md ├── SPECIAL_THANKS_TO.txt ├── _example └── chapter1.txt ├── af └── README.md ├── bn └── README.md ├── checkSourceCode.py ├── de ├── README.md ├── src │ ├── buggy.py │ ├── drachen.py │ ├── galgenmann.py │ ├── muenzwurf.py │ ├── tictactoe.py │ ├── witze.py │ └── zahlenRaten.py └── text │ ├── chapter1.figures.txt │ ├── chapter1.txt │ ├── chapter10.txt │ ├── chapter4.txt │ ├── chapter5.txt │ ├── chapter6.figures.txt │ ├── chapter6.txt │ ├── chapter7.figures.txt │ ├── chapter7.txt │ ├── chapter8.figures.txt │ ├── chapter8.txt │ └── chapter9.txt ├── es ├── README.md ├── glosario.txt ├── inventwithpython3rded_spanish.docx ├── src │ ├── AISim1.py │ ├── AISim2.py │ ├── AISim3.py │ ├── README.md │ ├── adivinaElNúmero.py │ ├── ahorcado.py │ ├── ahorcado2.py │ ├── animación.py │ ├── bugs.py │ ├── cereza.png │ ├── chistes.py │ ├── cifrado.py │ ├── detecciónColisión.py │ ├── dragón.py │ ├── evasor.py │ ├── evasorPantallaCompleta.py │ ├── gorila.py │ ├── hola.py │ ├── juegoterminado.wav │ ├── jugador.png │ ├── lanzarMoneda.py │ ├── musicaDeFondo.mid │ ├── panecillos.py │ ├── pygameEntrada.py │ ├── pygameHolaMundo.py │ ├── recolección.wav │ ├── reversi.py │ ├── reversi_mini.py │ ├── sonar.py │ ├── spritesYsonidos.py │ ├── tateti.py │ └── villano.png └── text │ ├── capítulo1.figuras.txt │ ├── capítulo1.txt │ ├── capítulo10.figuras.txt │ ├── capítulo10.txt │ ├── capítulo11.figuras.txt │ ├── capítulo11.txt │ ├── capítulo12.figuras.txt │ ├── capítulo12.txt │ ├── capítulo13.txt │ ├── capítulo14.figuras.txt │ ├── capítulo14.txt │ ├── capítulo15.figuras.txt │ ├── capítulo15.txt │ ├── capítulo16.figuras.txt │ ├── capítulo16.txt │ ├── capítulo17.figuras.txt │ ├── capítulo17.txt │ ├── capítulo18.figuras.txt │ ├── capítulo18.txt │ ├── capítulo19.figuras.txt │ ├── capítulo19.txt │ ├── capítulo2.figuras.txt │ ├── capítulo2.txt │ ├── capítulo20.figuras.txt │ ├── capítulo20.txt │ ├── capítulo3.figuras.txt │ ├── capítulo3.txt │ ├── capítulo4.figuras.txt │ ├── capítulo4.txt │ ├── capítulo5.figuras.txt │ ├── capítulo5.txt │ ├── capítulo6.figuras.txt │ ├── capítulo6.txt │ ├── capítulo7.figuras.txt │ ├── capítulo7.txt │ ├── capítulo8.figuras.txt │ ├── capítulo8.txt │ ├── capítulo9.5.figuras.txt │ ├── capítulo9.5.txt │ ├── capítulo9.figures.txt │ └── capítulo9.txt ├── fi └── README.md ├── fr ├── README.md ├── fr_chapter1.txt ├── fr_chapter2.txt ├── fr_chapter3.txt ├── fr_chapter4.txt ├── fr_chapter7.txt ├── fr_figures.txt └── src │ ├── PileFace.py │ ├── bogue.py │ ├── bonjour.py │ └── devine.py ├── hr └── README.md ├── id ├── README.md ├── src │ ├── animasi.py │ ├── deteksiTumbukan.py │ ├── halo.py │ ├── hangman.py │ ├── hangman2.py │ ├── lemparKoin.py │ ├── naga.py │ ├── ngebug.py │ ├── pygameHaloDunia.py │ ├── pygameMasukan.py │ ├── sandi.py │ └── tebak.py └── text │ ├── chapter1.figures.txt │ ├── chapter1.txt │ ├── chapter14.figures.txt │ ├── chapter14.txt │ ├── chapter17.figures.txt │ ├── chapter17.txt │ ├── chapter18.figures.txt │ ├── chapter18.txt │ ├── chapter2.figures.txt │ ├── chapter2.txt │ ├── chapter3.figures.txt │ ├── chapter3.txt │ ├── chapter4.figures.txt │ ├── chapter4.txt │ ├── chapter5.figures.txt │ ├── chapter5.txt │ ├── chapter6.figures.txt │ ├── chapter6.txt │ ├── chapter7.figures.txt │ ├── chapter7.txt │ ├── chapter8.figures.txt │ ├── chapter8.txt │ ├── chapter9.5.figures.txt │ ├── chapter9.5.txt │ ├── chapter9.figures.txt │ └── chapter9.txt ├── it └── README.md ├── kar └── README.md ├── ml └── README.md ├── nl └── README.md ├── pl ├── README.md ├── glossary.txt ├── src │ ├── buggy.py │ ├── coinFlips.py │ ├── dragon.py │ ├── guess.py │ ├── hello.py │ └── jokes.py └── txt │ ├── README.txt │ ├── chapter1.figures.txt │ ├── chapter1.txt │ ├── chapter2.figures.txt │ ├── chapter2.txt │ ├── chapter3.figures.txt │ ├── chapter3.txt │ ├── chapter4.figures.txt │ ├── chapter4.txt │ ├── chapter5.figures.txt │ ├── chapter5.txt │ ├── chapter6.figures.txt │ ├── chapter6.txt │ ├── chapter7.figures.txt │ └── chapter7.txt ├── pt-br ├── README.md ├── chap 1 ├── chap 12 ├── chap-13 │ ├── exemplo 01.txt │ └── fullSourceCode.txt └── chap13 │ └── chap 13 ├── pt └── README.md ├── ru └── README.md ├── sq └── README.md ├── sr └── README.md ├── sv ├── README.md ├── src │ ├── AISim1.py │ ├── AISim2.py │ ├── AISim3.py │ ├── animering.py │ ├── background.mid │ ├── baddie.png │ ├── bagels.py │ ├── bilderOchLjud.py │ ├── buggar.py │ ├── buggig.py │ ├── cherry.png │ ├── chiffer.py │ ├── drakriket.py │ ├── ekolod.py │ ├── gameover.wav │ ├── gissa.py │ ├── hangman.py │ ├── hangman2.py │ ├── hejsan.py │ ├── kollisionsdetektering.py │ ├── luffarschack.py │ ├── pickup.wav │ ├── player.png │ ├── pygamehejsan.py │ ├── pygameinmatning.py │ ├── reversi.py │ ├── reversi_mini.py │ ├── slantsingling.py │ ├── smitaren.py │ ├── smitarenfullscreen.py │ └── vitsar.py ├── sv_chapter1.figures.txt ├── sv_chapter1.txt ├── sv_chapter2.txt ├── sv_chapter3.txt ├── sv_chapter4.figures.txt ├── sv_chapter4.txt ├── sv_chapter5.txt ├── sv_chapter6.figures.txt ├── sv_chapter6.txt └── sv_chapter7.txt └── zh-cn ├── README.md ├── chapter1.figures.txt ├── chapter1.txt ├── chapter2.figures.txt ├── chapter2.txt ├── chapter3.figures.txt ├── chapter3.txt ├── chapter4.figures.txt ├── chapter4.txt └── src ├── AISim1.py ├── AISim2.py └── AISim3.py /.gitignore: -------------------------------------------------------------------------------- 1 | /readability/fullText.txt 2 | -------------------------------------------------------------------------------- /cla.md: -------------------------------------------------------------------------------- 1 | "Invent with Python" - Contributor License Agreement ("Agreement") 2 | ================================================================== 3 | 4 | Thank you for your interest in the "Invent with Python" project being administered by Al Sweigart. The form of license below is a document that clarifies the terms under which You, the person listed below, may contribute software, bug fixes, configuration changes, documentation, or any other materials that you send to us related to the Project (each a "Contribution") to the project. We appreciate your participation in our project, and your help in improving the project, so we want you to understand what will be done with the Contributions. This license is for your protection as well as the protection of Al Sweigart and its licensees; it does not change your rights to use your own Contributions for any other purpose. Please complete the following information about you and the Contributions and sign electronically by filling out the form below. 5 | 6 | If you have questions about these terms, please contact us at al@inventwithpython.com. 7 | 8 | Corporate Contributions: 9 | 10 | If you are employed as a software engineer, or if your employer is in the business of developing software, or otherwise may claim rights in the Contributions, please provide information about your employer's policy on contributing to open source projects, including the name of the supervisor to contact in connection with such contributions. 11 | 12 | **You and Al Sweigart agree:** 13 | 14 | You grant us the ability to use the Contributions in any way. You hereby grant to Al Sweigart, a non-exclusive, irrevocable, worldwide, royalty-free, sublicenseable, transferable license under all of Your relevant intellectual property rights (including copyright, patent, and any other rights), to use, copy, prepare derivative works of, distribute and publicly perform and display the Contributions on any licensing terms, including without limitation: (a) open source licenses like the GNU General Public License (GPL), the GNU Lesser General Public License (LGPL), the Common Public License, the Creative Commons license, or the Berkeley Software Distribution license (BSD); and (b) binary, proprietary, or commercial licenses. Except for the licenses granted herein, You reserve all right, title, and interest in and to the Contribution. 15 | 16 | You are able to grant us these rights. You represent that You are legally entitled to grant the above license. If Your employer has rights to intellectual property that You create, You represent that You have received permission to make the Contributions on behalf of that employer, or that Your employer has waived such rights for the Contributions. 17 | 18 | The Contributions are your original work. You represent that the Contributions are Your original works of authorship, and to Your knowledge, no other person claims, or has the right to claim, any right in any invention or patent related to the Contributions. You also represent that You are not legally obligated, whether by entering into an agreement or otherwise, in any way that conflicts with the terms of this license. For example, if you have signed an agreement requiring you to assign the intellectual property rights in the Contributions to an employer or customer, that would conflict with the terms of this license. 19 | 20 | We determine the code that is in our project. You understand that the decision to include the Contribution in any project or source repository is entirely that of Al Sweigart, and this agreement does not guarantee that the Contributions will be included in any product. 21 | 22 | No Implied Warranties. Al Sweigart acknowledges that, except as explicitly described in this Agreement, the Contribution is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. -------------------------------------------------------------------------------- /finaledits.md: -------------------------------------------------------------------------------- 1 | This document links to the diffs for the final drafts edits. 2 | 3 | [Chapter 1](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-501f9c94dd5fd242799ec0ed82b6a5a8) 4 | 5 | [Chapter 2](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-3de11238dc3ef163db2c8aac76620a37) 6 | 7 | [Chapter 3](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-559791e68e8fe1c1470682b427e72178) 8 | 9 | [Chapter 4](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-593b44178c85271c56dba21dc390bea2) 10 | 11 | [Chapter 5](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-c9cf455290f0acefbf9d24ff9b232e04) 12 | 13 | [Chapter 6](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-ac1ab0e2ff82f6527d18437f69ffda97) 14 | 15 | [Chapter 7](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-ebbed3dccebebd7670a9a04d229d2f3e) 16 | 17 | [Chapter 8](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-681eec4cf35fa66bb5a26220cb9964cf) 18 | 19 | [Chapter 9](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-abf9c4227fde0f2e36296bafe58f6726) 20 | 21 | [Chapter 9.5](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-772f9a7001afec51f42d9d64fb0109ad) 22 | 23 | [Chapter 10](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-8294b469c5c30b406924c21c38048766) 24 | 25 | [Chapter 11](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-c5757fb9fecfac775c18e5a8b09d32d2) 26 | 27 | [Chapter 12](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-29956095216af7595a7db6cb843b0d04) 28 | 29 | [Chapter 13](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-c8988add955b7701453dddbc5a5b4dbf) 30 | 31 | [Chapter 14](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-8ecfabb571e3d87aba1c7c6db88333f4) 32 | 33 | [Chapter 15](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-eb380fdb316bb5eea2b8c39132ec1c30) 34 | 35 | [Chapter 16](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-f2177c745219475cb45c8a20867e8c3e) 36 | 37 | [Chapter 17](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-7ee6eda0462046f422e53486b14dc316) 38 | 39 | [Chapter 18](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-ee9975f50ff0316ec051068fb2d13ac6) 40 | 41 | [Chapter 19](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-cfdaedcdbac86043972b91aace1d90d2) 42 | 43 | [Chapter 20](https://github.com/asweigart/inventwithpython3rded/commit/383b95119ae77dbde4c184eecd022242aac83149#diff-f523193fd5f6ea1888e5b25552974d83) 44 | 45 | -------------------------------------------------------------------------------- /proceeds.md: -------------------------------------------------------------------------------- 1 | Translated versions of "Invent Your Own Computer Games with Python, 3rd Edition" are free to download under a Creative Commons BY-NC-SA license. However, hard copies of the translated books are sold. All proceeds from these sales are donated to the Python Software Foundation. The PSF is a 501(c)(3) non-profit that manages the intellectual property rights behind the Python programming language. Al Sweigart, the original author, does not keep any this money for himself. Your translation efforts help bring programming knowledge to the global community. 2 | 3 | This document tracks the proceeds of the translated book sales. (Al Sweigart maintains a similar document at http://inventwithpython.com/hacking/proceeds/ for his book, Hacking Secret Ciphers with Python. All proceeds are donated to the EFF, Creative Commons, and Tor Project.) 4 | 5 | Any questions can be sent to al@inventwithpython.com. 6 | 7 | | Date | Selling Period | # Copies Sold | Language | Each Currency | Total | 8 | |------|----------------|---------------|----------|---------------|-------| 9 | | | | | | | | 10 | | | | | | | | 11 | | | | | | | | 12 | -------------------------------------------------------------------------------- /readability/README-readability.txt: -------------------------------------------------------------------------------- 1 | Do not modify the text files in this folder by hand. These are only updated by copy-pasting the text from the Word doc, then going through and removing the code and heading lines. Be sure there is a blank line separating each paragraph. 2 | 3 | To get the readability scores, run the Python "readability" module (pip install readability) to generate the output which goes in the *.readability.txt files. 4 | 5 | The goal is to get the wording down as close as possible to a Kincaid grade level of 8.0 and a Flesch score of 70.0. -------------------------------------------------------------------------------- /readability/chapter1.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.47 3 | ARI: 10.02 4 | Coleman-Liau: 10.56 5 | FleschReadingEase: 73.63 6 | GunningFogIndex: 11.03 7 | LIX: 38.06 8 | SMOGIndex: 10.19 9 | RIX: 3.61 10 | sentence info: 11 | characters_per_word: 4.76 12 | syll_per_word: 1.36 13 | words_per_sentence: 18.03 14 | sentences_per_paragraph: 1.95 15 | characters: 6182 16 | syllables: 1763 17 | words: 1298 18 | sentences: 72 19 | paragraphs: 37 20 | long_words: 260 21 | complex_words: 124 22 | word usage: 23 | tobeverb: 42 24 | auxverb: 26 25 | conjunction: 38 26 | pronoun: 127 27 | preposition: 164 28 | nominalization: 8 29 | sentence beginnings: 30 | pronoun: 7 31 | interrogative: 3 32 | article: 4 33 | subordination: 0 34 | conjunction: 0 35 | preposition: 5 36 | -------------------------------------------------------------------------------- /readability/chapter10.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.13 3 | ARI: 10.05 4 | Coleman-Liau: 8.89 5 | FleschReadingEase: 81.67 6 | GunningFogIndex: 12.08 7 | LIX: 38.25 8 | SMOGIndex: 10.58 9 | RIX: 3.62 10 | sentence info: 11 | characters_per_word: 4.44 12 | syll_per_word: 1.23 13 | words_per_sentence: 21.16 14 | sentences_per_paragraph: 1.98 15 | characters: 23659 16 | syllables: 6536 17 | words: 5333 18 | sentences: 252 19 | paragraphs: 127 20 | long_words: 911 21 | complex_words: 482 22 | word usage: 23 | tobeverb: 215 24 | auxverb: 125 25 | conjunction: 158 26 | pronoun: 318 27 | preposition: 629 28 | nominalization: 123 29 | sentence beginnings: 30 | pronoun: 17 31 | interrogative: 1 32 | article: 32 33 | subordination: 17 34 | conjunction: 7 35 | preposition: 12 36 | -------------------------------------------------------------------------------- /readability/chapter11.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.96 3 | ARI: 10.81 4 | Coleman-Liau: 9.63 5 | FleschReadingEase: 76.36 6 | GunningFogIndex: 12.75 7 | LIX: 40.26 8 | SMOGIndex: 11.17 9 | RIX: 4.03 10 | sentence info: 11 | characters_per_word: 4.56 12 | syll_per_word: 1.28 13 | words_per_sentence: 21.53 14 | sentences_per_paragraph: 1.97 15 | characters: 12174 16 | syllables: 3428 17 | words: 2670 18 | sentences: 124 19 | paragraphs: 63 20 | long_words: 500 21 | complex_words: 276 22 | word usage: 23 | tobeverb: 101 24 | auxverb: 55 25 | conjunction: 70 26 | pronoun: 177 27 | preposition: 337 28 | nominalization: 61 29 | sentence beginnings: 30 | pronoun: 5 31 | interrogative: 0 32 | article: 18 33 | subordination: 10 34 | conjunction: 0 35 | preposition: 6 36 | -------------------------------------------------------------------------------- /readability/chapter12.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.43 3 | ARI: 10.06 4 | Coleman-Liau: 8.76 5 | FleschReadingEase: 79.95 6 | GunningFogIndex: 12.45 7 | LIX: 41.48 8 | SMOGIndex: 10.9 9 | RIX: 4.3 10 | sentence info: 11 | characters_per_word: 4.41 12 | syll_per_word: 1.24 13 | words_per_sentence: 21.41 14 | sentences_per_paragraph: 1.95 15 | characters: 6990 16 | syllables: 1969 17 | words: 1584 18 | sentences: 74 19 | paragraphs: 38 20 | long_words: 318 21 | complex_words: 154 22 | word usage: 23 | tobeverb: 73 24 | auxverb: 37 25 | conjunction: 61 26 | pronoun: 114 27 | preposition: 195 28 | nominalization: 29 29 | sentence beginnings: 30 | pronoun: 9 31 | interrogative: 2 32 | article: 8 33 | subordination: 3 34 | conjunction: 0 35 | preposition: 2 36 | -------------------------------------------------------------------------------- /readability/chapter13.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.21 3 | ARI: 10.25 4 | Coleman-Liau: 9.74 5 | FleschReadingEase: 79.09 6 | GunningFogIndex: 12.42 7 | LIX: 40.68 8 | SMOGIndex: 11.13 9 | RIX: 4.14 10 | sentence info: 11 | characters_per_word: 4.59 12 | syll_per_word: 1.27 13 | words_per_sentence: 20.07 14 | sentences_per_paragraph: 1.98 15 | characters: 18999 16 | syllables: 5248 17 | words: 4135 18 | sentences: 206 19 | paragraphs: 104 20 | long_words: 852 21 | complex_words: 454 22 | word usage: 23 | tobeverb: 149 24 | auxverb: 82 25 | conjunction: 116 26 | pronoun: 216 27 | preposition: 530 28 | nominalization: 107 29 | sentence beginnings: 30 | pronoun: 7 31 | interrogative: 2 32 | article: 23 33 | subordination: 13 34 | conjunction: 3 35 | preposition: 9 36 | -------------------------------------------------------------------------------- /readability/chapter14.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 6.55 3 | ARI: 9.37 4 | Coleman-Liau: 10.08 5 | FleschReadingEase: 79.11 6 | GunningFogIndex: 11.3 7 | LIX: 40.11 8 | SMOGIndex: 10.52 9 | RIX: 3.95 10 | sentence info: 11 | characters_per_word: 4.69 12 | syll_per_word: 1.3 13 | words_per_sentence: 17.42 14 | sentences_per_paragraph: 1.95 15 | characters: 12255 16 | syllables: 3399 17 | words: 2613 18 | sentences: 150 19 | paragraphs: 77 20 | long_words: 593 21 | complex_words: 283 22 | word usage: 23 | tobeverb: 114 24 | auxverb: 61 25 | conjunction: 83 26 | pronoun: 176 27 | preposition: 290 28 | nominalization: 42 29 | sentence beginnings: 30 | pronoun: 6 31 | interrogative: 2 32 | article: 23 33 | subordination: 6 34 | conjunction: 2 35 | preposition: 8 36 | -------------------------------------------------------------------------------- /readability/chapter15.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.54 3 | ARI: 10.58 4 | Coleman-Liau: 9.27 5 | FleschReadingEase: 79.65 6 | GunningFogIndex: 12.22 7 | LIX: 39.22 8 | SMOGIndex: 10.6 9 | RIX: 3.8 10 | sentence info: 11 | characters_per_word: 4.5 12 | syll_per_word: 1.24 13 | words_per_sentence: 21.68 14 | sentences_per_paragraph: 1.98 15 | characters: 25731 16 | syllables: 7116 17 | words: 5724 18 | sentences: 264 19 | paragraphs: 133 20 | long_words: 1004 21 | complex_words: 508 22 | word usage: 23 | tobeverb: 219 24 | auxverb: 132 25 | conjunction: 180 26 | pronoun: 345 27 | preposition: 778 28 | nominalization: 118 29 | sentence beginnings: 30 | pronoun: 7 31 | interrogative: 4 32 | article: 35 33 | subordination: 23 34 | conjunction: 2 35 | preposition: 15 36 | -------------------------------------------------------------------------------- /readability/chapter16.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.82 3 | ARI: 10.51 4 | Coleman-Liau: 9.64 5 | FleschReadingEase: 76.16 6 | GunningFogIndex: 12.03 7 | LIX: 40.15 8 | SMOGIndex: 10.59 9 | RIX: 4.02 10 | sentence info: 11 | characters_per_word: 4.57 12 | syll_per_word: 1.29 13 | words_per_sentence: 20.85 14 | sentences_per_paragraph: 1.97 15 | characters: 12191 16 | syllables: 3455 17 | words: 2669 18 | sentences: 128 19 | paragraphs: 65 20 | long_words: 515 21 | complex_words: 246 22 | word usage: 23 | tobeverb: 69 24 | auxverb: 64 25 | conjunction: 75 26 | pronoun: 196 27 | preposition: 363 28 | nominalization: 29 29 | sentence beginnings: 30 | pronoun: 9 31 | interrogative: 5 32 | article: 11 33 | subordination: 5 34 | conjunction: 1 35 | preposition: 4 36 | -------------------------------------------------------------------------------- /readability/chapter17.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.27 3 | ARI: 10.08 4 | Coleman-Liau: 10.02 5 | FleschReadingEase: 77.13 6 | GunningFogIndex: 11.5 7 | LIX: 39.28 8 | SMOGIndex: 10.42 9 | RIX: 3.86 10 | sentence info: 11 | characters_per_word: 4.65 12 | syll_per_word: 1.3 13 | words_per_sentence: 19.18 14 | sentences_per_paragraph: 1.99 15 | characters: 24815 16 | syllables: 6949 17 | words: 5333 18 | sentences: 278 19 | paragraphs: 140 20 | long_words: 1072 21 | complex_words: 510 22 | word usage: 23 | tobeverb: 188 24 | auxverb: 113 25 | conjunction: 151 26 | pronoun: 354 27 | preposition: 704 28 | nominalization: 85 29 | sentence beginnings: 30 | pronoun: 18 31 | interrogative: 2 32 | article: 32 33 | subordination: 9 34 | conjunction: 2 35 | preposition: 19 36 | -------------------------------------------------------------------------------- /readability/chapter18.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.67 3 | ARI: 10.76 4 | Coleman-Liau: 10.15 5 | FleschReadingEase: 76.56 6 | GunningFogIndex: 12.5 7 | LIX: 41.42 8 | SMOGIndex: 11.13 9 | RIX: 4.29 10 | sentence info: 11 | characters_per_word: 4.66 12 | syll_per_word: 1.29 13 | words_per_sentence: 20.49 14 | sentences_per_paragraph: 1.97 15 | characters: 14508 16 | syllables: 4030 17 | words: 3114 18 | sentences: 152 19 | paragraphs: 77 20 | long_words: 652 21 | complex_words: 335 22 | word usage: 23 | tobeverb: 121 24 | auxverb: 65 25 | conjunction: 84 26 | pronoun: 176 27 | preposition: 407 28 | nominalization: 73 29 | sentence beginnings: 30 | pronoun: 8 31 | interrogative: 2 32 | article: 16 33 | subordination: 8 34 | conjunction: 1 35 | preposition: 14 36 | -------------------------------------------------------------------------------- /readability/chapter19.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 9.61 3 | ARI: 13.27 4 | Coleman-Liau: 11.07 5 | FleschReadingEase: 69.68 6 | GunningFogIndex: 13.14 7 | LIX: 44.48 8 | SMOGIndex: 10.86 9 | RIX: 4.9 10 | sentence info: 11 | characters_per_word: 4.78 12 | syll_per_word: 1.33 13 | words_per_sentence: 24.41 14 | sentences_per_paragraph: 1.94 15 | characters: 8163 16 | syllables: 2270 17 | words: 1709 18 | sentences: 70 19 | paragraphs: 36 20 | long_words: 343 21 | complex_words: 144 22 | word usage: 23 | tobeverb: 50 24 | auxverb: 44 25 | conjunction: 55 26 | pronoun: 120 27 | preposition: 204 28 | nominalization: 20 29 | sentence beginnings: 30 | pronoun: 5 31 | interrogative: 2 32 | article: 10 33 | subordination: 3 34 | conjunction: 0 35 | preposition: 5 36 | -------------------------------------------------------------------------------- /readability/chapter2.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.37 3 | ARI: 9.22 4 | Coleman-Liau: 10.25 5 | FleschReadingEase: 72.05 6 | GunningFogIndex: 12.63 7 | LIX: 39.09 8 | SMOGIndex: 11.63 9 | RIX: 3.74 10 | sentence info: 11 | characters_per_word: 4.73 12 | syll_per_word: 1.39 13 | words_per_sentence: 16.74 14 | sentences_per_paragraph: 1.98 15 | characters: 6415 16 | syllables: 1888 17 | words: 1356 18 | sentences: 81 19 | paragraphs: 41 20 | long_words: 303 21 | complex_words: 201 22 | word usage: 23 | tobeverb: 40 24 | auxverb: 37 25 | conjunction: 38 26 | pronoun: 86 27 | preposition: 162 28 | nominalization: 22 29 | sentence beginnings: 30 | pronoun: 9 31 | interrogative: 4 32 | article: 9 33 | subordination: 3 34 | conjunction: 0 35 | preposition: 5 36 | -------------------------------------------------------------------------------- /readability/chapter20.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.98 3 | ARI: 11.72 4 | Coleman-Liau: 10.89 5 | FleschReadingEase: 75.79 6 | GunningFogIndex: 12.31 7 | LIX: 42.54 8 | SMOGIndex: 10.78 9 | RIX: 4.52 10 | sentence info: 11 | characters_per_word: 4.78 12 | syll_per_word: 1.29 13 | words_per_sentence: 21.31 14 | sentences_per_paragraph: 1.98 15 | characters: 26459 16 | syllables: 7165 17 | words: 5540 18 | sentences: 260 19 | paragraphs: 131 20 | long_words: 1176 21 | complex_words: 525 22 | word usage: 23 | tobeverb: 185 24 | auxverb: 114 25 | conjunction: 157 26 | pronoun: 260 27 | preposition: 684 28 | nominalization: 98 29 | sentence beginnings: 30 | pronoun: 6 31 | interrogative: 4 32 | article: 33 33 | subordination: 20 34 | conjunction: 3 35 | preposition: 8 36 | -------------------------------------------------------------------------------- /readability/chapter3.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 8.18 3 | ARI: 11.18 4 | Coleman-Liau: 10.87 5 | FleschReadingEase: 72.31 6 | GunningFogIndex: 12.16 7 | LIX: 42.29 8 | SMOGIndex: 10.88 9 | RIX: 4.46 10 | sentence info: 11 | characters_per_word: 4.79 12 | syll_per_word: 1.35 13 | words_per_sentence: 20.14 14 | sentences_per_paragraph: 1.96 15 | characters: 9831 16 | syllables: 2770 17 | words: 2054 18 | sentences: 102 19 | paragraphs: 52 20 | long_words: 455 21 | complex_words: 211 22 | word usage: 23 | tobeverb: 75 24 | auxverb: 45 25 | conjunction: 47 26 | pronoun: 180 27 | preposition: 229 28 | nominalization: 49 29 | sentence beginnings: 30 | pronoun: 9 31 | interrogative: 3 32 | article: 10 33 | subordination: 3 34 | conjunction: 0 35 | preposition: 5 36 | -------------------------------------------------------------------------------- /readability/chapter4.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 8.2 3 | ARI: 11.15 4 | Coleman-Liau: 10.48 5 | FleschReadingEase: 73.29 6 | GunningFogIndex: 13.32 7 | LIX: 42.53 8 | SMOGIndex: 11.84 9 | RIX: 4.52 10 | sentence info: 11 | characters_per_word: 4.71 12 | syll_per_word: 1.33 13 | words_per_sentence: 20.78 14 | sentences_per_paragraph: 1.98 15 | characters: 19187 16 | syllables: 5413 17 | words: 4072 18 | sentences: 196 19 | paragraphs: 99 20 | long_words: 886 21 | complex_words: 510 22 | word usage: 23 | tobeverb: 136 24 | auxverb: 68 25 | conjunction: 106 26 | pronoun: 231 27 | preposition: 474 28 | nominalization: 153 29 | sentence beginnings: 30 | pronoun: 8 31 | interrogative: 0 32 | article: 20 33 | subordination: 6 34 | conjunction: 2 35 | preposition: 12 36 | -------------------------------------------------------------------------------- /readability/chapter5.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 5.6 3 | ARI: 8.31 4 | Coleman-Liau: 8.9 5 | FleschReadingEase: 85.42 6 | GunningFogIndex: 9.77 7 | LIX: 36.27 8 | SMOGIndex: 9.11 9 | RIX: 3.28 10 | sentence info: 11 | characters_per_word: 4.49 12 | syll_per_word: 1.23 13 | words_per_sentence: 17.15 14 | sentences_per_paragraph: 1.97 15 | characters: 4701 16 | syllables: 1286 17 | words: 1046 18 | sentences: 61 19 | paragraphs: 31 20 | long_words: 200 21 | complex_words: 76 22 | word usage: 23 | tobeverb: 36 24 | auxverb: 30 25 | conjunction: 20 26 | pronoun: 87 27 | preposition: 139 28 | nominalization: 14 29 | sentence beginnings: 30 | pronoun: 9 31 | interrogative: 1 32 | article: 5 33 | subordination: 1 34 | conjunction: 1 35 | preposition: 5 36 | -------------------------------------------------------------------------------- /readability/chapter6.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.78 3 | ARI: 10.29 4 | Coleman-Liau: 10.31 5 | FleschReadingEase: 73.4 6 | GunningFogIndex: 11.86 7 | LIX: 40.76 8 | SMOGIndex: 10.77 9 | RIX: 4.14 10 | sentence info: 11 | characters_per_word: 4.7 12 | syll_per_word: 1.35 13 | words_per_sentence: 19.14 14 | sentences_per_paragraph: 1.97 15 | characters: 15573 16 | syllables: 4462 17 | words: 3311 18 | sentences: 173 19 | paragraphs: 88 20 | long_words: 716 21 | complex_words: 348 22 | word usage: 23 | tobeverb: 128 24 | auxverb: 78 25 | conjunction: 102 26 | pronoun: 224 27 | preposition: 362 28 | nominalization: 142 29 | sentence beginnings: 30 | pronoun: 10 31 | interrogative: 7 32 | article: 11 33 | subordination: 8 34 | conjunction: 3 35 | preposition: 8 36 | -------------------------------------------------------------------------------- /readability/chapter7.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.99 3 | ARI: 10.78 4 | Coleman-Liau: 9.62 5 | FleschReadingEase: 76.02 6 | GunningFogIndex: 11.94 7 | LIX: 41.56 8 | SMOGIndex: 10.34 9 | RIX: 4.31 10 | sentence info: 11 | characters_per_word: 4.56 12 | syll_per_word: 1.29 13 | words_per_sentence: 21.49 14 | sentences_per_paragraph: 1.95 15 | characters: 15275 16 | syllables: 4319 17 | words: 3352 18 | sentences: 156 19 | paragraphs: 80 20 | long_words: 673 21 | complex_words: 280 22 | word usage: 23 | tobeverb: 126 24 | auxverb: 105 25 | conjunction: 65 26 | pronoun: 241 27 | preposition: 417 28 | nominalization: 61 29 | sentence beginnings: 30 | pronoun: 7 31 | interrogative: 4 32 | article: 12 33 | subordination: 8 34 | conjunction: 0 35 | preposition: 6 36 | -------------------------------------------------------------------------------- /readability/chapter8.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.47 3 | ARI: 10.6 4 | Coleman-Liau: 7.91 5 | FleschReadingEase: 84.46 6 | GunningFogIndex: 11.13 7 | LIX: 36.72 8 | SMOGIndex: 8.18 9 | RIX: 3.04 10 | sentence info: 11 | characters_per_word: 4.24 12 | syll_per_word: 1.16 13 | words_per_sentence: 24.1 14 | sentences_per_paragraph: 1.92 15 | characters: 4907 16 | syllables: 1339 17 | words: 1157 18 | sentences: 48 19 | paragraphs: 25 20 | long_words: 146 21 | complex_words: 43 22 | word usage: 23 | tobeverb: 36 24 | auxverb: 36 25 | conjunction: 29 26 | pronoun: 109 27 | preposition: 146 28 | nominalization: 2 29 | sentence beginnings: 30 | pronoun: 6 31 | interrogative: 1 32 | article: 5 33 | subordination: 3 34 | conjunction: 1 35 | preposition: 3 36 | -------------------------------------------------------------------------------- /readability/chapter9.5.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.61 3 | ARI: 10.15 4 | Coleman-Liau: 10.85 5 | FleschReadingEase: 72.22 6 | GunningFogIndex: 11.48 7 | LIX: 38.95 8 | SMOGIndex: 10.63 9 | RIX: 3.76 10 | sentence info: 11 | characters_per_word: 4.82 12 | syll_per_word: 1.38 13 | words_per_sentence: 17.79 14 | sentences_per_paragraph: 1.94 15 | characters: 5827 16 | syllables: 1667 17 | words: 1210 18 | sentences: 68 19 | paragraphs: 35 20 | long_words: 256 21 | complex_words: 132 22 | word usage: 23 | tobeverb: 43 24 | auxverb: 35 25 | conjunction: 23 26 | pronoun: 80 27 | preposition: 169 28 | nominalization: 18 29 | sentence beginnings: 30 | pronoun: 5 31 | interrogative: 0 32 | article: 7 33 | subordination: 3 34 | conjunction: 0 35 | preposition: 7 36 | -------------------------------------------------------------------------------- /readability/chapter9.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 6.52 3 | ARI: 9.23 4 | Coleman-Liau: 9.9 5 | FleschReadingEase: 79.35 6 | GunningFogIndex: 11.29 7 | LIX: 37.61 8 | SMOGIndex: 10.51 9 | RIX: 3.52 10 | sentence info: 11 | characters_per_word: 4.66 12 | syll_per_word: 1.3 13 | words_per_sentence: 17.42 14 | sentences_per_paragraph: 1.99 15 | characters: 23054 16 | syllables: 6422 17 | words: 4948 18 | sentences: 284 19 | paragraphs: 143 20 | long_words: 999 21 | complex_words: 534 22 | word usage: 23 | tobeverb: 184 24 | auxverb: 117 25 | conjunction: 119 26 | pronoun: 312 27 | preposition: 597 28 | nominalization: 110 29 | sentence beginnings: 30 | pronoun: 22 31 | interrogative: 3 32 | article: 44 33 | subordination: 17 34 | conjunction: 3 35 | preposition: 8 36 | -------------------------------------------------------------------------------- /readability/combineAllTexts.py: -------------------------------------------------------------------------------- 1 | #! python3 2 | fullText = [] 3 | 4 | for i in range(1, 5): 5 | fp = open('chapter%s.txt' % i, encoding='UTF=8') 6 | fullText.append(fp.read()) 7 | fp.close() 8 | 9 | fp = open('fullText.txt', 'w', encoding='UTF-8') 10 | fp.write('\n\n'.join(fullText)) 11 | fp.close() -------------------------------------------------------------------------------- /readability/fullText.readability.txt: -------------------------------------------------------------------------------- 1 | readability grades: 2 | Kincaid: 7.82 3 | ARI: 10.52 4 | Coleman-Liau: 10.53 5 | FleschReadingEase: 73.26 6 | GunningFogIndex: 12.47 7 | LIX: 40.94 8 | SMOGIndex: 11.3 9 | RIX: 4.18 10 | sentence info: 11 | characters_per_word: 4.74 12 | syll_per_word: 1.35 13 | words_per_sentence: 19.25 14 | sentences_per_paragraph: 1.97 15 | characters: 41615 16 | syllables: 11834 17 | words: 8780 18 | sentences: 456 19 | paragraphs: 231 20 | long_words: 1904 21 | complex_words: 1046 22 | word usage: 23 | tobeverb: 293 24 | auxverb: 176 25 | conjunction: 229 26 | pronoun: 624 27 | preposition: 1029 28 | nominalization: 232 29 | sentence beginnings: 30 | pronoun: 33 31 | interrogative: 10 32 | article: 43 33 | subordination: 12 34 | conjunction: 2 35 | preposition: 27 36 | -------------------------------------------------------------------------------- /src/_ISSUES.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sonar.py 4 | On lines 182 to 187, these might have to change if the language does not need to add an "s" to the plural of "device" or "chest". -------------------------------------------------------------------------------- /src/animation.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time 2 | from pygame.locals import * 3 | 4 | # set up pygame 5 | pygame.init() 6 | 7 | # set up the window 8 | WINDOWWIDTH = 400 9 | WINDOWHEIGHT = 400 10 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 11 | pygame.display.set_caption('Animation') 12 | 13 | # set up direction variables 14 | DOWNLEFT = 1 15 | DOWNRIGHT = 3 16 | UPLEFT = 7 17 | UPRIGHT = 9 18 | 19 | MOVESPEED = 4 20 | 21 | # set up the colors 22 | BLACK = (0, 0, 0) 23 | RED = (255, 0, 0) 24 | GREEN = (0, 255, 0) 25 | BLUE = (0, 0, 255) 26 | 27 | # set up the block data structure 28 | b1 = {'rect':pygame.Rect(300, 80, 50, 100), 'color':RED, 'dir':UPRIGHT} 29 | b2 = {'rect':pygame.Rect(200, 200, 20, 20), 'color':GREEN, 'dir':UPLEFT} 30 | b3 = {'rect':pygame.Rect(100, 150, 60, 60), 'color':BLUE, 'dir':DOWNLEFT} 31 | blocks = [b1, b2, b3] 32 | 33 | # run the game loop 34 | while True: 35 | # check for the QUIT event 36 | for event in pygame.event.get(): 37 | if event.type == QUIT: 38 | pygame.quit() 39 | sys.exit() 40 | 41 | # draw the black background onto the surface 42 | windowSurface.fill(BLACK) 43 | 44 | for b in blocks: 45 | # move the block data structure 46 | if b['dir'] == DOWNLEFT: 47 | b['rect'].left -= MOVESPEED 48 | b['rect'].top += MOVESPEED 49 | if b['dir'] == DOWNRIGHT: 50 | b['rect'].left += MOVESPEED 51 | b['rect'].top += MOVESPEED 52 | if b['dir'] == UPLEFT: 53 | b['rect'].left -= MOVESPEED 54 | b['rect'].top -= MOVESPEED 55 | if b['dir'] == UPRIGHT: 56 | b['rect'].left += MOVESPEED 57 | b['rect'].top -= MOVESPEED 58 | 59 | # check if the block has move out of the window 60 | if b['rect'].top < 0: 61 | # block has moved past the top 62 | if b['dir'] == UPLEFT: 63 | b['dir'] = DOWNLEFT 64 | if b['dir'] == UPRIGHT: 65 | b['dir'] = DOWNRIGHT 66 | if b['rect'].bottom > WINDOWHEIGHT: 67 | # block has moved past the bottom 68 | if b['dir'] == DOWNLEFT: 69 | b['dir'] = UPLEFT 70 | if b['dir'] == DOWNRIGHT: 71 | b['dir'] = UPRIGHT 72 | if b['rect'].left < 0: 73 | # block has moved past the left side 74 | if b['dir'] == DOWNLEFT: 75 | b['dir'] = DOWNRIGHT 76 | if b['dir'] == UPLEFT: 77 | b['dir'] = UPRIGHT 78 | if b['rect'].right > WINDOWWIDTH: 79 | # block has moved past the right side 80 | if b['dir'] == DOWNRIGHT: 81 | b['dir'] = DOWNLEFT 82 | if b['dir'] == UPRIGHT: 83 | b['dir'] = UPLEFT 84 | 85 | # draw the block onto the surface 86 | pygame.draw.rect(windowSurface, b['color'], b['rect']) 87 | 88 | # draw the window onto the screen 89 | pygame.display.update() 90 | time.sleep(0.02) 91 | -------------------------------------------------------------------------------- /src/background.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/background.mid -------------------------------------------------------------------------------- /src/baddie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/baddie.png -------------------------------------------------------------------------------- /src/bagels.py: -------------------------------------------------------------------------------- 1 | import random 2 | def getSecretNum(numDigits): 3 | # Returns a string that is numDigits long, made up of unique random digits. 4 | numbers = list(range(10)) 5 | random.shuffle(numbers) 6 | secretNum = '' 7 | for i in range(numDigits): 8 | secretNum += str(numbers[i]) 9 | return secretNum 10 | 11 | def getClues(guess, secretNum): 12 | # Returns a string with the pico, fermi, bagels clues to the user. 13 | if guess == secretNum: 14 | return 'You got it!' 15 | 16 | clue = [] 17 | 18 | for i in range(len(guess)): 19 | if guess[i] == secretNum[i]: 20 | clue.append('Fermi') 21 | elif guess[i] in secretNum: 22 | clue.append('Pico') 23 | if len(clue) == 0: 24 | return 'Bagels' 25 | 26 | clue.sort() 27 | return ' '.join(clue) 28 | 29 | def isOnlyDigits(num): 30 | # Returns True if num is a string made up only of digits. Otherwise returns False. 31 | if num == '': 32 | return False 33 | 34 | for i in num: 35 | if i not in '0 1 2 3 4 5 6 7 8 9'.split(): 36 | return False 37 | 38 | return True 39 | 40 | def playAgain(): 41 | # This function returns True if the player wants to play again, otherwise it returns False. 42 | print('Do you want to play again? (yes or no)') 43 | return input().lower().startswith('y') 44 | 45 | NUMDIGITS = 3 46 | MAXGUESS = 10 47 | 48 | print('I am thinking of a %s-digit number. Try to guess what it is.' % (NUMDIGITS)) 49 | print('Here are some clues:') 50 | print('When I say: That means:') 51 | print(' Pico One digit is correct but in the wrong position.') 52 | print(' Fermi One digit is correct and in the right position.') 53 | print(' Bagels No digit is correct.') 54 | 55 | while True: 56 | secretNum = getSecretNum(NUMDIGITS) 57 | print('I have thought up a number. You have %s guesses to get it.' % (MAXGUESS)) 58 | 59 | numGuesses = 1 60 | while numGuesses <= MAXGUESS: 61 | guess = '' 62 | while len(guess) != NUMDIGITS or not isOnlyDigits(guess): 63 | print('Guess #%s: ' % (numGuesses)) 64 | guess = input() 65 | 66 | clue = getClues(guess, secretNum) 67 | print(clue) 68 | numGuesses += 1 69 | 70 | if guess == secretNum: 71 | break 72 | if numGuesses > MAXGUESS: 73 | print('You ran out of guesses. The answer was %s.' % (secretNum)) 74 | 75 | if not playAgain(): 76 | break 77 | -------------------------------------------------------------------------------- /src/buggy.py: -------------------------------------------------------------------------------- 1 | import random 2 | number1 = random.randint(1, 10) 3 | number2 = random.randint(1, 10) 4 | print('What is ' + str(number1) + ' + ' + str(number2) + '?') 5 | answer = input() 6 | if answer == number1 + number2: 7 | print('Correct!') 8 | else: 9 | print('Nope! The answer is ' + str(number1 + number2)) 10 | -------------------------------------------------------------------------------- /src/bugs.py: -------------------------------------------------------------------------------- 1 | import random 2 | number1 = random.randint(1, 10) 3 | number2 = random.randint(1, 10) 4 | print('What is ' + str(number1) + ' + ' + str(number2) + '?') 5 | answer = input() 6 | if answer == number1 + number2: 7 | print('Correct!') 8 | else: 9 | print('Nope! The answer is ' + str(number1 + number2)) 10 | -------------------------------------------------------------------------------- /src/cherry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/cherry.png -------------------------------------------------------------------------------- /src/cipher.py: -------------------------------------------------------------------------------- 1 | # Caesar Cipher 2 | 3 | MAX_KEY_SIZE = 26 4 | 5 | def getMode(): 6 | while True: 7 | print('Do you wish to encrypt or decrypt a message?') 8 | mode = input().lower() 9 | if mode in 'encrypt e decrypt d'.split(): 10 | return mode 11 | else: 12 | print('Enter either "encrypt" or "e" or "decrypt" or "d".') 13 | 14 | def getMessage(): 15 | print('Enter your message:') 16 | return input() 17 | 18 | def getKey(): 19 | key = 0 20 | while True: 21 | print('Enter the key number (1-%s)' % (MAX_KEY_SIZE)) 22 | key = int(input()) 23 | if (key >= 1 and key <= MAX_KEY_SIZE): 24 | return key 25 | 26 | def getTranslatedMessage(mode, message, key): 27 | if mode[0] == 'd': 28 | key = -key 29 | translated = '' 30 | 31 | for symbol in message: 32 | if symbol.isalpha(): 33 | num = ord(symbol) 34 | num += key 35 | 36 | if symbol.isupper(): 37 | if num > ord('Z'): 38 | num -= 26 39 | elif num < ord('A'): 40 | num += 26 41 | elif symbol.islower(): 42 | if num > ord('z'): 43 | num -= 26 44 | elif num < ord('a'): 45 | num += 26 46 | 47 | translated += chr(num) 48 | else: 49 | translated += symbol 50 | return translated 51 | 52 | mode = getMode() 53 | message = getMessage() 54 | key = getKey() 55 | 56 | print('Your translated text is:') 57 | print(getTranslatedMessage(mode, message, key)) 58 | -------------------------------------------------------------------------------- /src/coinFlips.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('I will flip a coin 1000 times. Guess how many times it will come up heads. (Press enter to begin)') 3 | input() 4 | flips = 0 5 | heads = 0 6 | while flips < 1000: 7 | if random.randint(0, 1) == 1: 8 | heads = heads + 1 9 | flips = flips + 1 10 | 11 | if flips == 900: 12 | print('900 flips and there have been ' + str(heads) + ' heads.') 13 | if flips == 100: 14 | print('At 100 tosses, heads has come up ' + str(heads) + ' times so far.') 15 | if flips == 500: 16 | print('Half way done, and heads has come up ' + str(heads) + ' times.') 17 | 18 | print() 19 | print('Out of 1000 coin tosses, heads came up ' + str(heads) + ' times!') 20 | print('Were you close?') 21 | -------------------------------------------------------------------------------- /src/collisionDetection.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | def doRectsOverlap(rect1, rect2): 5 | for a, b in [(rect1, rect2), (rect2, rect1)]: 6 | # Check if a's corners are inside b 7 | if ((isPointInsideRect(a.left, a.top, b)) or 8 | (isPointInsideRect(a.left, a.bottom, b)) or 9 | (isPointInsideRect(a.right, a.top, b)) or 10 | (isPointInsideRect(a.right, a.bottom, b))): 11 | return True 12 | 13 | return False 14 | 15 | def isPointInsideRect(x, y, rect): 16 | if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom): 17 | return True 18 | else: 19 | return False 20 | 21 | 22 | # set up pygame 23 | pygame.init() 24 | mainClock = pygame.time.Clock() 25 | 26 | # set up the window 27 | WINDOWWIDTH = 400 28 | WINDOWHEIGHT = 400 29 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 30 | pygame.display.set_caption('Collision Detection') 31 | 32 | # set up direction variables 33 | DOWNLEFT = 1 34 | DOWNRIGHT = 3 35 | UPLEFT = 7 36 | UPRIGHT = 9 37 | 38 | MOVESPEED = 4 39 | 40 | # set up the colors 41 | BLACK = (0, 0, 0) 42 | GREEN = (0, 255, 0) 43 | WHITE = (255, 255, 255) 44 | 45 | # set up the bouncer and food data structures 46 | foodCounter = 0 47 | NEWFOOD = 40 48 | FOODSIZE = 20 49 | bouncer = {'rect':pygame.Rect(300, 100, 50, 50), 'dir':UPLEFT} 50 | foods = [] 51 | for i in range(20): 52 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 53 | 54 | # run the game loop 55 | while True: 56 | # check for the QUIT event 57 | for event in pygame.event.get(): 58 | if event.type == QUIT: 59 | pygame.quit() 60 | sys.exit() 61 | 62 | foodCounter += 1 63 | if foodCounter >= NEWFOOD: 64 | # add new food 65 | foodCounter = 0 66 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 67 | 68 | # draw the black background onto the surface 69 | windowSurface.fill(BLACK) 70 | 71 | # move the bouncer data structure 72 | if bouncer['dir'] == DOWNLEFT: 73 | bouncer['rect'].left -= MOVESPEED 74 | bouncer['rect'].top += MOVESPEED 75 | if bouncer['dir'] == DOWNRIGHT: 76 | bouncer['rect'].left += MOVESPEED 77 | bouncer['rect'].top += MOVESPEED 78 | if bouncer['dir'] == UPLEFT: 79 | bouncer['rect'].left -= MOVESPEED 80 | bouncer['rect'].top -= MOVESPEED 81 | if bouncer['dir'] == UPRIGHT: 82 | bouncer['rect'].left += MOVESPEED 83 | bouncer['rect'].top -= MOVESPEED 84 | 85 | # check if the bouncer has move out of the window 86 | if bouncer['rect'].top < 0: 87 | # bouncer has moved past the top 88 | if bouncer['dir'] == UPLEFT: 89 | bouncer['dir'] = DOWNLEFT 90 | if bouncer['dir'] == UPRIGHT: 91 | bouncer['dir'] = DOWNRIGHT 92 | if bouncer['rect'].bottom > WINDOWHEIGHT: 93 | # bouncer has moved past the bottom 94 | if bouncer['dir'] == DOWNLEFT: 95 | bouncer['dir'] = UPLEFT 96 | if bouncer['dir'] == DOWNRIGHT: 97 | bouncer['dir'] = UPRIGHT 98 | if bouncer['rect'].left < 0: 99 | # bouncer has moved past the left side 100 | if bouncer['dir'] == DOWNLEFT: 101 | bouncer['dir'] = DOWNRIGHT 102 | if bouncer['dir'] == UPLEFT: 103 | bouncer['dir'] = UPRIGHT 104 | if bouncer['rect'].right > WINDOWWIDTH: 105 | # bouncer has moved past the right side 106 | if bouncer['dir'] == DOWNRIGHT: 107 | bouncer['dir'] = DOWNLEFT 108 | if bouncer['dir'] == UPRIGHT: 109 | bouncer['dir'] = UPLEFT 110 | 111 | # draw the bouncer onto the surface 112 | pygame.draw.rect(windowSurface, WHITE, bouncer['rect']) 113 | 114 | # check if the bouncer has intersected with any food squares. 115 | for food in foods[:]: 116 | if doRectsOverlap(bouncer['rect'], food): 117 | foods.remove(food) 118 | 119 | # draw the food 120 | for i in range(len(foods)): 121 | pygame.draw.rect(windowSurface, GREEN, foods[i]) 122 | 123 | # draw the window onto the screen 124 | pygame.display.update() 125 | mainClock.tick(40) 126 | -------------------------------------------------------------------------------- /src/dragon.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def displayIntro(): 5 | print('You are in a land full of dragons. In front of you,') 6 | print('you see two caves. In one cave, the dragon is friendly') 7 | print('and will share his treasure with you. The other dragon') 8 | print('is greedy and hungry, and will eat you on sight.') 9 | print() 10 | 11 | def chooseCave(): 12 | cave = '' 13 | while cave != '1' and cave != '2': 14 | print('Which cave will you go into? (1 or 2)') 15 | cave = input() 16 | 17 | return cave 18 | 19 | def checkCave(chosenCave): 20 | print('You approach the cave...') 21 | time.sleep(2) 22 | print('It is dark and spooky...') 23 | time.sleep(2) 24 | print('A large dragon jumps out in front of you! He opens his jaws and...') 25 | print() 26 | time.sleep(2) 27 | 28 | friendlyCave = random.randint(1, 2) 29 | 30 | if chosenCave == str(friendlyCave): 31 | print('Gives you his treasure!') 32 | else: 33 | print('Gobbles you down in one bite!') 34 | 35 | playAgain = 'yes' 36 | while playAgain == 'yes' or playAgain == 'y': 37 | 38 | displayIntro() 39 | 40 | caveNumber = chooseCave() 41 | 42 | checkCave(caveNumber) 43 | 44 | print('Do you want to play again? (yes or no)') 45 | playAgain = input() 46 | -------------------------------------------------------------------------------- /src/gameover.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/gameover.wav -------------------------------------------------------------------------------- /src/guess.py: -------------------------------------------------------------------------------- 1 | # This is a guess the number game. 2 | import random 3 | 4 | guessesTaken = 0 5 | 6 | print('Hello! What is your name?') 7 | myName = input() 8 | 9 | number = random.randint(1, 20) 10 | print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') 11 | 12 | while guessesTaken < 6: 13 | print('Take a guess.') # There are four spaces in front of print. 14 | guess = input() 15 | guess = int(guess) 16 | 17 | guessesTaken = guessesTaken + 1 18 | 19 | if guess < number: 20 | print('Your guess is too low.') # There are eight spaces in front of print. 21 | 22 | if guess > number: 23 | print('Your guess is too high.') 24 | 25 | if guess == number: 26 | break 27 | 28 | if guess == number: 29 | guessesTaken = str(guessesTaken) 30 | print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!') 31 | 32 | if guess != number: 33 | number = str(number) 34 | print('Nope. The number I was thinking of was ' + number) 35 | -------------------------------------------------------------------------------- /src/hangman.py: -------------------------------------------------------------------------------- 1 | import random 2 | HANGMANPICS = [''' 3 | 4 | +---+ 5 | | | 6 | | 7 | | 8 | | 9 | | 10 | =========''', ''' 11 | 12 | +---+ 13 | | | 14 | O | 15 | | 16 | | 17 | | 18 | =========''', ''' 19 | 20 | +---+ 21 | | | 22 | O | 23 | | | 24 | | 25 | | 26 | =========''', ''' 27 | 28 | +---+ 29 | | | 30 | O | 31 | /| | 32 | | 33 | | 34 | =========''', ''' 35 | 36 | +---+ 37 | | | 38 | O | 39 | /|\ | 40 | | 41 | | 42 | =========''', ''' 43 | 44 | +---+ 45 | | | 46 | O | 47 | /|\ | 48 | / | 49 | | 50 | =========''', ''' 51 | 52 | +---+ 53 | | | 54 | O | 55 | /|\ | 56 | / \ | 57 | | 58 | ========='''] 59 | words = 'ant baboon badger bat bear beaver camel cat clam cobra cougar coyote crow deer dog donkey duck eagle ferret fox frog goat goose hawk lion lizard llama mole monkey moose mouse mule newt otter owl panda parrot pigeon python rabbit ram rat raven rhino salmon seal shark sheep skunk sloth snake spider stork swan tiger toad trout turkey turtle weasel whale wolf wombat zebra'.split() 60 | 61 | def getRandomWord(wordList): 62 | # This function returns a random string from the passed list of strings. 63 | wordIndex = random.randint(0, len(wordList) - 1) 64 | return wordList[wordIndex] 65 | 66 | def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord): 67 | print(HANGMANPICS[len(missedLetters)]) 68 | print() 69 | 70 | print('Missed letters:', end=' ') 71 | for letter in missedLetters: 72 | print(letter, end=' ') 73 | print() 74 | 75 | blanks = '_' * len(secretWord) 76 | 77 | for i in range(len(secretWord)): # replace blanks with correctly guessed letters 78 | if secretWord[i] in correctLetters: 79 | blanks = blanks[:i] + secretWord[i] + blanks[i+1:] 80 | 81 | for letter in blanks: # show the secret word with spaces in between each letter 82 | print(letter, end=' ') 83 | print() 84 | 85 | def getGuess(alreadyGuessed): 86 | # Returns the letter the player entered. This function makes sure the player entered a single letter, and not something else. 87 | while True: 88 | print('Guess a letter.') 89 | guess = input() 90 | guess = guess.lower() 91 | if len(guess) != 1: 92 | print('Please enter a single letter.') 93 | elif guess in alreadyGuessed: 94 | print('You have already guessed that letter. Choose again.') 95 | elif guess not in 'abcdefghijklmnopqrstuvwxyz': 96 | print('Please enter a LETTER.') 97 | else: 98 | return guess 99 | 100 | def playAgain(): 101 | # This function returns True if the player wants to play again, otherwise it returns False. 102 | print('Do you want to play again? (yes or no)') 103 | return input().lower().startswith('y') 104 | 105 | 106 | print('H A N G M A N') 107 | missedLetters = '' 108 | correctLetters = '' 109 | secretWord = getRandomWord(words) 110 | gameIsDone = False 111 | 112 | while True: 113 | displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord) 114 | 115 | # Let the player type in a letter. 116 | guess = getGuess(missedLetters + correctLetters) 117 | 118 | if guess in secretWord: 119 | correctLetters = correctLetters + guess 120 | 121 | # Check if the player has won 122 | foundAllLetters = True 123 | for i in range(len(secretWord)): 124 | if secretWord[i] not in correctLetters: 125 | foundAllLetters = False 126 | break 127 | if foundAllLetters: 128 | print('Yes! The secret word is "' + secretWord + '"! You have won!') 129 | gameIsDone = True 130 | else: 131 | missedLetters = missedLetters + guess 132 | 133 | # Check if player has guessed too many times and lost 134 | if len(missedLetters) == len(HANGMANPICS) - 1: 135 | displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord) 136 | print('You have run out of guesses!\nAfter ' + str(len(missedLetters)) + ' missed guesses and ' + str(len(correctLetters)) + ' correct guesses, the word was "' + secretWord + '"') 137 | gameIsDone = True 138 | 139 | # Ask the player if they want to play again (but only if the game is done). 140 | if gameIsDone: 141 | if playAgain(): 142 | missedLetters = '' 143 | correctLetters = '' 144 | gameIsDone = False 145 | secretWord = getRandomWord(words) 146 | else: 147 | break 148 | -------------------------------------------------------------------------------- /src/hello.py: -------------------------------------------------------------------------------- 1 | # This program says hello and asks for my name. 2 | print('Hello world!') 3 | print('What is your name?') 4 | myName = input() 5 | print('It is good to meet you, ' + myName) 6 | -------------------------------------------------------------------------------- /src/jokes.py: -------------------------------------------------------------------------------- 1 | print('What do you get when you cross a snowman with a vampire?') 2 | input() 3 | print('Frostbite!') 4 | print() 5 | print('What do dentists call a astronaut\'s cavity?') 6 | input() 7 | print('A black hole!') 8 | print() 9 | print('Knock knock.') 10 | input() 11 | print("Who's there?") 12 | input() 13 | print('Interrupting cow.') 14 | input() 15 | print('Interrupting cow wh', end='') 16 | print('-MOO!') 17 | -------------------------------------------------------------------------------- /src/pickup.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/pickup.wav -------------------------------------------------------------------------------- /src/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/src/player.png -------------------------------------------------------------------------------- /src/pygameHelloWorld.py: -------------------------------------------------------------------------------- 1 | import pygame, sys 2 | from pygame.locals import * 3 | 4 | # set up pygame 5 | pygame.init() 6 | 7 | # set up the window 8 | windowSurface = pygame.display.set_mode((500, 400), 0, 32) 9 | pygame.display.set_caption('Hello world!') 10 | 11 | # set up the colors 12 | BLACK = (0, 0, 0) 13 | WHITE = (255, 255, 255) 14 | RED = (255, 0, 0) 15 | GREEN = (0, 255, 0) 16 | BLUE = (0, 0, 255) 17 | 18 | # set up fonts 19 | basicFont = pygame.font.SysFont(None, 48) 20 | 21 | # set up the text 22 | text = basicFont.render('Hello world!', True, WHITE, BLUE) 23 | textRect = text.get_rect() 24 | textRect.centerx = windowSurface.get_rect().centerx 25 | textRect.centery = windowSurface.get_rect().centery 26 | 27 | # draw the white background onto the surface 28 | windowSurface.fill(WHITE) 29 | 30 | # draw a green polygon onto the surface 31 | pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))) 32 | 33 | # draw some blue lines onto the surface 34 | pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4) 35 | pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120)) 36 | pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4) 37 | 38 | # draw a blue circle onto the surface 39 | pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0) 40 | 41 | # draw a red ellipse onto the surface 42 | pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1) 43 | 44 | # draw the text's background rectangle onto the surface 45 | pygame.draw.rect(windowSurface, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40)) 46 | 47 | # get a pixel array of the surface 48 | pixArray = pygame.PixelArray(windowSurface) 49 | pixArray[480][380] = BLACK 50 | del pixArray 51 | 52 | # draw the text onto the surface 53 | windowSurface.blit(text, textRect) 54 | 55 | # draw the window onto the screen 56 | pygame.display.update() 57 | 58 | # run the game loop 59 | while True: 60 | for event in pygame.event.get(): 61 | if event.type == QUIT: 62 | pygame.quit() 63 | sys.exit() 64 | -------------------------------------------------------------------------------- /src/pygameInput.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | # set up pygame 5 | pygame.init() 6 | mainClock = pygame.time.Clock() 7 | 8 | # set up the window 9 | WINDOWWIDTH = 400 10 | WINDOWHEIGHT = 400 11 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 12 | pygame.display.set_caption('Input') 13 | 14 | # set up the colors 15 | BLACK = (0, 0, 0) 16 | GREEN = (0, 255, 0) 17 | WHITE = (255, 255, 255) 18 | 19 | # set up the player and food data structure 20 | foodCounter = 0 21 | NEWFOOD = 40 22 | FOODSIZE = 20 23 | player = pygame.Rect(300, 100, 50, 50) 24 | foods = [] 25 | for i in range(20): 26 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 27 | 28 | # set up movement variables 29 | moveLeft = False 30 | moveRight = False 31 | moveUp = False 32 | moveDown = False 33 | 34 | MOVESPEED = 6 35 | 36 | 37 | # run the game loop 38 | while True: 39 | # check for events 40 | for event in pygame.event.get(): 41 | if event.type == QUIT: 42 | pygame.quit() 43 | sys.exit() 44 | if event.type == KEYDOWN: 45 | # change the keyboard variables 46 | if event.key == K_LEFT or event.key == ord('a'): 47 | moveRight = False 48 | moveLeft = True 49 | if event.key == K_RIGHT or event.key == ord('d'): 50 | moveLeft = False 51 | moveRight = True 52 | if event.key == K_UP or event.key == ord('w'): 53 | moveDown = False 54 | moveUp = True 55 | if event.key == K_DOWN or event.key == ord('s'): 56 | moveUp = False 57 | moveDown = True 58 | if event.type == KEYUP: 59 | if event.key == K_ESCAPE: 60 | pygame.quit() 61 | sys.exit() 62 | if event.key == K_LEFT or event.key == ord('a'): 63 | moveLeft = False 64 | if event.key == K_RIGHT or event.key == ord('d'): 65 | moveRight = False 66 | if event.key == K_UP or event.key == ord('w'): 67 | moveUp = False 68 | if event.key == K_DOWN or event.key == ord('s'): 69 | moveDown = False 70 | if event.key == ord('x'): 71 | player.top = random.randint(0, WINDOWHEIGHT - player.height) 72 | player.left = random.randint(0, WINDOWWIDTH - player.width) 73 | 74 | if event.type == MOUSEBUTTONUP: 75 | foods.append(pygame.Rect(event.pos[0], event.pos[1], FOODSIZE, FOODSIZE)) 76 | 77 | foodCounter += 1 78 | if foodCounter >= NEWFOOD: 79 | # add new food 80 | foodCounter = 0 81 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 82 | 83 | # draw the black background onto the surface 84 | windowSurface.fill(BLACK) 85 | 86 | # move the player 87 | if moveDown and player.bottom < WINDOWHEIGHT: 88 | player.top += MOVESPEED 89 | if moveUp and player.top > 0: 90 | player.top -= MOVESPEED 91 | if moveLeft and player.left > 0: 92 | player.left -= MOVESPEED 93 | if moveRight and player.right < WINDOWWIDTH: 94 | player.right += MOVESPEED 95 | 96 | # draw the player onto the surface 97 | pygame.draw.rect(windowSurface, WHITE, player) 98 | 99 | # check if the player has intersected with any food squares. 100 | for food in foods[:]: 101 | if player.colliderect(food): 102 | foods.remove(food) 103 | 104 | # draw the food 105 | for i in range(len(foods)): 106 | pygame.draw.rect(windowSurface, GREEN, foods[i]) 107 | 108 | # draw the window onto the screen 109 | pygame.display.update() 110 | mainClock.tick(40) 111 | -------------------------------------------------------------------------------- /src/spritesAndSounds.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time, random 2 | from pygame.locals import * 3 | 4 | # set up pygame 5 | pygame.init() 6 | mainClock = pygame.time.Clock() 7 | 8 | # set up the window 9 | WINDOWWIDTH = 400 10 | WINDOWHEIGHT = 400 11 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 12 | pygame.display.set_caption('Sprites and Sound') 13 | 14 | # set up the colors 15 | BLACK = (0, 0, 0) 16 | 17 | # set up the block data structure 18 | player = pygame.Rect(300, 100, 40, 40) 19 | playerImage = pygame.image.load('player.png') 20 | playerStretchedImage = pygame.transform.scale(playerImage, (40, 40)) 21 | foodImage = pygame.image.load('cherry.png') 22 | foods = [] 23 | for i in range(20): 24 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - 20), random.randint(0, WINDOWHEIGHT - 20), 20, 20)) 25 | 26 | foodCounter = 0 27 | NEWFOOD = 40 28 | 29 | # set up keyboard variables 30 | moveLeft = False 31 | moveRight = False 32 | moveUp = False 33 | moveDown = False 34 | 35 | MOVESPEED = 6 36 | 37 | # set up music 38 | pickUpSound = pygame.mixer.Sound('pickup.wav') 39 | pygame.mixer.music.load('background.mid') 40 | pygame.mixer.music.play(-1, 0.0) 41 | musicPlaying = True 42 | 43 | # run the game loop 44 | while True: 45 | # check for the QUIT event 46 | for event in pygame.event.get(): 47 | if event.type == QUIT: 48 | pygame.quit() 49 | sys.exit() 50 | if event.type == KEYDOWN: 51 | # change the keyboard variables 52 | if event.key == K_LEFT or event.key == ord('a'): 53 | moveRight = False 54 | moveLeft = True 55 | if event.key == K_RIGHT or event.key == ord('d'): 56 | moveLeft = False 57 | moveRight = True 58 | if event.key == K_UP or event.key == ord('w'): 59 | moveDown = False 60 | moveUp = True 61 | if event.key == K_DOWN or event.key == ord('s'): 62 | moveUp = False 63 | moveDown = True 64 | if event.type == KEYUP: 65 | if event.key == K_ESCAPE: 66 | pygame.quit() 67 | sys.exit() 68 | if event.key == K_LEFT or event.key == ord('a'): 69 | moveLeft = False 70 | if event.key == K_RIGHT or event.key == ord('d'): 71 | moveRight = False 72 | if event.key == K_UP or event.key == ord('w'): 73 | moveUp = False 74 | if event.key == K_DOWN or event.key == ord('s'): 75 | moveDown = False 76 | if event.key == ord('x'): 77 | player.top = random.randint(0, WINDOWHEIGHT - player.height) 78 | player.left = random.randint(0, WINDOWWIDTH - player.width) 79 | if event.key == ord('m'): 80 | if musicPlaying: 81 | pygame.mixer.music.stop() 82 | else: 83 | pygame.mixer.music.play(-1, 0.0) 84 | musicPlaying = not musicPlaying 85 | 86 | if event.type == MOUSEBUTTONUP: 87 | foods.append(pygame.Rect(event.pos[0] - 10, event.pos[1] - 10, 20, 20)) 88 | 89 | foodCounter += 1 90 | if foodCounter >= NEWFOOD: 91 | # add new food 92 | foodCounter = 0 93 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - 20), random.randint(0, WINDOWHEIGHT - 20), 20, 20)) 94 | 95 | # draw the black background onto the surface 96 | windowSurface.fill(BLACK) 97 | 98 | # move the player 99 | if moveDown and player.bottom < WINDOWHEIGHT: 100 | player.top += MOVESPEED 101 | if moveUp and player.top > 0: 102 | player.top -= MOVESPEED 103 | if moveLeft and player.left > 0: 104 | player.left -= MOVESPEED 105 | if moveRight and player.right < WINDOWWIDTH: 106 | player.right += MOVESPEED 107 | 108 | 109 | # draw the block onto the surface 110 | windowSurface.blit(playerStretchedImage, player) 111 | 112 | # check if the block has intersected with any food squares. 113 | for food in foods[:]: 114 | if player.colliderect(food): 115 | foods.remove(food) 116 | player = pygame.Rect(player.left, player.top, player.width + 2, player.height + 2) 117 | playerStretchedImage = pygame.transform.scale(playerImage, (player.width, player.height)) 118 | if musicPlaying: 119 | pickUpSound.play() 120 | 121 | # draw the food 122 | for food in foods: 123 | windowSurface.blit(foodImage, food) 124 | 125 | # draw the window onto the screen 126 | pygame.display.update() 127 | mainClock.tick(40) 128 | -------------------------------------------------------------------------------- /text/README.txt: -------------------------------------------------------------------------------- 1 | The "text" folder contains text files for the chapter contents, not the formatting. These file will be used for copy editing, and then sent to Word or InDesign for layout. -------------------------------------------------------------------------------- /text/c0.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c0.docx -------------------------------------------------------------------------------- /text/c1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c1.docx -------------------------------------------------------------------------------- /text/c10.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c10.docx -------------------------------------------------------------------------------- /text/c11.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c11.docx -------------------------------------------------------------------------------- /text/c12.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c12.docx -------------------------------------------------------------------------------- /text/c13.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c13.docx -------------------------------------------------------------------------------- /text/c14.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c14.docx -------------------------------------------------------------------------------- /text/c15.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c15.docx -------------------------------------------------------------------------------- /text/c16.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c16.docx -------------------------------------------------------------------------------- /text/c17.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c17.docx -------------------------------------------------------------------------------- /text/c18.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c18.docx -------------------------------------------------------------------------------- /text/c19.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c19.docx -------------------------------------------------------------------------------- /text/c2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c2.docx -------------------------------------------------------------------------------- /text/c20.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c20.docx -------------------------------------------------------------------------------- /text/c3.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c3.docx -------------------------------------------------------------------------------- /text/c4.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c4.docx -------------------------------------------------------------------------------- /text/c5.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c5.docx -------------------------------------------------------------------------------- /text/c6.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c6.docx -------------------------------------------------------------------------------- /text/c7.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c7.docx -------------------------------------------------------------------------------- /text/c8.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c8.docx -------------------------------------------------------------------------------- /text/c9.5.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c9.5.docx -------------------------------------------------------------------------------- /text/c9.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/text/c9.docx -------------------------------------------------------------------------------- /text/chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | Be sure to install Python 3, not Python 2! -------------------------------------------------------------------------------- /text/chapter10.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 10-1: 2 | Start 3 | Ask for player's letter. 4 | Decide who goes first. 5 | Player's Turn 6 | Show the board. 7 | Get player's move. 8 | Check if player won. 9 | Check for tie. 10 | Computer's Turn 11 | Get computer's move. 12 | Check if computer won. 13 | Check for tie. 14 | Ask player to play again. 15 | End 16 | 17 | Fig 10-3: 18 | Corner 19 | Side 20 | Center 21 | 22 | Fig 10-4: 23 | 1. Make winning move. 24 | 2. Block player's winning move. 25 | 3. Move on corner. 26 | 4. Move on center. 27 | 5. Move on side. 28 | 29 | Fig 10-5: 30 | Reference 31 | (a list value) 32 | 33 | -------------------------------------------------------------------------------- /text/chapter11.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 11-1: 2 | Start 3 | Generate secret number. 4 | See if player has run out of guesses. 5 | Get player's guess. 6 | Tell player clues. 7 | Increment guess count. 8 | Ask to play again. 9 | Player has lost. 10 | Player has won. 11 | End 12 | 13 | -------------------------------------------------------------------------------- /text/chapter12.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 12-1: 2 | X-axis 3 | Y-axis 4 | 5 | Fig 12-3: 6 | (smaller) 7 | (bigger) 8 | 9 | Fig 12-8: 10 | (a minus eats the plus sign on its left) 11 | 12 | Fig 12-9: 13 | (two minuses combine into a plus) 14 | 15 | Fig 12-11: 16 | (because this is addition, swap the order) 17 | (the minus sign eats the plus sign on its left) 18 | 19 | Fig 12-12: 20 | X increases 21 | Y increases 22 | 23 | -------------------------------------------------------------------------------- /text/chapter13.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 13-1: 2 | Treasure Chest 3 | Sonar Device 4 | 5 | Fig 13-2: 6 | Treasure Chest 7 | Sonar Device 8 | Possible Treasure Chest 9 | 10 | -------------------------------------------------------------------------------- /text/chapter14.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter15.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 15-7: 2 | X increases 3 | Y increases -------------------------------------------------------------------------------- /text/chapter16.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter17.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 17-3: 2 | Programming is fun! 3 | 4 | Fig 17-4: 5 | Aliased 6 | Anti-aliased 7 | 8 | -------------------------------------------------------------------------------- /text/chapter18.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 18-2: 2 | Intersecting Rectangles 3 | Not Intersecting Rectangles 4 | 5 | -------------------------------------------------------------------------------- /text/chapter19.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter2.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 2-3: 2 | value 3 | operator 4 | expression 5 | 6 | Fig 2-4: 7 | spam 8 | 9 | Fig 2-5: 10 | eggs 11 | fizz 12 | -------------------------------------------------------------------------------- /text/chapter20.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter3.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter4.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 4-2: 2 | ...go inside the while-block to here. 3 | ...go past the while-block to here. 4 | 5 | Fig 4-3: 6 | fizzy 7 | if keyword 8 | condition 9 | while keyword 10 | doesn't loop 11 | loops 12 | -------------------------------------------------------------------------------- /text/chapter5.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter6.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 6-1: 2 | def keyword 3 | parentheses 4 | function name 5 | colon 6 | 7 | Fig 6-2: 8 | Start 9 | Show introduction 10 | Player chooses a cave 11 | Check for friendly or hungry dragon 12 | Player wins 13 | Player loses 14 | Ask to play again 15 | End 16 | 17 | -------------------------------------------------------------------------------- /text/chapter7.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter8.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 8-1 through 8-9: 2 | Start 3 | Come up with a secret word. 4 | Show the board and blanks to the player. 5 | Ask player to guess a letter. 6 | Player already guessed this letter. 7 | Letter is in secret word. 8 | Letter is not in secret word. 9 | Player has guessed all letters and wins. 10 | Player has run out of body parts and loses. 11 | Ask player to play again. 12 | End 13 | -------------------------------------------------------------------------------- /text/chapter9.5.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /text/chapter9.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/README.md: -------------------------------------------------------------------------------- 1 | This folder contains translation work of the chapter from the "text" folder. The _example folder shows an example of what types of files are expected for each language translaiton. 2 | 3 | A list of translators and their contact information is in the SPECIAL_THANKS_TO.txt file, if you wish to collaborate with others or avoid duplicating work. 4 | 5 | Write down any notes for translators about cultural/translation issues they should keep in mind when translating each chapter: 6 | 7 | 8 | CHAPTER 1 9 | --------- 10 | 11 | * No issues so far. 12 | 13 | 14 | CHAPTER 2 15 | --------- 16 | 17 | * No issues so far. 18 | 19 | 20 | CHAPTER 3 21 | --------- 22 | 23 | * No issues so far. 24 | 25 | 26 | CHAPTER 4 27 | --------- 28 | 29 | 30 | * The jokes will have to be changed to something culturally relevant. 31 | 32 | 33 | CHAPTER 5 34 | --------- 35 | 36 | * No issues so far. 37 | 38 | 39 | CHAPTER 6 40 | --------- 41 | 42 | * No issues so far. 43 | 44 | 45 | CHAPTER 7 46 | --------- 47 | 48 | * No issues so far. 49 | 50 | 51 | CHAPTER 8 52 | --------- 53 | 54 | * No issues so far. 55 | 56 | 57 | CHAPTER 9 58 | --------- 59 | 60 | * ES: The accents have been removed from some words, as it would be unnatural to have different letters like "a"!="á". Also "ñ" has been added to the dictionary string "abc...xyz" 61 | 62 | 63 | CHAPTER 10 64 | --------- 65 | 66 | * No issues so far. 67 | 68 | 69 | CHAPTER 11 70 | --------- 71 | 72 | * No issues so far. 73 | 74 | 75 | CHAPTER 12 76 | --------- 77 | 78 | * No issues so far. 79 | 80 | 81 | CHAPTER 13 82 | --------- 83 | 84 | * No issues so far. 85 | 86 | 87 | CHAPTER 14 88 | --------- 89 | 90 | * No issues so far. 91 | 92 | 93 | CHAPTER 15 94 | --------- 95 | 96 | * No issues so far. 97 | 98 | 99 | CHAPTER 16 100 | --------- 101 | 102 | * No issues so far. 103 | 104 | 105 | CHAPTER 17 106 | --------- 107 | 108 | * No issues so far. 109 | 110 | 111 | CHAPTER 18 112 | --------- 113 | 114 | * No issues so far. 115 | 116 | CHAPTER 19 117 | --------- 118 | 119 | * No issues so far. 120 | 121 | 122 | CHAPTER 20 123 | --------- 124 | 125 | * No issues so far. 126 | 127 | -------------------------------------------------------------------------------- /translations/SPECIAL_THANKS_TO.txt: -------------------------------------------------------------------------------- 1 | Here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS -- 2 | people who have helped with translations, answered questions, and generally 3 | made Invent with Python that much better: 4 | 5 | Alejandro Pernin - ale.pernin@gmail.com 6 | Alfredo R. Carella - alfredocarella@gmail.com 7 | David Fleury - dfleury2@free.fr 8 | Christer Nilsson - janchrister.nilsson@gmail.com 9 | Jakob Malm - jakob.malm@gmail.com 10 | Mats Rörbecker - mats@rorbecker.com 11 | -------------------------------------------------------------------------------- /translations/_example/chapter1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/_example/chapter1.txt -------------------------------------------------------------------------------- /translations/af/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/bn/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/de/src/buggy.py: -------------------------------------------------------------------------------- 1 | import random 2 | nummer1 = random.randint(1, 10) 3 | nummer2 = random.randint(1, 10) 4 | print('Wieviel ist ' + str(nummer1) + ' + ' + str(nummer2) + '?') 5 | antwort = input() 6 | if antwort == nummer1 + nummer2: 7 | print('Richtig!') 8 | else: 9 | print('Nein! Die Antwort ist ' + str(nummer1 + nummer2)) -------------------------------------------------------------------------------- /translations/de/src/drachen.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def zeigeEinfuehrungAn(): 5 | print('Du bist ein einem Land voller Drachen. Vor Dir') 6 | print('siehst Du zwei Höhlen. In einer Höhle haust ein freundlicher Drache,') 7 | print('der seine Schätze mit Dir teilt. Der andere Drache') 8 | print('ist gierig und hungrig, und wird Dich bei Sichtkontakt auffressen.') 9 | print() 10 | 11 | def sucheHoehleAus(): 12 | hoehle = '' 13 | while hoehle != '1' and hoehle != '2': 14 | print('In welche Höhle wirst Du gehen? (1 oder 2)') 15 | hoehle = input() 16 | 17 | return hoehle 18 | 19 | def ueberpruefeHoehle(ausgewaehlteHoehle): 20 | print('Du näherst Dich der Höhle...') 21 | time.sleep(2) 22 | print('Es ist dunkel und gruselig...') 23 | time.sleep(2) 24 | print('Ein großer Drache springt vor Deine Füße! Er öffnet sein Maul und...') 25 | print() 26 | time.sleep(2) 27 | 28 | freundlicheHoehle = random.randint(1, 2) 29 | 30 | if ausgewaehlteHoehle == str(freundlicheHoehle): 31 | print('Gibt Dir seinen Schatz!') 32 | else: 33 | print('Verschlingt Dich in einem Mal!') 34 | 35 | spieleNochEinmal = 'ja' 36 | while spieleNochEinmal == 'ja' or spieleNochEinmal == 'j': 37 | 38 | zeigeEinfuehrungAn() 39 | 40 | hoehlenNummer = sucheHoehleAus() 41 | 42 | ueberpruefeHoehle(hoehlenNummer) 43 | 44 | print('Möchtest Du noch einmal spielen? (ja oder nein)') 45 | spieleNochEinmal = input() 46 | -------------------------------------------------------------------------------- /translations/de/src/galgenmann.py: -------------------------------------------------------------------------------- 1 | import random 2 | GALGENMANNBILDER = [''' 3 | 4 | +---+ 5 | | | 6 | | 7 | | 8 | | 9 | | 10 | =========''', ''' 11 | 12 | +---+ 13 | | | 14 | O | 15 | | 16 | | 17 | | 18 | =========''', ''' 19 | 20 | +---+ 21 | | | 22 | O | 23 | | | 24 | | 25 | | 26 | =========''', ''' 27 | 28 | +---+ 29 | | | 30 | O | 31 | /| | 32 | | 33 | | 34 | =========''', ''' 35 | 36 | +---+ 37 | | | 38 | O | 39 | /|\ | 40 | | 41 | | 42 | =========''', ''' 43 | 44 | +---+ 45 | | | 46 | O | 47 | /|\ | 48 | / | 49 | | 50 | =========''', ''' 51 | 52 | +---+ 53 | | | 54 | O | 55 | /|\ | 56 | / \ | 57 | | 58 | ========='''] 59 | worte = 'aal adler alligator ameise amsel bär biber bussard chamäleon dachs delfin eichhörnchen eidechse elch elefant faultier fledermaus fuchs gans gepard gorilla hai hamster hase hirsch huhn igel jaguar kamel känguru koala leopard libelle marienkäfer maulwurf meerschweinchen möwe nachtigal nilpferd panda pfau qualle ratte regenwurm schaf schimpanse schwan schwein strauß tausendfüßer tintenfisch wachtel wal wolf zebra ziege'.split() 60 | 61 | def zufallsWort(wortListe): 62 | # Diese Funktion gibt eine zufällige Zeichenkette aus der übergebenen Zeichenketten-Liste zurück. 63 | wortIndex = random.randint(0, len(wortListe) - 1) 64 | return wortListe[wortIndex] 65 | 66 | def zeigeSpielbrettAn(GALGENMANNBILDER, falscheBuchstaben, richtigeBuchstaben, geheimWort): 67 | print(GALGENMANNBILDER[len(falscheBuchstaben)]) 68 | print() 69 | 70 | print('Falsche Buchstaben:', end=' ') 71 | for buchstabe in falscheBuchstaben: 72 | print(buchstabe, end=' ') 73 | print() 74 | 75 | luecken = '_' * len(geheimWort) 76 | 77 | for i in range(len(geheimWort)): # Ersetze Lücken mit korrekt geratenen Buchstaben 78 | if geheimWort[i] in richtigeBuchstaben: 79 | luecken = luecken[:i] + geheimWort[i] + luecken[i+1:] 80 | 81 | for buchstabe in luecken: # Zeige das Geheimwort mit Leerzeichen zwischen den Buchstaben 82 | print(buchstabe, end=' ') 83 | print() 84 | 85 | def rateBuchstabe(bereitsGeraten): 86 | # Stellt sicher, dass der Spieler nur einen einzelnen Buchstaben eintippt und gibt ihn zurück. 87 | while True: 88 | print('Rate einen Buchstaben.') 89 | eingabe = input() 90 | eingabe = eingabe.lower() 91 | if len(eingabe) != 1: 92 | print('Bitte gib einen einzelnen Buchstaben ein.') 93 | elif eingabe in bereitsGeraten: 94 | print('Du hast diesen Buchstaben bereits probiert. Rate noch einmal.') 95 | elif eingabe not in 'abcdefghijklmnopqrstuvwxyz': 96 | print('Bitte gib einen BUCHSTABEN ein.') 97 | else: 98 | return eingabe 99 | 100 | def spieleNochEinmal(): 101 | # Diese Funktion True zurück, falls der Spieler noch einmal spielen möchte, False sonst. 102 | print('Möchtest Du noch einmal spielen? (ja oder nein)') 103 | return input().lower().startswith('j') 104 | 105 | 106 | print('G A L G E N M A N N') 107 | falscheBuchstaben = '' 108 | richtigeBuchstaben = '' 109 | geheimWort = zufallsWort(worte) 110 | spielIstBeendet = False 111 | 112 | while True: 113 | zeigeSpielbrettAn(GALGENMANNBILDER, falscheBuchstaben, richtigeBuchstaben, geheimWort) 114 | 115 | # Lass den Spieler einen Buchhstaben eingeben. 116 | buchstabe = rateBuchstabe(falscheBuchstaben + richtigeBuchstaben) 117 | 118 | if buchstabe in geheimWort: 119 | richtigeBuchstaben = richtigeBuchstaben + buchstabe 120 | 121 | # Überprüfe, ob der Spieler gewonnen hat 122 | alleBuchstabenGeraten = True 123 | for i in range(len(geheimWort)): 124 | if geheimWort[i] not in richtigeBuchstaben: 125 | alleBuchstabenGeraten = False 126 | break 127 | if alleBuchstabenGeraten: 128 | print('Ja! Das geheime Wort ist "' + geheimWort + '"! Du hast gewonnen!') 129 | spielIstBeendet = True 130 | else: 131 | falscheBuchstaben = falscheBuchstaben + buchstabe 132 | 133 | # Überprüfe, ob der Spieler zu viele Rateversuche verbraucht und damit verloren hat 134 | if len(falscheBuchstaben) == len(GALGENMANNBILDER) - 1: 135 | zeigeSpielbrettAn(GALGENMANNBILDER, falscheBuchstaben, richtigeBuchstaben, geheimWort) 136 | print('Du hast zu viele Versuche gebraucht!\nNach ' + str(len(falscheBuchstaben)) + ' falsch und ' + str(len(richtigeBuchstaben)) + ' richtig geratenen Buchstaben lautet das Wort "' + geheimWort + '"') 137 | spielIstBeendet = True 138 | 139 | # Frage den Spieler, ob er noch einmal spielen möchte (aber nur, wenn das Spiel zu Ende ist). 140 | if spielIstBeendet: 141 | if spieleNochEinmal(): 142 | falscheBuchstaben = '' 143 | richtigeBuchstaben = '' 144 | spielIstBeendet = False 145 | geheimWort = zufallsWort(worte) 146 | else: 147 | break 148 | -------------------------------------------------------------------------------- /translations/de/src/muenzwurf.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Ich simuliere 1000 Münzenwürfe. Rate, wie oft das Ergebnis Zahl ist. (Drücke Enter, um zu beginnen)') 3 | input() 4 | wuerfe = 0 5 | kopf = 0 6 | while wuerfe < 1000: 7 | if random.randint(0, 1) == 1 8 | kopf = kopf + 1 9 | wuerfe = wuerfe + 1 10 | 11 | if wuerfe == 900: 12 | print('900 Münzenwürfe, und Kopf kam ' + str(kopf) + ' mal vor.') 13 | if wuerfe == 100: 14 | print('100 Münzenwürfe, Kopf kam bisher ' + str(kopf) + ' mal vor.') 15 | if wuerfe == 500: 16 | print('Halbzeit, und Kopf kam ' + str(kopf) + ' mal vor.') 17 | 18 | print() 19 | print('Von 1000 Münzwürfen hatten ' + str(kopf) + ' das Ergebnis Kopf!') 20 | print('Warst du nahe dran?') -------------------------------------------------------------------------------- /translations/de/src/witze.py: -------------------------------------------------------------------------------- 1 | print('Warum sind Geisterfahrer die freundlichsten Menschen?') 2 | input() 3 | print('Weil sie so entgegenkommend sind!') 4 | print() 5 | print('Was ist der Unterschied zwischen einem Bäcker und einem Teppich?') 6 | input() 7 | print('Der Bäcker muss morgens um 4 aufstehen. Der Teppich kann liegen bleiben.') 8 | print() 9 | print('Klopf, klopf.') 10 | input() 11 | print("Wer da?") 12 | input() 13 | print('Anna!') 14 | input() 15 | print('Anna wer?') 16 | input() 17 | print('An\'na Tür hat wer geklingelt', end='') 18 | print('-HAHA!') 19 | -------------------------------------------------------------------------------- /translations/de/src/zahlenRaten.py: -------------------------------------------------------------------------------- 1 | # Das ist ein Zahlenratespiel. 2 | import random 3 | 4 | abgegebenTipps = 0 5 | 6 | print('Hallo! Was ist dein Name?') 7 | meinName = input() 8 | 9 | zahl = random.randint(1, 20) 10 | print('Also, ' + meinName + ', ich denke an eine Zahl zwischen 1 und 20.') 11 | 12 | while abgegebenTipps < 6: 13 | print('Los, rate.') # Vor print sind vier Leerzeichen. 14 | tipp = input() 15 | tipp = int(tipp) 16 | 17 | abgegebenTipps = abgegebenTipps + 1 18 | 19 | if tipp < zahl: 20 | print('Dein Tipp ist zu niedrig.') # Hier sind acht Leerzeichen vor print. 21 | 22 | if tipp > zahl: 23 | print('Dein Tipp ist zu hoch.') 24 | 25 | if tipp == zahl: 26 | break 27 | 28 | if tipp == zahl: 29 | abgegebenTipps = str(abgegebenTipps) 30 | print('Gut gemacht, ' + meinName + '! Du hast meine Zahl in ' + abgegebenTipps + ' Zügen erraten!') 31 | 32 | if tipp != zahl: 33 | zahl = str(zahl) 34 | print('Nene. Die Nummer an die ich gedacht habe war ' + zahl) 35 | -------------------------------------------------------------------------------- /translations/de/text/chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Abb. 1-1: 2 | Stelle sicher Python 3 zu installieren, nicht Python 2! -------------------------------------------------------------------------------- /translations/de/text/chapter6.figures.txt: -------------------------------------------------------------------------------- 1 | Abb 6-1: 2 | Das Schlüsselwort def 3 | Klammern 4 | Funktionsname 5 | Doppelpunkt 6 | 7 | Abb 6-2: 8 | Start 9 | Zeige Einführung 10 | Spieler sucht Höhle aus 11 | Auf freundlichen oder hungrigen Drachen überprüfen 12 | Spieler gewinnt 13 | Spieler verliert 14 | Frage Spieler, ob er nochmal spielen möchte 15 | Ende 16 | 17 | -------------------------------------------------------------------------------- /translations/de/text/chapter7.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/de/text/chapter8.figures.txt: -------------------------------------------------------------------------------- 1 | Abbildungen 8-1 bis 8-9: 2 | Start 3 | Geheimes Wort ausdenken. 4 | Zeige dem Spieler den Galgenmann und die richtig-geratenen Buchstaben. 5 | Frage Spieler nach Buchstabe. 6 | Spieler hat diesen Buchstaben bereits geraten. 7 | Buchstabe ist in geheimem Wort enthalten. 8 | Buchstabe ist in geheimem Wort nicht enthalten. 9 | Spieler hat alle Buchstaben richtig geraten und gewinnt. 10 | Galgenmann komplett: Leider verloren. 11 | Frage Spieler, ob er nochmals spielen möchte. 12 | Ende -------------------------------------------------------------------------------- /translations/es/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | Alfredo Carella https://github.com/alfredocarella 5 | 6 | Alejandro Pernin https://github.com/aleperno 7 | 8 | 9 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 10 | 11 | Title 12 | ===== 13 | 14 | Inventa tus Propios Juegos de Computadora con Python 15 | 16 | General Notes 17 | ============= 18 | 19 | It is recommended to follow the general vocabulary style of this tutorial: http://docs.python.org.ar/tutorial/ 20 | 21 | A glossary has been added in translations/es/ under the name of "glosario.txt" to be a reference for all translators to use the same translations. 22 | -------------------------------------------------------------------------------- /translations/es/glosario.txt: -------------------------------------------------------------------------------- 1 | backslash, barra inversa 2 | cake, torta 3 | case-sensitive, sensible a mayúsculas 4 | cheat, truco 5 | computer, computadora 6 | draw, dibujar 7 | flag, bandera 8 | get, obtener 9 | I/O, E/S 10 | indentation, indentación 11 | input, entrada 12 | keyword, palabra reservada 13 | loop, bucle 14 | mouse, ratón 15 | move (noun), movida - movimiento 16 | newline (character), salto de línea 17 | output, salida 18 | punch line, remate del chiste (en el contexto de un chiste) 19 | random, aleatorio 20 | return value, valor de retorno 21 | run, ejecutar 22 | sample run, muestra de ejecución 23 | slash, barra inclinada 24 | slicing, rebanado (ref: http://docs.python.org.ar/tutorial/3/introduction.html#listas) 25 | set, establecer 26 | set up, configurar 27 | shell, consola 28 | show, mostrar 29 | statement, sentencia 30 | trace/tracing: traza de trazado (se refiere a la ejecución linea a linea o "corrida en frío") 31 | #(pound sign), símbolo almohadilla 32 | -------------------------------------------------------------------------------- /translations/es/inventwithpython3rded_spanish.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/inventwithpython3rded_spanish.docx -------------------------------------------------------------------------------- /translations/es/src/README.md: -------------------------------------------------------------------------------- 1 | The purpose of this file is to annotate any cultural / translation issues that may occurr while translating programs source files. 2 | 3 | A glossary has been added in translations/es/ under the name of "glosario.txt" to be a reference for all translators to use the same translations. 4 | 5 | TATETI.py 6 | --------- 7 | 8 | Took the freedom of modifying line 147 to print the article preceding the noun 'jugador' / 'computadora' accordingly, since these nouns have different genders (and so do the articles). "Ground rules" should be set within other spanish translators to avoid translating differently because of regional variations in language. 9 | 10 | EVASOR.py 11 | --------- 12 | 13 | Changed the start window and game over window texts alignment since spanish texts are larger. 14 | -------------------------------------------------------------------------------- /translations/es/src/adivinaElNúmero.py: -------------------------------------------------------------------------------- 1 | # Este es el juego de adivinar el número. 2 | import random 3 | 4 | intentosRealizados = 0 5 | 6 | print('¡Hola! ¿Cómo te llamas?') 7 | miNombre = input() 8 | 9 | número = random.randint(1, 20) 10 | print('Bueno, ' + miNombre + ', estoy pensando en un número entre 1 y 20.') 11 | 12 | while intentosRealizados < 6: 13 | print('Intenta adivinar.') # Hay cuatro espacios delante de print. 14 | estimación = input() 15 | estimación = int(estimación) 16 | 17 | intentosRealizados = intentosRealizados + 1 18 | 19 | if estimación < número: 20 | print('Tu estimación es muy baja.') # Hay ocho espacios delante de print. 21 | 22 | if estimación > número: 23 | print('Tu estimación es muy alta.') 24 | 25 | if estimación == número: 26 | break 27 | 28 | if estimación == número: 29 | intentosRealizados = str(intentosRealizados) 30 | print('¡Buen trabajo, ' + miNombre + '! ¡Has adivinado mi número en ' + intentosRealizados + ' intentos!') 31 | 32 | if estimación != número: 33 | número = str(número) 34 | print('Pues no. El número que estaba pensando era ' + número) 35 | -------------------------------------------------------------------------------- /translations/es/src/animación.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time 2 | from pygame.locals import * 3 | 4 | # Establece pygame 5 | pygame.init() 6 | 7 | # Establece la ventana 8 | ANCHOVENTANA = 400 9 | ALTOVENTANA = 400 10 | windowSurface = pygame.display.set_mode((ANCHOVENTANA, ALTOVENTANA), 0, 32) 11 | pygame.display.set_caption('Animación') 12 | 13 | # Establece las variables de dirección 14 | ABAJOIZQUIERDA = 1 15 | ABAJODERECHA = 3 16 | ARRIBAIZQUIERDA = 7 17 | ARRIBADERECHA = 9 18 | 19 | VELOCIDADMOVIMIENTO = 4 20 | 21 | # Establece los colores 22 | NEGRO = (0, 0, 0) 23 | ROJO = (255, 0, 0) 24 | VERDE = (0, 255, 0) 25 | AZUL = (0, 0, 255) 26 | 27 | # Establece la estructura de datos de los bloques. 28 | b1 = {'rect':pygame.Rect(300, 80, 50, 100), 'color':ROJO, 'dir':ARRIBADERECHA} 29 | b2 = {'rect':pygame.Rect(200, 200, 20, 20), 'color':VERDE, 'dir':ARRIBAIZQUIERDA} 30 | b3 = {'rect':pygame.Rect(100, 150, 60, 60), 'color':AZUL, 'dir':ABAJOIZQUIERDA} 31 | bloques = [b1, b2, b3] 32 | 33 | # Corre el ciclo de juego 34 | while True: 35 | # Busca un evento QUIT. 36 | for evento in pygame.event.get(): 37 | if evento.type == QUIT: 38 | pygame.quit() 39 | sys.exit() 40 | 41 | # Dibuja el fondo negro sobre la superficie 42 | windowSurface.fill(NEGRO) 43 | 44 | for b in bloques: 45 | # mueve la estructura de datos de bloques 46 | if b['dir'] == ABAJOIZQUIERDA: 47 | b['rect'].left -= VELOCIDADMOVIMIENTO 48 | b['rect'].top += VELOCIDADMOVIMIENTO 49 | if b['dir'] == ABAJODERECHA: 50 | b['rect'].left += VELOCIDADMOVIMIENTO 51 | b['rect'].top += VELOCIDADMOVIMIENTO 52 | if b['dir'] == ARRIBAIZQUIERDA: 53 | b['rect'].left -= VELOCIDADMOVIMIENTO 54 | b['rect'].top -= VELOCIDADMOVIMIENTO 55 | if b['dir'] == ARRIBADERECHA: 56 | b['rect'].left += VELOCIDADMOVIMIENTO 57 | b['rect'].top -= VELOCIDADMOVIMIENTO 58 | 59 | # Verifica si el bloque se movió fuera de la ventana 60 | if b['rect'].top < 0: 61 | # el bloque se movió por arriba de la ventana 62 | if b['dir'] == ARRIBAIZQUIERDA: 63 | b['dir'] = ABAJOIZQUIERDA 64 | if b['dir'] == ARRIBADERECHA: 65 | b['dir'] = ABAJODERECHA 66 | if b['rect'].bottom > ALTOVENTANA: 67 | # el bloque se movió por debajo de la ventana 68 | if b['dir'] == ABAJOIZQUIERDA: 69 | b['dir'] = ARRIBAIZQUIERDA 70 | if b['dir'] == ABAJODERECHA: 71 | b['dir'] = ARRIBADERECHA 72 | if b['rect'].left < 0: 73 | # el bloque se movió por la izquierda de la ventana 74 | if b['dir'] == ABAJOIZQUIERDA: 75 | b['dir'] = ABAJODERECHA 76 | if b['dir'] == ARRIBAIZQUIERDA: 77 | b['dir'] = ARRIBADERECHA 78 | if b['rect'].right > ANCHOVENTANA: 79 | # el bloque se movió por la derecha de la ventana 80 | if b['dir'] == ABAJODERECHA: 81 | b['dir'] = ABAJOIZQUIERDA 82 | if b['dir'] == ARRIBADERECHA: 83 | b['dir'] = ARRIBAIZQUIERDA 84 | 85 | # Dibuja el bloque en la superficie 86 | pygame.draw.rect(windowSurface, b['color'], b['rect']) 87 | 88 | # Dibuja la ventana en la pantalla 89 | pygame.display.update() 90 | time.sleep(0.02) 91 | -------------------------------------------------------------------------------- /translations/es/src/bugs.py: -------------------------------------------------------------------------------- 1 | import random 2 | numero1 = random.randint(1, 10) 3 | numero2 = random.randint(1, 10) 4 | print('¿Cuánto es ' + str(numero1) + ' + ' + str(numero2) + '?') 5 | respuesta = input() 6 | if respuesta == numero1 + numero2: 7 | print('¡Correcto!') 8 | else: 9 | print('¡Nops! La respuesta es ' + str(numero1 + numero2)) 10 | -------------------------------------------------------------------------------- /translations/es/src/cereza.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/cereza.png -------------------------------------------------------------------------------- /translations/es/src/chistes.py: -------------------------------------------------------------------------------- 1 | print('¿Qué sale de la cruza entre un mono y un pato?') 2 | input() 3 | print('¡Un monopatín!') 4 | print() 5 | print('¿Porqué vuelan los pájaros pa\'l sur?') 6 | input() 7 | print('¡Porque caminando tardarían muchísimo!') 8 | print() 9 | print('¿En qué se parecen una familia, un bombero y un barco?') 10 | input() 11 | print("No sé... ¿en qué se parecen?") 12 | input() 13 | print('En que el bombero y el barco tienen casco.') 14 | input() 15 | print('¿Y la familia?', end='') 16 | print(' -Bien, gracias.') 17 | -------------------------------------------------------------------------------- /translations/es/src/cifrado.py: -------------------------------------------------------------------------------- 1 | # Cifrado Cesar 2 | 3 | TAM_MAX_CLAVE = 26 4 | 5 | def obtenerModo(): 6 | while True: 7 | print('¿Deseas encriptar o desencriptar un mensaje?') 8 | modo = input().lower() 9 | if modo in 'encriptar e desencriptar d'.split(): 10 | return modo 11 | else: 12 | print('Ingresa "encriptar" o "e" o "desencriptar" o "d"') 13 | 14 | def obtenerMensaje(): 15 | print('Ingresa tu mensaje:') 16 | return input() 17 | 18 | def obtenerClave(): 19 | clave = 0 20 | while True: 21 | print('Ingresa el número de clave (1-%s)' % (TAM_MAX_CLAVE)) 22 | clave = int(input()) 23 | if (clave >= 1 and clave <= TAM_MAX_CLAVE): 24 | return clave 25 | 26 | def obtenerMensajeTraducido(modo, mensaje, clave): 27 | if modo[0] == 'd': 28 | clave = -clave 29 | traduccion = '' 30 | 31 | for simbolo in mensaje: 32 | if simbolo.isalpha(): 33 | num = ord(simbolo) 34 | num += clave 35 | 36 | if simbolo.isupper(): 37 | if num > ord('Z'): 38 | num -= 26 39 | elif num < ord('A'): 40 | num += 26 41 | elif simbolo.islower(): 42 | if num > ord('z'): 43 | num -= 26 44 | elif num < ord('a'): 45 | num += 26 46 | 47 | traduccion += chr(num) 48 | else: 49 | traduccion += simbolo 50 | return traduccion 51 | 52 | modo = obtenerModo() 53 | mensaje = obtenerMensaje() 54 | clave = obtenerClave() 55 | 56 | print('Tu texto traducido es:') 57 | print(obtenerMensajeTraducido(modo, mensaje, clave)) 58 | -------------------------------------------------------------------------------- /translations/es/src/detecciónColisión.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | def verifSuperposiciónRects(rect1, rect2): 5 | for a, b in [(rect1, rect2), (rect2, rect1)]: 6 | # Verifica si las esquinas de a se encuentran dentro de b 7 | if ((puntoDentroDeRect(a.left, a.top, b)) or 8 | (puntoDentroDeRect(a.left, a.bottom, b)) or 9 | (puntoDentroDeRect(a.right, a.top, b)) or 10 | (puntoDentroDeRect(a.right, a.bottom, b))): 11 | return True 12 | 13 | return False 14 | 15 | def puntoDentroDeRect(x, y, rect): 16 | if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom): 17 | return True 18 | else: 19 | return False 20 | 21 | 22 | # establece el juego 23 | pygame.init() 24 | relojPrincipal = pygame.time.Clock() 25 | 26 | # establece la ventana 27 | ANCHOVENTANA = 400 28 | ALTOVENTANA = 400 29 | superficieVentana = pygame.display.set_mode((ANCHOVENTANA, ALTOVENTANA), 0, 32) 30 | pygame.display.set_caption('Deteccion de Colisiones') 31 | 32 | # establece las variables de dirección 33 | ABAJOIZQUIERDA = 1 34 | ABAJODERECHA = 3 35 | ARRIBAIZQUIERDA = 7 36 | ARRIBADERECHA = 9 37 | 38 | VELOCIDADMOVIMIENTO = 4 39 | 40 | # establece los colores 41 | NEGRO = (0, 0, 0) 42 | VERDE = (0, 255, 0) 43 | BLANCO = (255, 255, 255) 44 | 45 | # establece las estructuras de datos de comida y rebotín 46 | contadorComida = 0 47 | NUEVACOMIDA = 40 48 | TAMAÑOCOMIDA = 20 49 | rebotín = {'rect':pygame.Rect(300, 100, 50, 50), 'dir':ARRIBAIZQUIERDA} 50 | comidas = [] 51 | for i in range(20): 52 | comidas.append(pygame.Rect(random.randint(0, ANCHOVENTANA - TAMAÑOCOMIDA), random.randint(0, ALTOVENTANA - TAMAÑOCOMIDA), TAMAÑOCOMIDA, TAMAÑOCOMIDA)) 53 | 54 | # corre el bucle de juego 55 | while True: 56 | # busca un evento QUIT 57 | for evento in pygame.event.get(): 58 | if evento.type == QUIT: 59 | pygame.quit() 60 | sys.exit() 61 | 62 | contadorComida += 1 63 | if contadorComida >= NUEVACOMIDA: 64 | # añade nueva comida 65 | contadorComida = 0 66 | comidas.append(pygame.Rect(random.randint(0, ANCHOVENTANA - TAMAÑOCOMIDA), random.randint(0, ALTOVENTANA - TAMAÑOCOMIDA), TAMAÑOCOMIDA, TAMAÑOCOMIDA)) 67 | 68 | # Dibuja el fondo NEGRO sobre la superficie 69 | superficieVentana.fill(NEGRO) 70 | 71 | # Mueve la estructura de datos rebotín 72 | if rebotín['dir'] == ABAJOIZQUIERDA: 73 | rebotín['rect'].left -= VELOCIDADMOVIMIENTO 74 | rebotín['rect'].top += VELOCIDADMOVIMIENTO 75 | if rebotín['dir'] == ABAJODERECHA: 76 | rebotín['rect'].left += VELOCIDADMOVIMIENTO 77 | rebotín['rect'].top += VELOCIDADMOVIMIENTO 78 | if rebotín['dir'] == ARRIBAIZQUIERDA: 79 | rebotín['rect'].left -= VELOCIDADMOVIMIENTO 80 | rebotín['rect'].top -= VELOCIDADMOVIMIENTO 81 | if rebotín['dir'] == ARRIBADERECHA: 82 | rebotín['rect'].left += VELOCIDADMOVIMIENTO 83 | rebotín['rect'].top -= VELOCIDADMOVIMIENTO 84 | 85 | # Verifica si rebotín se movió fuera de la ventana 86 | if rebotín['rect'].top < 0: 87 | # rebotín se movió por arriba de la ventana 88 | if rebotín['dir'] == ARRIBAIZQUIERDA: 89 | rebotín['dir'] = ABAJOIZQUIERDA 90 | if rebotín['dir'] == ARRIBADERECHA: 91 | rebotín['dir'] = ABAJODERECHA 92 | if rebotín['rect'].bottom > ALTOVENTANA: 93 | # rebotín se movió por debajo de la ventana 94 | if rebotín['dir'] == ABAJOIZQUIERDA: 95 | rebotín['dir'] = ARRIBAIZQUIERDA 96 | if rebotín['dir'] == ABAJODERECHA: 97 | rebotín['dir'] = ARRIBADERECHA 98 | if rebotín['rect'].left < 0: 99 | # rebotín se movió por la izquierda de la ventana 100 | if rebotín['dir'] == ABAJOIZQUIERDA: 101 | rebotín['dir'] = ABAJODERECHA 102 | if rebotín['dir'] == ARRIBAIZQUIERDA: 103 | rebotín['dir'] = ARRIBADERECHA 104 | if rebotín['rect'].right > ANCHOVENTANA: 105 | # rebotín se movió por la derecha de la ventana 106 | if rebotín['dir'] == ABAJODERECHA: 107 | rebotín['dir'] = ABAJOIZQUIERDA 108 | if rebotín['dir'] == ARRIBADERECHA: 109 | rebotín['dir'] = ARRIBAIZQUIERDA 110 | 111 | # Dibuja a rebotín en la superficie 112 | pygame.draw.rect(superficieVentana, BLANCO, rebotín['rect']) 113 | 114 | # Verifica si rebotín intersectó algun cuadrado de comida 115 | for comida in comidas[:]: 116 | if verifSuperposiciónRects(rebotín['rect'], comida): 117 | comidas.remove(comida) 118 | 119 | # Dibuja la comida 120 | for i in range(len(comidas)): 121 | pygame.draw.rect(superficieVentana, VERDE, comidas[i]) 122 | 123 | # Dibuja la ventana en la pantalla 124 | pygame.display.update() 125 | relojPrincipal.tick(40) 126 | -------------------------------------------------------------------------------- /translations/es/src/dragón.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def mostrarIntroducción(): 5 | print('Estás en una tierra llena de dragones. Frente a tí') 6 | print('hay dos cuevas. En una de ellas, el dragón es generoso y') 7 | print('amigable y compartirá su tesoro contigo. El otro dragón') 8 | print('es codicioso y está hambriento, y te devorará inmediatamente.') 9 | print() 10 | 11 | def elegirCueva(): 12 | cueva = '' 13 | while cueva != '1' and cueva != '2': 14 | print('¿A qué cueva quieres entrar? (1 ó 2)') 15 | cueva = input() 16 | 17 | return cueva 18 | 19 | def explorarCueva(cuevaElegida): 20 | print('Te aproximas a la cueva...') 21 | time.sleep(2) 22 | print('Es oscura y espeluznante...') 23 | time.sleep(2) 24 | print('¡Un gran dragon aparece súbitamente frente a tí! Abre sus fauces y...') 25 | print() 26 | time.sleep(2) 27 | 28 | cuevaAmigable = random.randint(1, 2) 29 | 30 | if cuevaElegida == str(cuevaAmigable): 31 | print('¡Te regala su tesoro!') 32 | else: 33 | print('¡Te engulle de un bocado!') 34 | 35 | jugarDeNuevo = 'sí' 36 | while jugarDeNuevo == 'sí' or jugarDeNuevo == 's': 37 | 38 | mostrarIntroducción() 39 | 40 | númeroDeCueva = elegirCueva() 41 | 42 | explorarCueva(númeroDeCueva) 43 | 44 | print('¿Quieres jugar de nuevo? (sí o no)') 45 | jugarDeNuevo = input() 46 | -------------------------------------------------------------------------------- /translations/es/src/hola.py: -------------------------------------------------------------------------------- 1 | # Este programa saluda y pregunta por mi nombre. 2 | print('¡Hola Mundo!') 3 | print('¿Cómo te llamas?') 4 | miNombre = input() 5 | print('Es un placer conocerte, ' + miNombre) 6 | -------------------------------------------------------------------------------- /translations/es/src/juegoterminado.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/juegoterminado.wav -------------------------------------------------------------------------------- /translations/es/src/jugador.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/jugador.png -------------------------------------------------------------------------------- /translations/es/src/lanzarMoneda.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Lanzaré una moneda 1000 veces. Adivina cuantas veces caerá Cara. (Presiona enter para comenzar)') 3 | input() 4 | lanzamientos = 0 5 | caras = 0 6 | while lanzamientos < 1000: 7 | if random.randint(0, 1) == 1: 8 | caras = caras + 1 9 | lanzamientos = lanzamientos + 1 10 | 11 | if lanzamientos == 900: 12 | print('900 lanzamientos y hubo ' + str(caras) + ' caras.') 13 | if lanzamientos == 100: 14 | print('En 100 lanzamientos, cara salió ' + str(caras) + ' veces.') 15 | if lanzamientos == 500: 16 | print('La mitad de los lanzamientos y cara salió ' + str(caras) + ' veces.') 17 | 18 | print() 19 | print('De 1000 lanzamientos, al final cara salió ' + str(caras) + ' veces!') 20 | print('¿Estuviste cerca?') -------------------------------------------------------------------------------- /translations/es/src/musicaDeFondo.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/musicaDeFondo.mid -------------------------------------------------------------------------------- /translations/es/src/panecillos.py: -------------------------------------------------------------------------------- 1 | import random 2 | def obtenerNumSecreto(digitosNum): 3 | # Devuelve un numero de largo digotosNUm, compuesto de dígitos únicos al azar. 4 | numeros = list(range(10)) 5 | random.shuffle(numeros) 6 | numSecreto = '' 7 | for i in range(digitosNum): 8 | numSecreto += str(numeros[i]) 9 | return numSecreto 10 | 11 | def obtenerPistas(conjetura, numSecreto): 12 | # Devuelve una palabra con las pistas Panecillos Pico y Fermi en ella. 13 | if conjetura == numSecreto: 14 | return '¡Lo has adivinado!' 15 | 16 | pista = [] 17 | 18 | for i in range(len(conjetura)): 19 | if conjetura[i] == numSecreto[i]: 20 | pista.append('Fermi') 21 | elif conjetura[i] in numSecreto: 22 | pista.append('Pico') 23 | if len(pista) == 0: 24 | return 'Panecillos' 25 | 26 | pista.sort() 27 | return ' '.join(pista) 28 | 29 | def esSoloDigitos(num): 30 | # Devuelve True si el número se compone sólo de dígitos. De lo contrario Falso. 31 | if num == '': 32 | return False 33 | 34 | for i in num: 35 | if i not in '0 1 2 3 4 5 6 7 8 9'.split(): 36 | return False 37 | 38 | return True 39 | 40 | def jugarDeNuevo(): 41 | # Esta funcion devuelve True si el jugador desea vovler a jugar, de lo contrario Falso. 42 | print('¿Deseas volver a jugar? (sí o no)') 43 | return input().lower().startswith('s') 44 | 45 | digitosNum = 3 46 | MAXADIVINANZAS = 10 47 | 48 | print('Estoy pensando en un número de %s dígitos. Intenta adivinar cuál es.' % (digitosNum)) 49 | print('Aquí hay algunas pistas:') 50 | print('Cuando digo: Eso significa:') 51 | print(' Pico Un dígito es correcto pero en la posición incorrecta.') 52 | print(' Fermi Un dígito es correcto y en la posición correcta.') 53 | print(' Panecillos Ningún dígito es correcto.') 54 | 55 | while True: 56 | numSecreto = obtenerNumSecreto(digitosNum) 57 | print('He pensado un número. Tienes %s intentos para adivinarlo.' % (MAXADIVINANZAS)) 58 | 59 | numIntentos = 1 60 | while numIntentos <= MAXADIVINANZAS: 61 | conjetura = '' 62 | while len(conjetura) != digitosNum or not esSoloDigitos(conjetura): 63 | print('Conjetura #%s: ' % (numIntentos)) 64 | conjetura = input() 65 | 66 | pista = obtenerPistas(conjetura, numSecreto) 67 | print(pista) 68 | numIntentos += 1 69 | 70 | if conjetura == numSecreto: 71 | break 72 | if numIntentos > MAXADIVINANZAS: 73 | print('Te has quedado sin intentos. La respuesta era %s.' % (numSecreto)) 74 | 75 | if not jugarDeNuevo(): 76 | break 77 | -------------------------------------------------------------------------------- /translations/es/src/pygameEntrada.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | # configurar pygame 5 | pygame.init() 6 | relojPrincipal = pygame.time.Clock() 7 | 8 | # configurar la ventana 9 | ANCHOVENTANA = 400 10 | ALTURAVENTANA = 400 11 | superficieVentana = pygame.display.set_mode((ANCHOVENTANA, ALTURAVENTANA), 0, 32) 12 | pygame.display.set_caption('Entrada') 13 | 14 | # configurar los colores 15 | NEGRO = (0, 0, 0) 16 | VERDE = (0, 255, 0) 17 | BLANCO = (255, 255, 255) 18 | 19 | # configurar estructura de datos del jugador y la comida 20 | contadorDeComida = 0 21 | NUEVACOMIDA = 40 22 | TAMAÑOCOMIDA = 20 23 | jugador = pygame.Rect(300, 100, 50, 50) 24 | comidas = [] 25 | for i in range(20): 26 | comidas.append(pygame.Rect(random.randint(0, ANCHOVENTANA - TAMAÑOCOMIDA), random.randint(0, ALTURAVENTANA - TAMAÑOCOMIDA), TAMAÑOCOMIDA, TAMAÑOCOMIDA)) 27 | 28 | # configurar variables de movimiento 29 | moverseIzquierda = False 30 | moverseDerecha = False 31 | moverseArriba = False 32 | moverseAbajo = False 33 | 34 | VELOCIDADMOVIMIENTO = 6 35 | 36 | 37 | # ejecutar el bucle del juego 38 | while True: 39 | # comprobar eventos 40 | for evento in pygame.event.get(): 41 | if evento.type == QUIT: 42 | pygame.quit() 43 | sys.exit() 44 | if evento.type == KEYDOWN: 45 | # cambiar las variables del teclado 46 | if evento.key == K_LEFT or evento.key == ord('a'): 47 | moverseDerecha = False 48 | moverseIzquierda = True 49 | if evento.key == K_RIGHT or evento.key == ord('d'): 50 | moverseIzquierda = False 51 | moverseDerecha = True 52 | if evento.key == K_UP or evento.key == ord('w'): 53 | moverseAbajo = False 54 | moverseArriba = True 55 | if evento.key == K_DOWN or evento.key == ord('s'): 56 | moverseArriba = False 57 | moverseAbajo = True 58 | if evento.type == KEYUP: 59 | if evento.key == K_ESCAPE: 60 | pygame.quit() 61 | sys.exit() 62 | if evento.key == K_LEFT or evento.key == ord('a'): 63 | moverseIzquierda = False 64 | if evento.key == K_RIGHT or evento.key == ord('d'): 65 | moverseDerecha = False 66 | if evento.key == K_UP or evento.key == ord('w'): 67 | moverseArriba = False 68 | if evento.key == K_DOWN or evento.key == ord('s'): 69 | moverseAbajo = False 70 | if evento.key == ord('x'): 71 | jugador.top = random.randint(0, ALTURAVENTANA - jugador.height) 72 | jugador.left = random.randint(0, ANCHOVENTANA - jugador.width) 73 | 74 | if evento.type == MOUSEBUTTONUP: 75 | comidas.append(pygame.Rect(evento.pos[0], evento.pos[1], TAMAÑOCOMIDA, TAMAÑOCOMIDA)) 76 | 77 | contadorDeComida += 1 78 | if contadorDeComida >= NUEVACOMIDA: 79 | # agregar nueva comida 80 | contadorDeComida = 0 81 | comidas.append(pygame.Rect(random.randint(0, ANCHOVENTANA - TAMAÑOCOMIDA), random.randint(0, ALTURAVENTANA - TAMAÑOCOMIDA), TAMAÑOCOMIDA, TAMAÑOCOMIDA)) 82 | 83 | # dibujar el fondo negro sobre la superficie 84 | superficieVentana.fill(NEGRO) 85 | 86 | # mover al jugador 87 | if moverseAbajo and jugador.bottom < ALTURAVENTANA: 88 | jugador.top += VELOCIDADMOVIMIENTO 89 | if moverseArriba and jugador.top > 0: 90 | jugador.top -= VELOCIDADMOVIMIENTO 91 | if moverseIzquierda and jugador.left > 0: 92 | jugador.left -= VELOCIDADMOVIMIENTO 93 | if moverseDerecha and jugador.right < ANCHOVENTANA: 94 | jugador.right += VELOCIDADMOVIMIENTO 95 | 96 | # dibujar al jugador sobre la superficie 97 | pygame.draw.rect(superficieVentana, BLANCO, jugador) 98 | 99 | # comprobar si el jugador ha intersectado alguno de los cuadrados de comida 100 | for comida in comidas[:]: 101 | if jugador.colliderect(comida): 102 | comidas.remove(comida) 103 | 104 | # dibujar la comida 105 | for i in range(len(comidas)): 106 | pygame.draw.rect(superficieVentana, VERDE, comidas[i]) 107 | 108 | # dibujar la ventana sobre la pantalla 109 | pygame.display.update() 110 | relojPrincipal.tick(40) 111 | -------------------------------------------------------------------------------- /translations/es/src/pygameHolaMundo.py: -------------------------------------------------------------------------------- 1 | import pygame, sys 2 | from pygame.locals import * 3 | 4 | # configurar pygame 5 | pygame.init() 6 | 7 | # configurar la ventana 8 | superficieVentana = pygame.display.set_mode((500, 400), 0, 32) 9 | pygame.display.set_caption('¡Hola mundo!') 10 | 11 | # configurar los colores 12 | NEGRO = (0, 0, 0) 13 | BLANCO = (255, 255, 255) 14 | ROJO = (255, 0, 0) 15 | VERDE = (0, 255, 0) 16 | AZUL = (0, 0, 255) 17 | 18 | # configurar fuentes 19 | fuenteBásica = pygame.font.SysFont(None, 48) 20 | 21 | # configurar el texto 22 | texto = fuenteBásica.render('¡Hola mundo!', True, BLANCO, AZUL) 23 | textRect = texto.get_rect() 24 | textRect.centerx = superficieVentana.get_rect().centerx 25 | textRect.centery = superficieVentana.get_rect().centery 26 | 27 | # pintar un fondo blanco sobre la ventana 28 | superficieVentana.fill(BLANCO) 29 | 30 | # dibujar un polígono verde sobre la superficie 31 | pygame.draw.polygon(superficieVentana, VERDE, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))) 32 | 33 | # dibujar algunas líneas azules sobre la superficie 34 | pygame.draw.line(superficieVentana, AZUL, (60, 60), (120, 60), 4) 35 | pygame.draw.line(superficieVentana, AZUL, (120, 60), (60, 120)) 36 | pygame.draw.line(superficieVentana, AZUL, (60, 120), (120, 120), 4) 37 | 38 | # dibujar un círculo azul sobre la superficie 39 | pygame.draw.circle(superficieVentana, AZUL, (300, 50), 20, 0) 40 | 41 | # dibujar una elipse roja sobre la superficie 42 | pygame.draw.ellipse(superficieVentana, ROJO, (300, 250, 40, 80), 1) 43 | 44 | # dibujar el rectángulo de fondo para el texto sobre la superficie 45 | pygame.draw.rect(superficieVentana, ROJO, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40)) 46 | 47 | # obtener un arreglo de píxeles de la superficie 48 | arregloDePíxeles = pygame.PixelArray(superficieVentana) 49 | arregloDePíxeles[480][380] = NEGRO 50 | del arregloDePíxeles 51 | 52 | # dibujar el texto sobre la superficie 53 | superficieVentana.blit(texto, textRect) 54 | 55 | # dibujar la ventana sobre la pantalla 56 | pygame.display.update() 57 | 58 | # ejecutar el bucle del juego 59 | while True: 60 | for event in pygame.event.get(): 61 | if event.type == QUIT: 62 | pygame.quit() 63 | sys.exit() 64 | -------------------------------------------------------------------------------- /translations/es/src/recolección.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/recolección.wav -------------------------------------------------------------------------------- /translations/es/src/villano.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/src/villano.png -------------------------------------------------------------------------------- /translations/es/text/capítulo1.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | ¡Asegúrate de instalar Python 3, no Python 2! -------------------------------------------------------------------------------- /translations/es/text/capítulo10.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 10-1: 2 | Inicio 3 | Preguntar la letra del jugador. 4 | Decidir quién comienza. 5 | Turno del Jugador 6 | Mostrar el tablero. 7 | Obtener jugada del jugador. 8 | Comprobar si el jugador ha ganado. 9 | Comprobar si ha sido un empate. 10 | Turno de la Computadora 11 | Obtener movimiento de la computadora. 12 | Comprobar si la computadora ha ganado. 13 | Comprobar si ha sido un empate. 14 | Preguntar al jugador si desea jugar de nuevo. 15 | Fin 16 | 17 | Fig 10-3: 18 | Esquina 19 | Lado 20 | Centro 21 | 22 | Fig 10-4: 23 | 1. Hacer jugada ganadora. 24 | 2. Bloquear la jugada ganadora del jugador. 25 | 3. Jugar en una esquina. 26 | 4. Jugar en el centro. 27 | 5. Jugar en un lado. 28 | 29 | Fig 10-5: 30 | Referencia 31 | (un valor de lista) 32 | 33 | -------------------------------------------------------------------------------- /translations/es/text/capítulo11.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 11-1: 2 | Inicio 3 | Generar número secreto. 4 | Ver si el jugador se ha quedado sin intentos. 5 | Obtener conjetura del jugador. 6 | Dar pistas al jugador. 7 | Incrementar el número de intentos. 8 | Preguntar al jugador si desea volver a jugar. 9 | El jugador ha perdido. 10 | El jugador ha ganado. 11 | Fin 12 | 13 | -------------------------------------------------------------------------------- /translations/es/text/capítulo12.figuras.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/text/capítulo12.figuras.txt -------------------------------------------------------------------------------- /translations/es/text/capítulo14.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo15.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 15-7: 2 | X aumenta 3 | Y aumenta -------------------------------------------------------------------------------- /translations/es/text/capítulo16.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo17.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 17-3: 2 | ¡Programar es divertido! 3 | 4 | Fig 17-4: 5 | Sin antialiasing 6 | Con antialiasing 7 | 8 | -------------------------------------------------------------------------------- /translations/es/text/capítulo18.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 18-2: 2 | Rectángulos Superpuestos 3 | Rectángulos No Superpuestos 4 | 5 | -------------------------------------------------------------------------------- /translations/es/text/capítulo19.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo2.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 2-3: 2 | valor 3 | operador 4 | expresión 5 | 6 | Fig 2-4: 7 | spam 8 | 9 | Fig 2-5: 10 | eggs 11 | fizz 12 | -------------------------------------------------------------------------------- /translations/es/text/capítulo20.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo3.figuras.txt: -------------------------------------------------------------------------------- 1 | Ninguna. -------------------------------------------------------------------------------- /translations/es/text/capítulo4.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 4-2: 2 | ...ve dentro del bloque while, aquí. 3 | ...ve más allá del bloque while, aquí. 4 | 5 | Fig 4-3: 6 | fizzy 7 | palabra reservada if 8 | condición 9 | palabra reservada while 10 | -------------------------------------------------------------------------------- /translations/es/text/capítulo5.figuras.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/es/text/capítulo5.figuras.txt -------------------------------------------------------------------------------- /translations/es/text/capítulo6.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 6-1: 2 | palabra reservada def 3 | paréntesis 4 | nombre de la función 5 | dos puntos 6 | 7 | Fig 6-2: 8 | Inicio 9 | Mostrar introducción 10 | Jugador elige una cueva 11 | Comprobar dragón amistoso o hambriento 12 | Jugador gana 13 | Jugador pierde 14 | Ofrece jugar de nuevo 15 | Fin 16 | 17 | -------------------------------------------------------------------------------- /translations/es/text/capítulo7.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo8.figuras.txt: -------------------------------------------------------------------------------- 1 | Fig 8-1 a 8-9: 2 | Inicio 3 | Generar una palabra secreta. 4 | Mostrar el tablero y los espacios vacíos al jugador. 5 | Invitar al jugador a adivinar una letra. 6 | El jugador ya ha probado esa letra. 7 | La letra está en la palabra secreta. 8 | La letra no está en la palabra secreta. 9 | El jugador ha adivinado todas las letras y gana. 10 | El jugador se ha quedado sin partes del cuerpo y pierde. 11 | Preguntar al jugador si quiere jugar de nuevo. 12 | Fin 13 | -------------------------------------------------------------------------------- /translations/es/text/capítulo9.5.figuras.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/es/text/capítulo9.figures.txt: -------------------------------------------------------------------------------- 1 | Ninguna. -------------------------------------------------------------------------------- /translations/fi/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/fr/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 7 | 8 | Title 9 | ===== 10 | 11 | (Put translated book title here.) 12 | 13 | General Notes 14 | ============= 15 | 16 | (Add notes for other translators here.) -------------------------------------------------------------------------------- /translations/fr/fr_figures.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | Soyez sûr d'installer Python 3, et non pas Python 2 ! 3 | 4 | Fig 2-3: 5 | valeur 6 | opérateur 7 | expression 8 | 9 | Fig 2-4: 10 | spam 11 | 12 | Fig 2-5: 13 | eggs 14 | fizz 15 | -------------------------------------------------------------------------------- /translations/fr/src/PileFace.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Je vais jouer à Pile ou Face, 1000 fois. Devinez combien de pile vont sortir (Appuyez sur Entrée pour commencer)') 3 | input() 4 | lances = 0 5 | piles = 0 6 | while lances < 1000: 7 | if random.randint(0, 1) == 1: 8 | piles = piles + 1 9 | lances = lances + 1 10 | 11 | if lances == 900: 12 | print('900 lancés et il y a eu ' + str(piles) + ' pile.') 13 | if lances == 100: 14 | print('A 100 lancés, pile est sorti ' + str(piles) + ' fois jusque là.') 15 | if lances == 500: 16 | print('Mi-parcours, et pile est sorti ' + str(piles) + ' fois.') 17 | 18 | print() 19 | print('Après 1000 lancés de pièces, pile est sorti ' + str(piles) + ' fois !') 20 | print('Etiez-vous proche ?') 21 | -------------------------------------------------------------------------------- /translations/fr/src/bogue.py: -------------------------------------------------------------------------------- 1 | import random 2 | nombre1 = random.randint(1, 10) 3 | nombre2 = random.randint(1, 10) 4 | print('Combien fait ' + str(nombre1) + ' + ' + str(nombre2) + ' ?') 5 | reponse = input() 6 | if int(reponse) == nombre1 + nombre2: 7 | print('Correct!') 8 | else: 9 | print('Raté ! La réponse est ' + str(nombre1 + nombre2)) 10 | -------------------------------------------------------------------------------- /translations/fr/src/bonjour.py: -------------------------------------------------------------------------------- 1 | # Ce programme affiche bonjour et demande votre nom. 2 | print('Bonjour le Monde !') 3 | print('Quel est votre nom ?') 4 | monNom = input() 5 | print('Je suis ravi de vous connaitre , ' + monNom) 6 | -------------------------------------------------------------------------------- /translations/fr/src/devine.py: -------------------------------------------------------------------------------- 1 | # Ceci est un jeu deviner un nombre 2 | import random 3 | 4 | tentative = 0 5 | 6 | print('Bonjour ! Quel est votre nom ?') 7 | monNom = input() 8 | 9 | nombre = random.randint(1, 20) 10 | print('Bien, ' + monNom + ', Je choisis un nombre entre 1 et 20.') 11 | 12 | while tentative < 6: 13 | print('Faites votre choix.') # Il y a 4 espaces avant le print. 14 | choix = input() 15 | choix = int(choix) 16 | 17 | tentative = tentative + 1 18 | 19 | if choix < nombre: 20 | 21 | print('Votre choix est trop bas.') # There are eight spaces in front of print. 22 | 23 | if choix > nombre: 24 | print('Votre choix est trop haut.') 25 | 26 | if choix == nombre: 27 | break 28 | 29 | if choix == nombre: 30 | tentative = str(tentative) 31 | print('Bien joué, ' + monNom + '! Vous avez devinez mon nombre en ' + tentative + ' tentatives !') 32 | 33 | if choix != nombre: 34 | nombre = str(nombre) 35 | print('Raté. Le nombre que j''avais choisi était ' + nombre) 36 | -------------------------------------------------------------------------------- /translations/hr/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | Veky 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/id/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | - Ben Bernard ([https://github.com/bbn-bernard](https://github.com/bbn-bernard)) 5 | - Daya Adianto ([https://github.com/addianto](https://github.com/addianto)) 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | ## Convention ## 18 | 19 | - use "aku" and "kamu" 20 | - "Bab" for "chapter", dan "bagian" for "section" 21 | - "wrapped" <-> "terlipat" with text/paragraph context 22 | 23 | ## Glossary ## 24 | 25 | - chapter, bab 26 | - section, bagian 27 | - run, menjalankan dalam konteks program 28 | - software, perangkat lunak 29 | - wrapped, terlipat dalam konteks paragraf atau teks 30 | - concatenation, perangkaian 31 | - assigment, pengisian atau subtitusi bilangan ke variabel 32 | - integer, bilangan bulat 33 | - float, float atau bilangan dengan tanda koma 34 | - cursor, kursor 35 | - source code, sumber kode 36 | - tool, perkakas 37 | - passing, melempar 38 | - return value, nilai kembalian 39 | - loop, putaran iterasi 40 | - module, module dalam konteks Python 41 | - import, import dalam konteks Python 42 | - increment, meningkatkan suatu variabel 43 | - decrement, merendahkan suatu variabel 44 | - programmer 45 | - interpeter 46 | - shell 47 | - online 48 | - domain 49 | - post 50 | - tracing 51 | - newline 52 | - backslash 53 | - forward slash 54 | - keyword 55 | - floating point 56 | - games 57 | - video games 58 | - keyboard 59 | - prompt 60 | - string 61 | - case-sensitivity 62 | - file editor 63 | - shortcut 64 | - build-in 65 | - argument 66 | - bug, bug, ngebug 67 | - mouse 68 | - debugger, debugger 69 | - step into, melangkah masuk dalam konteks debugger 70 | - step over, melangkah melalui dalam konteks debugger 71 | - step out, melangkah keluar dalam konteks debugger 72 | - Go, lanjutkan dalam konteks debugger 73 | - Quit, keluar dalam konteks debugger 74 | - breakpoint, titik henti dalam konteks debugger 75 | - runtime, runtime 76 | - crash, crash 77 | - infinite loop, putaran takhingga 78 | - checkbox, checkbox 79 | - scope, cakupan 80 | - debug, debug 81 | - parantheses, tanda kurung buka-tutup 82 | - main, main dalam konteks main method program Python 83 | - def-block, blok def 84 | - while-block, blok while 85 | -------------------------------------------------------------------------------- /translations/id/src/animasi.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time 2 | from pygame.locals import * 3 | 4 | # menyiapkan pygame 5 | pygame.init() 6 | 7 | # menyiapkan jendela 8 | WINDOWWIDTH = 400 9 | WINDOWHEIGHT = 400 10 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 11 | pygame.display.set_caption('Animasi') 12 | 13 | # menyiapakan variabel arah 14 | DOWNLEFT = 1 15 | DOWNRIGHT = 3 16 | UPLEFT = 7 17 | UPRIGHT = 9 18 | 19 | MOVESPEED = 4 20 | 21 | # menyiapkan warna 22 | BLACK = (0, 0, 0) 23 | RED = (255, 0, 0) 24 | GREEN = (0, 255, 0) 25 | BLUE = (0, 0, 255) 26 | 27 | # menyiapkan struktur data blok 28 | b1 = {'rect':pygame.Rect(300, 80, 50, 100), 'color':RED, 'dir':UPRIGHT} 29 | b2 = {'rect':pygame.Rect(200, 200, 20, 20), 'color':GREEN, 'dir':UPLEFT} 30 | b3 = {'rect':pygame.Rect(100, 150, 60, 60), 'color':BLUE, 'dir':DOWNLEFT} 31 | blocks = [b1, b2, b3] 32 | 33 | # mulai putaran game 34 | while True: 35 | # cek peristiwa QUIT 36 | for event in pygame.event.get(): 37 | if event.type == QUIT: 38 | pygame.quit() 39 | sys.exit() 40 | 41 | # gambar latar belakang hitam pada surface 42 | windowSurface.fill(BLACK) 43 | 44 | for b in blocks: 45 | # pindahkan struktur data blok 46 | if b['dir'] == DOWNLEFT: 47 | b['rect'].left -= MOVESPEED 48 | b['rect'].top += MOVESPEED 49 | if b['dir'] == DOWNRIGHT: 50 | b['rect'].left += MOVESPEED 51 | b['rect'].top += MOVESPEED 52 | if b['dir'] == UPLEFT: 53 | b['rect'].left -= MOVESPEED 54 | b['rect'].top -= MOVESPEED 55 | if b['dir'] == UPRIGHT: 56 | b['rect'].left += MOVESPEED 57 | b['rect'].top -= MOVESPEED 58 | 59 | # cek apakah blok sudah pindah keluar jendela 60 | if b['rect'].top < 0: 61 | # blok sudah pindah melewati bagian atas 62 | if b['dir'] == UPLEFT: 63 | b['dir'] = DOWNLEFT 64 | if b['dir'] == UPRIGHT: 65 | b['dir'] = DOWNRIGHT 66 | if b['rect'].bottom > WINDOWHEIGHT: 67 | # blok sudah pindah melewati bagian bawah 68 | if b['dir'] == DOWNLEFT: 69 | b['dir'] = UPLEFT 70 | if b['dir'] == DOWNRIGHT: 71 | b['dir'] = UPRIGHT 72 | if b['rect'].left < 0: 73 | # blok sudah pindah melewati sisi kiri 74 | if b['dir'] == DOWNLEFT: 75 | b['dir'] = DOWNRIGHT 76 | if b['dir'] == UPLEFT: 77 | b['dir'] = UPRIGHT 78 | if b['rect'].right > WINDOWWIDTH: 79 | # blok sudah pindah melewati sisi kanan 80 | if b['dir'] == DOWNRIGHT: 81 | b['dir'] = DOWNLEFT 82 | if b['dir'] == UPRIGHT: 83 | b['dir'] = UPLEFT 84 | 85 | # gambar blok ke dalam surface 86 | pygame.draw.rect(windowSurface, b['color'], b['rect']) 87 | 88 | # gambar jendela ke layar 89 | pygame.display.update() 90 | time.sleep(0.02) 91 | -------------------------------------------------------------------------------- /translations/id/src/deteksiTumbukan.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | def doRectsOverlap(rect1, rect2): 5 | for a, b in [(rect1, rect2), (rect2, rect1)]: 6 | # cek apakah sudut a ada dalam b 7 | if ((isPointInsideRect(a.left, a.top, b)) or 8 | (isPointInsideRect(a.left, a.bottom, b)) or 9 | (isPointInsideRect(a.right, a.top, b)) or 10 | (isPointInsideRect(a.right, a.bottom, b))): 11 | return True 12 | 13 | return False 14 | 15 | def isPointInsideRect(x, y, rect): 16 | if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom): 17 | return True 18 | else: 19 | return False 20 | 21 | 22 | # menyiapkan pygame 23 | pygame.init() 24 | mainClock = pygame.time.Clock() 25 | 26 | # menyiapakan jendela 27 | WINDOWWIDTH = 400 28 | WINDOWHEIGHT = 400 29 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 30 | pygame.display.set_caption('Collision Detection') 31 | 32 | # menyiapkan variabel arah 33 | DOWNLEFT = 1 34 | DOWNRIGHT = 3 35 | UPLEFT = 7 36 | UPRIGHT = 9 37 | 38 | MOVESPEED = 4 39 | 40 | # menyiapakan warna 41 | BLACK = (0, 0, 0) 42 | GREEN = (0, 255, 0) 43 | WHITE = (255, 255, 255) 44 | 45 | # menyiapkan pemantul dan data struktur makanan 46 | foodCounter = 0 47 | NEWFOOD = 40 48 | FOODSIZE = 20 49 | bouncer = {'rect':pygame.Rect(300, 100, 50, 50), 'dir':UPLEFT} 50 | foods = [] 51 | for i in range(20): 52 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 53 | 54 | # menjalankan putaran game 55 | while True: 56 | # cek apakah ada peristiwa QUIT 57 | for event in pygame.event.get(): 58 | if event.type == QUIT: 59 | pygame.quit() 60 | sys.exit() 61 | 62 | foodCounter += 1 63 | if foodCounter >= NEWFOOD: 64 | # tambah makanan baru 65 | foodCounter = 0 66 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 67 | 68 | # gambar latar belakang hitam pada permukaan 69 | windowSurface.fill(BLACK) 70 | 71 | # pindahkan data struktur pemantul 72 | if bouncer['dir'] == DOWNLEFT: 73 | bouncer['rect'].left -= MOVESPEED 74 | bouncer['rect'].top += MOVESPEED 75 | if bouncer['dir'] == DOWNRIGHT: 76 | bouncer['rect'].left += MOVESPEED 77 | bouncer['rect'].top += MOVESPEED 78 | if bouncer['dir'] == UPLEFT: 79 | bouncer['rect'].left -= MOVESPEED 80 | bouncer['rect'].top -= MOVESPEED 81 | if bouncer['dir'] == UPRIGHT: 82 | bouncer['rect'].left += MOVESPEED 83 | bouncer['rect'].top -= MOVESPEED 84 | 85 | # cek apakah pemantul sudah pindah keluar jendela 86 | if bouncer['rect'].top < 0: 87 | # pemantul sudah melewati sisi atas jendela 88 | if bouncer['dir'] == UPLEFT: 89 | bouncer['dir'] = DOWNLEFT 90 | if bouncer['dir'] == UPRIGHT: 91 | bouncer['dir'] = DOWNRIGHT 92 | if bouncer['rect'].bottom > WINDOWHEIGHT: 93 | # pemantul sudah melewati sisi bawah jendela 94 | if bouncer['dir'] == DOWNLEFT: 95 | bouncer['dir'] = UPLEFT 96 | if bouncer['dir'] == DOWNRIGHT: 97 | bouncer['dir'] = UPRIGHT 98 | if bouncer['rect'].left < 0: 99 | # pemantul sudah melewati sisi kiri jendela 100 | if bouncer['dir'] == DOWNLEFT: 101 | bouncer['dir'] = DOWNRIGHT 102 | if bouncer['dir'] == UPLEFT: 103 | bouncer['dir'] = UPRIGHT 104 | if bouncer['rect'].right > WINDOWWIDTH: 105 | # pemantul sudah melewati sisi kanan jendela 106 | if bouncer['dir'] == DOWNRIGHT: 107 | bouncer['dir'] = DOWNLEFT 108 | if bouncer['dir'] == UPRIGHT: 109 | bouncer['dir'] = UPLEFT 110 | 111 | # gambar pemantul pada permukaan 112 | pygame.draw.rect(windowSurface, WHITE, bouncer['rect']) 113 | 114 | # cek apakah pemantul saling tumpang tindih dengan kotak makanan. 115 | for food in foods[:]: 116 | if doRectsOverlap(bouncer['rect'], food): 117 | foods.remove(food) 118 | 119 | # gambar makanan 120 | for i in range(len(foods)): 121 | pygame.draw.rect(windowSurface, GREEN, foods[i]) 122 | 123 | # gambar jendela pada layar 124 | pygame.display.update() 125 | mainClock.tick(40) 126 | -------------------------------------------------------------------------------- /translations/id/src/halo.py: -------------------------------------------------------------------------------- 1 | # Program ini berkata halo dan bertanya siapa namaku. 2 | print('Halo Dunia!') 3 | print('Siapa namamu?') 4 | myName = input() 5 | print('Senang bertemu denganmu, ' + myName) 6 | -------------------------------------------------------------------------------- /translations/id/src/lemparKoin.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Akan kulemparkan sebuah koin 1000 kali. Tebak berapa kali muncul kepala. (Tekan ENTER untuk memulai)') 3 | input() 4 | flips = 0 5 | heads = 0 6 | while flips < 1000: 7 | if random.randint(0, 1) == 1: 8 | heads = heads + 1 9 | flips = flips + 1 10 | 11 | if flips == 900: 12 | print('900 lembaran dan sudah muncul kepala sebanyak ' + str(heads) + ' kali.') 13 | if flips == 100: 14 | print('Setelah lemparan 100, kepala muncul ' + str(heads) + ' kali.') 15 | if flips == 500: 16 | print('Baru setengah perjalanan dan kepala telah muncul ' + str(heads) + ' kali.') 17 | 18 | print() 19 | print('Setelah 1000 kali lemparan koin, kepala muncul ' + str(heads) + ' kali!') 20 | print('Apa tebakanmu dekat?') 21 | -------------------------------------------------------------------------------- /translations/id/src/naga.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def displayIntro(): 5 | print('Kamu ada di pulau yang dihuni banyak naga. Di depanmu,') 6 | print('kamu melihat dua gua. Di salah satu gua dihuni oleh naga ramah') 7 | print('dan mau berbagi harta karun bersamamu. Naga lain') 8 | print('tamak dan lapar. Kamu bisa dimakan olehnya jika terlihat.') 9 | print() 10 | 11 | def chooseCave(): 12 | cave = '' 13 | while cave != '1' and cave != '2': 14 | print('Gua mana yang ingin kau jelajahi? (1 atau 2)') 15 | cave = input() 16 | 17 | return cave 18 | 19 | def checkCave(chosenCave): 20 | print('Kamu memasuki gua...') 21 | time.sleep(2) 22 | print('Gua ini gelap dan menakutkan...') 23 | time.sleep(2) 24 | print('Naga besar lompat didepanmu! Dia membuka mulutnya dan...') 25 | print() 26 | time.sleep(2) 27 | 28 | friendlyCave = random.randint(1, 2) 29 | 30 | if chosenCave == str(friendlyCave): 31 | print('Memberimu harta karunnya!') 32 | else: 33 | print('Mengunyahmu dalam satu gigitan!') 34 | 35 | playAgain = 'ya' 36 | while playAgain == 'ya' or playAgain == 'y': 37 | 38 | displayIntro() 39 | 40 | caveNumber = chooseCave() 41 | 42 | checkCave(caveNumber) 43 | 44 | print('Mau main lagi? (ya atau tidak)') 45 | playAgain = input() 46 | -------------------------------------------------------------------------------- /translations/id/src/ngebug.py: -------------------------------------------------------------------------------- 1 | import random 2 | number1 = random.randint(1, 10) 3 | number2 = random.randint(1, 10) 4 | print('Berapa ' + str(number1) + ' + ' + str(number2) + '?') 5 | answer = input() 6 | if answer == number1 + number2: 7 | print('Tepat!') 8 | else: 9 | print('Bukan! Jawabannya adalah ' + str(number1 + number2)) 10 | -------------------------------------------------------------------------------- /translations/id/src/pygameHaloDunia.py: -------------------------------------------------------------------------------- 1 | import pygame, sys 2 | from pygame.locals import * 3 | 4 | # menyiapkan pygame 5 | pygame.init() 6 | 7 | # menyiapkan jendela keluaran 8 | windowSurface = pygame.display.set_mode((500, 400), 0, 32) 9 | pygame.display.set_caption('Halo Dunia!') 10 | 11 | # menyiapkan warna yang dipakai 12 | BLACK = (0, 0, 0) 13 | WHITE = (255, 255, 255) 14 | RED = (255, 0, 0) 15 | GREEN = (0, 255, 0) 16 | BLUE = (0, 0, 255) 17 | 18 | # menyiapkan font yang dipakai 19 | basicFont = pygame.font.SysFont(None, 48) 20 | 21 | # menyiapkan teks 22 | text = basicFont.render('Halo Dunia!', True, WHITE, BLUE) 23 | textRect = text.get_rect() 24 | textRect.centerx = windowSurface.get_rect().centerx 25 | textRect.centery = windowSurface.get_rect().centery 26 | 27 | # menggambar latar belakang putih pada surface 28 | windowSurface.fill(WHITE) 29 | 30 | # menggambar segibanyak hijau pada surface 31 | pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))) 32 | 33 | # menggambar beberapa garis biru pada surface 34 | pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4) 35 | pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120)) 36 | pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4) 37 | 38 | # menggambar lingkaran biru pada surface 39 | pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0) 40 | 41 | # menggambar elips merah pada surface 42 | pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1) 43 | 44 | # menggambar kotak latar belakang untuk teks pada surface 45 | pygame.draw.rect(windowSurface, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40)) 46 | 47 | # ambil array pixel dari surface 48 | pixArray = pygame.PixelArray(windowSurface) 49 | pixArray[480][380] = BLACK 50 | del pixArray 51 | 52 | # menggambar teks pada surface 53 | windowSurface.blit(text, textRect) 54 | 55 | # menggambar jendela pada layar 56 | pygame.display.update() 57 | 58 | # jalankan putaran game 59 | while True: 60 | for event in pygame.event.get(): 61 | if event.type == QUIT: 62 | pygame.quit() 63 | sys.exit() 64 | -------------------------------------------------------------------------------- /translations/id/src/pygameMasukan.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | # menyiapkan pygame 5 | pygame.init() 6 | mainClock = pygame.time.Clock() 7 | 8 | # menyiapkan jendela 9 | WINDOWWIDTH = 400 10 | WINDOWHEIGHT = 400 11 | windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) 12 | pygame.display.set_caption('Masukan') 13 | 14 | # menyiapkan warna 15 | BLACK = (0, 0, 0) 16 | GREEN = (0, 255, 0) 17 | WHITE = (255, 255, 255) 18 | 19 | # menyiapkan data struktur pemain dan makanan 20 | foodCounter = 0 21 | NEWFOOD = 40 22 | FOODSIZE = 20 23 | player = pygame.Rect(300, 100, 50, 50) 24 | foods = [] 25 | for i in range(20): 26 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 27 | 28 | # menyiapkan variabel arah gerak 29 | moveLeft = False 30 | moveRight = False 31 | moveUp = False 32 | moveDown = False 33 | 34 | MOVESPEED = 6 35 | 36 | 37 | # menjalankan putaran game 38 | while True: 39 | # mengecek peristiwa yang terjadi 40 | for event in pygame.event.get(): 41 | if event.type == QUIT: 42 | pygame.quit() 43 | sys.exit() 44 | if event.type == KEYDOWN: 45 | # mengubah variabel keyboard 46 | if event.key == K_LEFT or event.key == ord('a'): 47 | moveRight = False 48 | moveLeft = True 49 | if event.key == K_RIGHT or event.key == ord('d'): 50 | moveLeft = False 51 | moveRight = True 52 | if event.key == K_UP or event.key == ord('w'): 53 | moveDown = False 54 | moveUp = True 55 | if event.key == K_DOWN or event.key == ord('s'): 56 | moveUp = False 57 | moveDown = True 58 | if event.type == KEYUP: 59 | if event.key == K_ESCAPE: 60 | pygame.quit() 61 | sys.exit() 62 | if event.key == K_LEFT or event.key == ord('a'): 63 | moveLeft = False 64 | if event.key == K_RIGHT or event.key == ord('d'): 65 | moveRight = False 66 | if event.key == K_UP or event.key == ord('w'): 67 | moveUp = False 68 | if event.key == K_DOWN or event.key == ord('s'): 69 | moveDown = False 70 | if event.key == ord('x'): 71 | player.top = random.randint(0, WINDOWHEIGHT - player.height) 72 | player.left = random.randint(0, WINDOWWIDTH - player.width) 73 | 74 | if event.type == MOUSEBUTTONUP: 75 | foods.append(pygame.Rect(event.pos[0], event.pos[1], FOODSIZE, FOODSIZE)) 76 | 77 | foodCounter += 1 78 | if foodCounter >= NEWFOOD: 79 | # menambahkan makanan baru 80 | foodCounter = 0 81 | foods.append(pygame.Rect(random.randint(0, WINDOWWIDTH - FOODSIZE), random.randint(0, WINDOWHEIGHT - FOODSIZE), FOODSIZE, FOODSIZE)) 82 | 83 | # menggambar latar belakang hitam pada permukaan 84 | windowSurface.fill(BLACK) 85 | 86 | # menggerakkan pemain 87 | if moveDown and player.bottom < WINDOWHEIGHT: 88 | player.top += MOVESPEED 89 | if moveUp and player.top > 0: 90 | player.top -= MOVESPEED 91 | if moveLeft and player.left > 0: 92 | player.left -= MOVESPEED 93 | if moveRight and player.right < WINDOWWIDTH: 94 | player.right += MOVESPEED 95 | 96 | # menggambar pemain pada permukaan 97 | pygame.draw.rect(windowSurface, WHITE, player) 98 | 99 | # mengecek apakah pemain saling tumpang tindih dengan suatu kotak makanan 100 | for food in foods[:]: 101 | if player.colliderect(food): 102 | foods.remove(food) 103 | 104 | # menggambar makanan 105 | for i in range(len(foods)): 106 | pygame.draw.rect(windowSurface, GREEN, foods[i]) 107 | 108 | # menggambar jendela pada layar 109 | pygame.display.update() 110 | mainClock.tick(40) 111 | -------------------------------------------------------------------------------- /translations/id/src/sandi.py: -------------------------------------------------------------------------------- 1 | # Sandi Caesar 2 | 3 | MAX_KEY_SIZE = 26 4 | 5 | def getMode(): 6 | while True: 7 | print('Apa kamu ingin mengenkripsi atau mendekripsi suatu pesan?') 8 | mode = input().lower() 9 | if mode in 'enkripsi e dekripsi d'.split(): 10 | return mode 11 | else: 12 | print('Masukkan "enkripsi" atau "e" atau "dekripsi" atau "d".') 13 | 14 | def getMessage(): 15 | print('Masukkan pesanmu:') 16 | return input() 17 | 18 | def getKey(): 19 | key = 0 20 | while True: 21 | print('Masukkan bilangan kunci (1-%s)' % (MAX_KEY_SIZE)) 22 | key = int(input()) 23 | if (key >= 1 and key <= MAX_KEY_SIZE): 24 | return key 25 | 26 | def getTranslatedMessage(mode, message, key): 27 | if mode[0] == 'd': 28 | key = -key 29 | translated = '' 30 | 31 | for symbol in message: 32 | if symbol.isalpha(): 33 | num = ord(symbol) 34 | num += key 35 | 36 | if symbol.isupper(): 37 | if num > ord('Z'): 38 | num -= 26 39 | elif num < ord('A'): 40 | num += 26 41 | elif symbol.islower(): 42 | if num > ord('z'): 43 | num -= 26 44 | elif num < ord('a'): 45 | num += 26 46 | 47 | translated += chr(num) 48 | else: 49 | translated += symbol 50 | return translated 51 | 52 | mode = getMode() 53 | message = getMessage() 54 | key = getKey() 55 | 56 | print('Pesan hasil pergeserannya adalah:') 57 | print(getTranslatedMessage(mode, message, key)) 58 | -------------------------------------------------------------------------------- /translations/id/src/tebak.py: -------------------------------------------------------------------------------- 1 | # Ini adalah game tebak angka. 2 | import random 3 | 4 | guessesTaken = 0 5 | 6 | print('Halo! Siapa namamu?') 7 | myName = input() 8 | 9 | number = random.randint(1, 20) 10 | print('Eh, ' + myName + ', Aku lagi berpikir angka antara 1 dan 20.') 11 | 12 | while guessesTaken < 6: 13 | print('Coba tebak.') # Ada empat spasi di depan print. 14 | guess = input() 15 | guess = int(guess) 16 | 17 | guessesTaken = guessesTaken + 1 18 | 19 | if guess < number: 20 | print('Tebakanmu terlalu rendah.') # Ada delapan spasi didepan print. 21 | 22 | if guess > number: 23 | print('Tebakanmu terlalu tinggi.') 24 | 25 | if guess == number: 26 | break 27 | 28 | if guess == number: 29 | guessesTaken = str(guessesTaken) 30 | print('Hebat, ' + myName + '! Kamu menebak angkaku dalam ' + guessesTaken + ' tebakan!') 31 | 32 | if guess != number: 33 | number = str(number) 34 | print('Sayang sekali. Angka yang aku pikirkan adalah ' + number) 35 | -------------------------------------------------------------------------------- /translations/id/text/chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | Pastikan instal Python 3, bukan Python 2! -------------------------------------------------------------------------------- /translations/id/text/chapter14.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/id/text/chapter17.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 17-3: 2 | Pemrograman itu menyenangkan! 3 | 4 | Fig 17-4: 5 | Teraliasi 6 | Anti-alias 7 | 8 | -------------------------------------------------------------------------------- /translations/id/text/chapter18.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 18-2: 2 | Persegi panjang yang saling tumpang tindih 3 | Persegi panjang yang tidak saling tumpang tindih 4 | 5 | -------------------------------------------------------------------------------- /translations/id/text/chapter2.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 2-3: 2 | nilai 3 | operator 4 | ekspresi 5 | 6 | Fig 2-4: 7 | spam 8 | 9 | Fig 2-5: 10 | eggs 11 | fizz 12 | -------------------------------------------------------------------------------- /translations/id/text/chapter3.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/id/text/chapter4.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 4-2: 2 | ...maju ke dalam blok while di sini. 3 | ...maju melewati blok while ke sini. 4 | 5 | Fig 4-3: 6 | fizzy 7 | katakunci if 8 | kondisi 9 | katakunci while 10 | 11 | -------------------------------------------------------------------------------- /translations/id/text/chapter5.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/id/text/chapter6.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 6-1: 2 | keyword def 3 | tanda kurung buka-tutup 4 | nama fungsi 5 | titik dua 6 | 7 | Fig 6-2: 8 | Mulai 9 | Tampilkan pengantar 10 | Pemain memilih sebuah gua 11 | Cek apakah ada naga ramah atau naga lapar 12 | Pemain menang 13 | Pemain kalah 14 | Mau main lagi? 15 | Selesai 16 | 17 | -------------------------------------------------------------------------------- /translations/id/text/chapter7.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/id/text/chapter8.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 8-1 through 8-9: 2 | Mulai 3 | Buat kata rahasia. 4 | Tampilkan papan dan garis pada pemain. 5 | Tanya pemain untuk menebak satu huruf. 6 | Pemain sudah menebak huruf ini. 7 | Huruf ada dalam kata rahasia. 8 | Hurut tidak ada dalam kata rahasia. 9 | Pemain sudah menebak semua huruf dan menang. 10 | Bagian tubuh yang tesisa sudah habis dan pemain kalah. 11 | Tanya pemain apa ingin main lagi. 12 | Akhir 13 | -------------------------------------------------------------------------------- /translations/id/text/chapter9.5.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/id/text/chapter9.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/it/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/kar/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/ml/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/nl/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | Veky 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/pl/README.md: -------------------------------------------------------------------------------- 1 | Tłumacze 2 | =========== 3 | 4 | Michał Niklas https://github.com/michal-niklas 5 | 6 | 7 | (Zawsze warto sprawdzić w historii plików w tym katalogu, czy są inni tłumacze) 8 | 9 | Tytuł 10 | ===== 11 | 12 | Twórz własne gry komputerowe używając Pythona, wydanie 3 13 | 14 | 15 | Uwagi ogólne 16 | ============= 17 | 18 | Na potrzebę szybkiego znajdywania wspólnych fraz i by zachować w miarę jednolite tłumaczena danych fraz stworzyłem plik glossary.txt z moimi propozycjami. Przykładowo chciałbym, by 'file' zawsze było tłumaczone jako plik. 19 | -------------------------------------------------------------------------------- /translations/pl/glossary.txt: -------------------------------------------------------------------------------- 1 | Python, odmieniamy: Pythona, Pythonem, Pythonie itd 2 | 3 | backslash, odwrócony ukośnik 4 | click, kliknij 5 | debugger, odpluskiwacz 6 | download, pobranie 7 | Evaluation, Obliczanie, wyliczanie 8 | expression, wyrażenie 9 | Figure, Rysunek 10 | file, plik 11 | run, uruchom 12 | scope, zasięg 13 | shell, powłoka 14 | slash, ukośnik 15 | statement, dyrektywa 16 | stepping into, wchodzenie do (debugger) 17 | string, napis 18 | -------------------------------------------------------------------------------- /translations/pl/src/buggy.py: -------------------------------------------------------------------------------- 1 | import random 2 | number1 = random.randint(1, 10) 3 | number2 = random.randint(1, 10) 4 | print('Jaki jest wynik ' + str(number1) + ' + ' + str(number2) + '?') 5 | answer = input() 6 | if answer == number1 + number2: 7 | print('Bardzo dobrze!') 8 | else: 9 | print('Niestety! Prawidłowa odpowiedź to ' + str(number1 + number2)) 10 | -------------------------------------------------------------------------------- /translations/pl/src/coinFlips.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Rzucę monetą 1000 razy. Zgadnij ile razy wypadnie orzeł. (Naciśnij enter by rozpocząć)') 3 | input() 4 | flips = 0 5 | heads = 0 6 | while flips < 1000: 7 | if random.randint(0, 1) == 1: 8 | heads = heads + 1 9 | flips = flips + 1 10 | 11 | if flips == 900: 12 | print('900 rzutów i orzeł wypadł ' + str(heads) + ' razy.') 13 | if flips == 100: 14 | print('Mamy 100 rzutów, jak na razie orzeł wypadł ' + str(heads) + ' razy.') 15 | if flips == 500: 16 | print('Połowa za nami, a orzeł wypadł ' + str(heads) + ' razy.') 17 | 18 | print() 19 | print('Na 1000 rzutów, orzeł wypadł ' + str(heads) + ' razy!') 20 | print('Byłeś bliski?') 21 | -------------------------------------------------------------------------------- /translations/pl/src/dragon.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def displayIntro(): 5 | print('Jesteś w krainie pełnej smoków. Przed sobą widzisz') 6 | print('dwie jasinie. W jednej mieszka przyjacielski smok,') 7 | print('który podzieli sie z tobą skarbem. Drugi smok jest') 8 | print('chciwy i głodny, i zje cię na miejscu.') 9 | print() 10 | 11 | def chooseCave(): 12 | cave = '' 13 | while cave != '1' and cave != '2': 14 | print('Do której jaskini chcesz wejść? (1 lub 2)') 15 | cave = input() 16 | 17 | return cave 18 | 19 | def checkCave(chosenCave): 20 | print('Zbliżasz się do jaskini...') 21 | time.sleep(2) 22 | print('Jest ciemna i straszna...') 23 | time.sleep(2) 24 | print('Wielki smok wyskakuje prosto na ciebie! Otwiera swą paszczę i ...') 25 | print() 26 | time.sleep(2) 27 | 28 | friendlyCave = random.randint(1, 2) 29 | 30 | if chosenCave == str(friendlyCave): 31 | print('Daje ci swój skarb!') 32 | else: 33 | print('Pożera cię jednym kłapnięciem paszczy!') 34 | 35 | playAgain = 'tak' 36 | while playAgain == 'tak' or playAgain == 't': 37 | 38 | displayIntro() 39 | 40 | caveNumber = chooseCave() 41 | 42 | checkCave(caveNumber) 43 | 44 | print('Chcesz zagrać ponownie? (tak lub nie)') 45 | playAgain = input() 46 | -------------------------------------------------------------------------------- /translations/pl/src/guess.py: -------------------------------------------------------------------------------- 1 | # To jest gra w zgadywanie liczby 2 | import random 3 | 4 | probyZgadniecia = 0 5 | 6 | print('Cześć! Jak masz na imię?') 7 | mojeImie = input() 8 | 9 | tajemnaLiczba = random.randint(1, 20) 10 | print('Dobrze ' + mojeImie + ', myślę sobie o liczbie między 1 i 20.') 11 | 12 | while probyZgadniecia < 6: 13 | print('Spróbuj ją zgadnąć.') # Na początku linii są cztery spacje. 14 | podanaLiczba = input() 15 | podanaLiczba = int(podanaLiczba) 16 | 17 | probyZgadniecia = probyZgadniecia + 1 18 | 19 | if podanaLiczba < tajemnaLiczba: 20 | print('Podałeś za małą liczbę.') # Na początku linii jest osiem spacji. 21 | 22 | if podanaLiczba > tajemnaLiczba: 23 | print('Podałeś zbyt dużą liczbę.') 24 | 25 | if podanaLiczba == tajemnaLiczba: 26 | break 27 | 28 | if podanaLiczba == tajemnaLiczba: 29 | probyZgadniecia = str(probyZgadniecia) 30 | print('Gratuluję ' + mojeImie + '! Zgadłeś moją liczbę w ' + probyZgadniecia + ' próbach!') 31 | 32 | if podanaLiczba != tajemnaLiczba: 33 | tajemnaLiczba = str(tajemnaLiczba) 34 | print('Niestety. Numer o jakim myślałem to ' + tajemnaLiczba) 35 | -------------------------------------------------------------------------------- /translations/pl/src/hello.py: -------------------------------------------------------------------------------- 1 | # Ten program wypisuje napisy i pyta o imię 2 | print('Witaj świecie!') 3 | print('Jak masz na imię?') 4 | mojeImie = input() 5 | print(mojeImie + ', miło Cię poznać') 6 | -------------------------------------------------------------------------------- /translations/pl/src/jokes.py: -------------------------------------------------------------------------------- 1 | print('Co kłótliwy człowiek robi w pralce?') 2 | input() 3 | print('Spiera się.') 4 | print() 5 | print('Co powiedział chemik jak zjadł zimny brom??') 6 | input() 7 | print('Chemik powiedział \'Br\'!') 8 | print() 9 | print('Puk, puk.') 10 | input() 11 | print("Kto tam?") 12 | input() 13 | print('Przerywająca krowa.') 14 | input() 15 | print('Przerywająca krowa? O co', end='') 16 | print('-Muu!') 17 | -------------------------------------------------------------------------------- /translations/pl/txt/README.txt: -------------------------------------------------------------------------------- 1 | Katalog zawiera pliki tekstowe dla poszczególnych rozdziałów. Nie ma tu formatowania. Te pliki będą skopiowane do Worda, lub InDesign by dac im odpowiedni wygląd. 2 | -------------------------------------------------------------------------------- /translations/pl/txt/chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Rysunek 1-1: 2 | Upewnij się, że instalujesz Python 3, a nie Python 2! -------------------------------------------------------------------------------- /translations/pl/txt/chapter2.figures.txt: -------------------------------------------------------------------------------- 1 | Rys. 2-3: 2 | wartość 3 | operator 4 | wyrażenie 5 | 6 | Rys. 2-4: 7 | spam 8 | 9 | Rys. 2-5: 10 | eggs 11 | fizz 12 | -------------------------------------------------------------------------------- /translations/pl/txt/chapter3.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/pl/txt/chapter4.figures.txt: -------------------------------------------------------------------------------- 1 | Rys. 4-2: 2 | ...tu idź do środka bloku while. 3 | ...tu wyjdź z bloku while. 4 | 5 | Rys. 4-3: 6 | fizzy 7 | słowow kluczowe if 8 | warunek 9 | słowo kluczowe while 10 | 11 | -------------------------------------------------------------------------------- /translations/pl/txt/chapter5.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/pl/txt/chapter6.figures.txt: -------------------------------------------------------------------------------- 1 | Rys. 6-1: 2 | Słowo kluczowe def 3 | nawiasy 4 | nazwa funkcji 5 | dwukropek 6 | 7 | Rys. 6-2: 8 | Start 9 | Pokazanie wstępu 10 | Gracz wybiera jaskinię 11 | Sprawdzenie, czy smok jest przyjacielski, czy głodny 12 | Gracz wygrywa 13 | Gracz przegrywa 14 | Zapytanie, czy gracz chce zagrać ponownie 15 | Koniec 16 | 17 | -------------------------------------------------------------------------------- /translations/pl/txt/chapter7.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/pt-br/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/pt/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/ru/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/sq/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/sr/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | 7 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 8 | 9 | Title 10 | ===== 11 | 12 | (Put translated book title here.) 13 | 14 | General Notes 15 | ============= 16 | 17 | Add notes here. -------------------------------------------------------------------------------- /translations/sv/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | 5 | 6 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 7 | 8 | Title 9 | ===== 10 | 11 | (Put translated book title here.) 12 | 13 | General Notes 14 | ============= 15 | 16 | (Add notes for other translators here.) -------------------------------------------------------------------------------- /translations/sv/src/animering.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time 2 | from pygame.locals import * 3 | 4 | # initiera pygame 5 | pygame.init() 6 | 7 | # initiera fönstret 8 | FÖNSTERBREDD = 400 9 | FÖNSTERHÖJD = 400 10 | fönsteryta = pygame.display.set_mode((FÖNSTERBREDD, FÖNSTERHÖJD), 0, 32) 11 | pygame.display.set_caption('Animering') 12 | 13 | # skapa riktningskonstanter 14 | NER_VÄNSTER = 1 15 | NER_HÖGER = 3 16 | UPP_VÄNSTER = 7 17 | UPP_HÖGER = 9 18 | 19 | HASTIGHET = 4 20 | 21 | # skapa färgkonstanter 22 | SVART = (0, 0, 0) 23 | RÖD = (255, 0, 0) 24 | GRÖN = (0, 255, 0) 25 | BLÅ = (0, 0, 255) 26 | 27 | # initiera blockets datastruktur 28 | b1 = {'rektangel':pygame.Rect(300, 80, 50, 100), 'färg':RÖD, 'riktning':UPP_HÖGER} 29 | b2 = {'rektangel':pygame.Rect(200, 200, 20, 20), 'färg':GRÖN, 'riktning':UPP_VÄNSTER} 30 | b3 = {'rektangel':pygame.Rect(100, 150, 60, 60), 'färg':BLÅ, 'riktning':NER_VÄNSTER} 31 | block = [b1, b2, b3] 32 | 33 | # kör spelslingan 34 | while True: 35 | # kontrollera om händelsen QUIT inträffat 36 | for event in pygame.event.get(): 37 | if event.type == QUIT: 38 | pygame.quit() 39 | sys.exit() 40 | 41 | # rita svart bakgrund på ytan 42 | fönsteryta.fill(SVART) 43 | 44 | for b in block: 45 | # flytta blockets datastruktur 46 | if b['riktning'] == NER_VÄNSTER: 47 | b['rektangel'].left -= HASTIGHET 48 | b['rektangel'].top += HASTIGHET 49 | if b['riktning'] == NER_HÖGER: 50 | b['rektangel'].left += HASTIGHET 51 | b['rektangel'].top += HASTIGHET 52 | if b['riktning'] == UPP_VÄNSTER: 53 | b['rektangel'].left -= HASTIGHET 54 | b['rektangel'].top -= HASTIGHET 55 | if b['riktning'] == UPP_HÖGER: 56 | b['rektangel'].left += HASTIGHET 57 | b['rektangel'].top -= HASTIGHET 58 | 59 | # kontrollera om blocket har hamnat utanför fönstret 60 | if b['rektangel'].top < 0: 61 | # blocket har hamnat utanför ovansidan 62 | if b['riktning'] == UPP_VÄNSTER: 63 | b['riktning'] = NER_VÄNSTER 64 | if b['riktning'] == UPP_HÖGER: 65 | b['riktning'] = NER_HÖGER 66 | if b['rektangel'].bottom > FÖNSTERHÖJD: 67 | # blocket har hamnat utanför undersidan 68 | if b['riktning'] == NER_VÄNSTER: 69 | b['riktning'] = UPP_VÄNSTER 70 | if b['riktning'] == NER_HÖGER: 71 | b['riktning'] = UPP_HÖGER 72 | if b['rektangel'].left < 0: 73 | # blocket har hamnat utanför vänster sida 74 | if b['riktning'] == NER_VÄNSTER: 75 | b['riktning'] = NER_HÖGER 76 | if b['riktning'] == UPP_VÄNSTER: 77 | b['riktning'] = UPP_HÖGER 78 | if b['rektangel'].right > FÖNSTERBREDD: 79 | # blocket har hamnat utanför höger sida 80 | if b['riktning'] == NER_HÖGER: 81 | b['riktning'] = NER_VÄNSTER 82 | if b['riktning'] == UPP_HÖGER: 83 | b['riktning'] = UPP_VÄNSTER 84 | 85 | # rita blocket på ytan 86 | pygame.draw.rect(fönsteryta, b['färg'], b['rektangel']) 87 | 88 | # rita fönstret på skärmen 89 | pygame.display.update() 90 | time.sleep(0.02) 91 | -------------------------------------------------------------------------------- /translations/sv/src/background.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/background.mid -------------------------------------------------------------------------------- /translations/sv/src/baddie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/baddie.png -------------------------------------------------------------------------------- /translations/sv/src/bagels.py: -------------------------------------------------------------------------------- 1 | import random 2 | def hämtaHemligtTal(antalSiffror): 3 | # Returnerar en sträng som är antalSiffror lång och som består av unika, framslumpade siffror. 4 | siffror = list(range(10)) 5 | random.shuffle(siffror) 6 | hemligtTal = '' 7 | for i in range(antalSiffror): 8 | hemligtTal += str(siffror[i]) 9 | return hemligtTal 10 | 11 | def hämtaLedtrådar(gissning, hemligtTal): 12 | # Returnerar en sträng med ledtrådar till användaren. 13 | if gissning == hemligtTal: 14 | return 'Du kom på det!' 15 | 16 | ledtråd = [] 17 | 18 | for i in range(len(gissning)): 19 | if gissning[i] == hemligtTal[i]: 20 | ledtråd.append('Fermi') 21 | elif gissning[i] in hemligtTal: 22 | ledtråd.append('Pico') 23 | if len(ledtråd) == 0: 24 | return 'Bagels' 25 | 26 | ledtråd.sort() 27 | return ' '.join(ledtråd) 28 | 29 | def ärBaraSiffror(tal): 30 | # Returnerar True om tal är en sträng som enbart består av siffror. Annars returneras False. 31 | if tal == '': 32 | return False 33 | 34 | for i in tal: 35 | if i not in '0 1 2 3 4 5 6 7 8 9'.split(): 36 | return False 37 | 38 | return True 39 | 40 | def spelaIgen(): 41 | # Den här funktionen returnerar True om spelaren vill spela igen, annars returnerar den False. 42 | print('Vill du spela igen? (ja eller nej)') 43 | return input().lower().startswith('j') 44 | 45 | ANTAL_SIFFROR = 3 46 | MAX_ANTAL_GISSNINGAR = 10 47 | 48 | print('Jag tänker på ett %s-siffrigt tal. Försök att gissa talet.' % (ANTAL_SIFFROR)) 49 | print('Här får du några ledtrådar:') 50 | print('När jag säger: Betyder det:') 51 | print(' Pico En siffra är korrekt men på fel position.') 52 | print(' Fermi En siffra är korrekt och på rätt position.') 53 | print(' Bagels Ingen siffra är korrekt.') 54 | 55 | while True: 56 | hemligtTal = hämtaHemligtTal(ANTAL_SIFFROR) 57 | print('Jag har kommit på ett tal. Du får %s gissningar på dig för att räkna ut det.' % (MAX_ANTAL_GISSNINGAR)) 58 | 59 | antalGissningar = 1 60 | while antalGissningar <= MAX_ANTAL_GISSNINGAR: 61 | gissning = '' 62 | while len(gissning) != ANTAL_SIFFROR or not ärBaraSiffror(gissning): 63 | print('Gissning #%s: ' % (antalGissningar)) 64 | gissning = input() 65 | 66 | ledtråd = hämtaLedtrådar(gissning, hemligtTal) 67 | print(ledtråd) 68 | antalGissningar += 1 69 | 70 | if gissning == hemligtTal: 71 | break 72 | if antalGissningar > MAX_ANTAL_GISSNINGAR: 73 | print('Du fick slut på gissningar. Svaret var %s.' % (hemligtTal)) 74 | 75 | if not spelaIgen(): 76 | break 77 | -------------------------------------------------------------------------------- /translations/sv/src/bilderOchLjud.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, time, random 2 | from pygame.locals import * 3 | 4 | # initiera pygame 5 | pygame.init() 6 | huvudklocka = pygame.time.Clock() 7 | 8 | # initiera fönstret 9 | FÖNSTERBREDD = 400 10 | FÖNSTERHÖJD = 400 11 | fönsteryta = pygame.display.set_mode((FÖNSTERBREDD, FÖNSTERHÖJD), 0, 32) 12 | pygame.display.set_caption('Bilder och ljud') 13 | 14 | # skapa färgkonstanter 15 | SVART = (0, 0, 0) 16 | 17 | # initiera blockets datastruktur 18 | spelare = pygame.Rect(300, 100, 40, 40) 19 | spelarbild = pygame.image.load('player.png') 20 | skaladSpelarbild = pygame.transform.scale(spelarbild, (40, 40)) 21 | matbild = pygame.image.load('cherry.png') 22 | matbitar = [] 23 | for i in range(20): 24 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - 20), random.randint(0, FÖNSTERHÖJD - 20), 20, 20)) 25 | 26 | matbitsräknare = 0 27 | NY_MATBIT = 40 28 | 29 | # skapa tangenbordsvariabler 30 | flyttaVänster = False 31 | flyttaHöger = False 32 | flyttaUpp = False 33 | flyttaNer = False 34 | 35 | HASTIGHET = 6 36 | 37 | # Skapa musik 38 | plockaUppLjud = pygame.mixer.Sound('pickup.wav') 39 | pygame.mixer.music.load('background.mid') 40 | pygame.mixer.music.play(-1, 0.0) 41 | musikSpelas = True 42 | 43 | # kör spelslingan 44 | while True: 45 | # kontrollera om händelsen QUIT inträffat 46 | for event in pygame.event.get(): 47 | if event.type == QUIT: 48 | pygame.quit() 49 | sys.exit() 50 | if event.type == KEYDOWN: 51 | # uppdatera tangentbordsvariablerna 52 | if event.key == K_LEFT or event.key == ord('a'): 53 | flyttaHöger = False 54 | flyttaVänster = True 55 | if event.key == K_RIGHT or event.key == ord('d'): 56 | flyttaVänster = False 57 | flyttaHöger = True 58 | if event.key == K_UP or event.key == ord('w'): 59 | flyttaNer = False 60 | flyttaUpp = True 61 | if event.key == K_DOWN or event.key == ord('s'): 62 | flyttaUpp = False 63 | flyttaNer = True 64 | if event.type == KEYUP: 65 | if event.key == K_ESCAPE: 66 | pygame.quit() 67 | sys.exit() 68 | if event.key == K_LEFT or event.key == ord('a'): 69 | flyttaVänster = False 70 | if event.key == K_RIGHT or event.key == ord('d'): 71 | flyttaHöger = False 72 | if event.key == K_UP or event.key == ord('w'): 73 | flyttaUpp = False 74 | if event.key == K_DOWN or event.key == ord('s'): 75 | flyttaNer = False 76 | if event.key == ord('x'): 77 | spelare.top = random.randint(0, FÖNSTERHÖJD - spelare.height) 78 | spelare.left = random.randint(0, FÖNSTERBREDD - spelare.width) 79 | if event.key == ord('m'): 80 | if musikSpelas: 81 | pygame.mixer.music.stop() 82 | else: 83 | pygame.mixer.music.play(-1, 0.0) 84 | musikSpelas = not musikSpelas 85 | 86 | if event.type == MOUSEBUTTONUP: 87 | matbitar.append(pygame.Rect(event.pos[0] - 10, event.pos[1] - 10, 20, 20)) 88 | 89 | matbitsräknare += 1 90 | if matbitsräknare >= NY_MATBIT: 91 | # addera mera matbitar 92 | matbitsräknare = 0 93 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - 20), random.randint(0, FÖNSTERHÖJD - 20), 20, 20)) 94 | 95 | # rita svart bakgrund på ytan 96 | fönsteryta.fill(SVART) 97 | 98 | # flytta spelaren 99 | if flyttaNer and spelare.bottom < FÖNSTERHÖJD: 100 | spelare.top += HASTIGHET 101 | if flyttaUpp and spelare.top > 0: 102 | spelare.top -= HASTIGHET 103 | if flyttaVänster and spelare.left > 0: 104 | spelare.left -= HASTIGHET 105 | if flyttaHöger and spelare.right < FÖNSTERBREDD: 106 | spelare.right += HASTIGHET 107 | 108 | 109 | # rita blocket på ytan 110 | fönsteryta.blit(skaladSpelarbild, spelare) 111 | 112 | # kontrollera om blocket överlappar någon matbit. 113 | for matbit in matbitar[:]: 114 | if spelare.colliderect(matbit): 115 | matbitar.remove(matbit) 116 | spelare = pygame.Rect(spelare.left, spelare.top, spelare.width + 2, spelare.height + 2) 117 | skaladSpelarbild = pygame.transform.scale(spelarbild, (spelare.width, spelare.height)) 118 | if musikSpelas: 119 | plockaUppLjud.play() 120 | 121 | # rita matbitarna 122 | for matbit in matbitar: 123 | fönsteryta.blit(matbild, matbit) 124 | 125 | # rita fönstret på skärmen 126 | pygame.display.update() 127 | huvudklocka.tick(40) 128 | -------------------------------------------------------------------------------- /translations/sv/src/buggar.py: -------------------------------------------------------------------------------- 1 | import random 2 | tal1 = random.randint(1, 10) 3 | tal2 = random.randint(1, 10) 4 | print('Vad blir ' + str(tal1) + ' + ' + str(tal2) + '?') 5 | svar = input() 6 | if svar == tal1 + tal2: 7 | print('Rätt!') 8 | else: 9 | print('Nix! Svaret är ' + str(tal1 + tal2)) 10 | -------------------------------------------------------------------------------- /translations/sv/src/buggig.py: -------------------------------------------------------------------------------- 1 | import random 2 | tal1 = random.randint(1, 10) 3 | tal2 = random.randint(1, 10) 4 | print('Vad blir ' + str(tal1) + ' + ' + str(tal2) + '?') 5 | svar = input() 6 | if svar == tal1 + tal2: 7 | print('Rätt!') 8 | else: 9 | print('Nix! Svaret är ' + str(tal1 + tal2)) 10 | -------------------------------------------------------------------------------- /translations/sv/src/cherry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/cherry.png -------------------------------------------------------------------------------- /translations/sv/src/chiffer.py: -------------------------------------------------------------------------------- 1 | # Caesarchiffer 2 | 3 | MAX_NYCKELSTORLEK = 58 4 | 5 | def hämtaRiktning(): 6 | while True: 7 | print('Vill du kryptera eller dekryptera ett meddelande?') 8 | riktning = input().lower() 9 | if riktning in 'kryptera k dekryptera d'.split(): 10 | return riktning 11 | else: 12 | print('Mata in antingen "kryptera", "k", "dekryptera" eller "d"') 13 | 14 | def hämtaMeddelande(): 15 | print('Mata in ditt meddelande:') 16 | return input() 17 | 18 | def hämtaNyckel(): 19 | nyckel = 0 20 | while True: 21 | print('Mata in nyckel (1-%s)' % (MAX_NYCKELSTORLEK)) 22 | nyckel = int(input()) 23 | if (nyckel >= 1 and nyckel <= MAX_NYCKELSTORLEK): 24 | return nyckel 25 | 26 | def hämtaÖversattMeddelande(riktning, meddelande, nyckel): 27 | if riktning[0] == 'd': 28 | nyckel = -nyckel 29 | översatt = '' 30 | 31 | alfabet = 'abcdefghijklmnopqrstuvwxyzåäöABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ' 32 | 33 | for tecken in meddelande: 34 | if tecken.isalpha(): 35 | nummer = alfabet.index(tecken) 36 | nummer += nyckel 37 | nummer = nummer % len(alfabet) 38 | tecken = alfabet[nummer] 39 | översatt += tecken 40 | return översatt 41 | 42 | 43 | riktning = hämtaRiktning() 44 | meddelande = hämtaMeddelande() 45 | nyckel = hämtaNyckel() 46 | 47 | print('Din översatta text är:') 48 | print(hämtaÖversattMeddelande(riktning, meddelande, nyckel)) 49 | -------------------------------------------------------------------------------- /translations/sv/src/drakriket.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def visaIntro(): 5 | print('Du befinner dig i ett land fullt av drakar. Framför dig') 6 | print('ser du två grottor. I en av grottorna bor en snäll drake') 7 | print('som kommer att dela sin skatt med dig. Den andra draken') 8 | print('är girig och hungrig, och kommer att äta upp dig på fläcken.') 9 | print() 10 | 11 | def väljGrotta(): 12 | grotta = '' 13 | while grotta != '1' and grotta != '2': 14 | print('Vilken grotta går du in i? (1 eller 2)') 15 | grotta = input() 16 | 17 | return grotta 18 | 19 | def kollaGrotta(valdGrotta): 20 | print('Du närmar dig grottan...') 21 | time.sleep(2) 22 | print('Det är mörkt och kusligt...') 23 | time.sleep(2) 24 | print('En stor drake hoppar ut framför dig! Han öppnar sina käftar och...') 25 | print() 26 | time.sleep(2) 27 | 28 | snällGrotta = random.randint(1, 2) 29 | 30 | if valdGrotta == str(snällGrotta): 31 | print('Ger dig sin skatt!') 32 | else: 33 | print('Slukar dig hel!') 34 | 35 | spelaIgen = 'ja' 36 | while spelaIgen == 'ja' or spelaIgen == 'j': 37 | 38 | visaIntro() 39 | 40 | grottnummer = väljGrotta() 41 | 42 | kollaGrotta(grottnummer) 43 | 44 | print('Vill du spela igen? (ja eller nej)') 45 | spelaIgen = input() 46 | -------------------------------------------------------------------------------- /translations/sv/src/gameover.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/gameover.wav -------------------------------------------------------------------------------- /translations/sv/src/gissa.py: -------------------------------------------------------------------------------- 1 | # Det här spelet går ut på att gissa rätt tal. 2 | import random 3 | 4 | antalGissningar = 0 5 | 6 | print('Hej! Vad heter du?') 7 | namn = input() 8 | 9 | tal = random.randint(1, 20) 10 | print('Okej, ' + namn + ', jag tänker på ett tal mellan 1 och 20.') 11 | 12 | while antalGissningar < 6: 13 | print('Gör en gissning.') # Det är fyra mellanslag före print. 14 | gissning = input() 15 | gissning = int(gissning) 16 | 17 | antalGissningar = antalGissningar + 1 18 | 19 | if gissning < tal: 20 | print('Du gissade på ett för lågt tal.') # Det är åtta mellanslag före print. 21 | 22 | if gissning > tal: 23 | print('Du gissade på ett för högt tal.') 24 | 25 | if gissning == tal: 26 | break 27 | 28 | if gissning == tal: 29 | antalGissningar = str(antalGissningar) 30 | print('Bra jobbat, ' + namn + '! Du gissade rätt på ' + antalGissningar + ' gissningar!') 31 | 32 | if gissning != tal: 33 | tal = str(tal) 34 | print('Nix. Talet jag tänkte på var ' + tal) 35 | -------------------------------------------------------------------------------- /translations/sv/src/hangman.py: -------------------------------------------------------------------------------- 1 | import random 2 | HANGMANBILDER = [''' 3 | 4 | +---+ 5 | | | 6 | | 7 | | 8 | | 9 | | 10 | =========''', ''' 11 | 12 | +---+ 13 | | | 14 | O | 15 | | 16 | | 17 | | 18 | =========''', ''' 19 | 20 | +---+ 21 | | | 22 | O | 23 | | | 24 | | 25 | | 26 | =========''', ''' 27 | 28 | +---+ 29 | | | 30 | O | 31 | /| | 32 | | 33 | | 34 | =========''', ''' 35 | 36 | +---+ 37 | | | 38 | O | 39 | /|\ | 40 | | 41 | | 42 | =========''', ''' 43 | 44 | +---+ 45 | | | 46 | O | 47 | /|\ | 48 | / | 49 | | 50 | =========''', ''' 51 | 52 | +---+ 53 | | | 54 | O | 55 | /|\ | 56 | / \ | 57 | | 58 | ========='''] 59 | ord = 'anka apa babian bagge björn bäver duva fladdermus forell får get groda grävling gås haj hund hök iller kalkon kamel kanin katt kobra korp kråka lama lax lejon mullvad mulåsna mus mussla myra noshörning orm padda panda papegoja prärievarg puma pytonorm rådjur råtta räv sengångare skunk sköldpadda spindel stork svan säl tiger uggla utter val vattenödla varg vessla vombat zebra åsna älg ödla örn'.split() 60 | 61 | def slumpaOrd(ordlista): 62 | # Den här funktionen slumpar fram en sträng ur den lista av strängar som skickats in. 63 | ordindex = random.randint(0, len(ordlista) - 1) 64 | return ordlista[ordindex] 65 | 66 | def visaBräde(HANGMANBILDER, missar, träffar, hemligtOrd): 67 | print(HANGMANBILDER[len(missar)]) 68 | print() 69 | 70 | print('Felaktiga bokstäver:', end=' ') 71 | for bokstav in missar: 72 | print(bokstav, end=' ') 73 | print() 74 | 75 | tomrum = '_' * len(hemligtOrd) 76 | 77 | for i in range(len(hemligtOrd)): # ersätt tomrum med korrekt gissade bokstäver 78 | if hemligtOrd[i] in träffar: 79 | tomrum = tomrum[:i] + hemligtOrd[i] + tomrum[i+1:] 80 | 81 | for bokstav in tomrum: # visa det hemliga ordet med mellanrum mellan varje bokstav 82 | print(bokstav, end=' ') 83 | print() 84 | 85 | def hämtaGissning(tidigareGissningar): 86 | # Returnerar bokstaven som spelaren har matat in. Den här funktionen kontrollerar att spelaren bara har matat in en enda bokstav. 87 | while True: 88 | print('Gissa en bokstav.') 89 | gissning = input() 90 | gissning = gissning.lower() 91 | if len(gissning) != 1: 92 | print('Var snäll och mata in en enda bokstav.') 93 | elif gissning in tidigareGissningar: 94 | print('Du har redan gissat på den bokstaven. Gissa igen.') 95 | elif gissning not in 'abcdefghijklmnopqrstuvwxyzåäö': 96 | print('Var snäll och mata in en BOKSTAV.') 97 | else: 98 | return gissning 99 | 100 | def spelaIgen(): 101 | # Den här funktionen returnerar True om spelaren vill spela igen, annars returnerar den False. 102 | print('Vill du spela igen? (ja eller nej)') 103 | return input().lower().startswith('j') 104 | 105 | 106 | print('H A N G M A N') 107 | missar = '' 108 | träffar = '' 109 | hemligtOrd = slumpaOrd(ord) 110 | speletSlut = False 111 | 112 | while True: 113 | visaBräde(HANGMANBILDER, missar, träffar, hemligtOrd) 114 | 115 | # Låt spelaren skriva in en bokstav. 116 | gissning = hämtaGissning(missar + träffar) 117 | 118 | if gissning in hemligtOrd: 119 | träffar = träffar + gissning 120 | 121 | # Kolla om spelaren har vunnit 122 | hittatAllaBokstäver = True 123 | for i in range(len(hemligtOrd)): 124 | if hemligtOrd[i] not in träffar: 125 | hittatAllaBokstäver = False 126 | break 127 | if hittatAllaBokstäver: 128 | print('Ja! Det hemliga ordet var "' + hemligtOrd + '"! Du har vunnit!') 129 | speletSlut = True 130 | else: 131 | missar = missar + gissning 132 | 133 | # Kolla om spelaren har gissat för många gånger och förlorat 134 | if len(missar) == len(HANGMANBILDER) - 1: 135 | visaBräde(HANGMANBILDER, missar, träffar, hemligtOrd) 136 | print('Du har slut på gissningar!\nEfter ' + str(len(missar)) + ' felaktiga gissningar och ' + str(len(träffar)) + ' korrekta gissningar, kan jag avslöja att ordet var "' + hemligtOrd + '"') 137 | speletSlut = True 138 | 139 | # Fråga om spelaren vill spela igen (men bara om spelet är slut). 140 | if speletSlut: 141 | if spelaIgen(): 142 | missar = '' 143 | träffar = '' 144 | speletSlut = False 145 | hemligtOrd = slumpaOrd(ord) 146 | else: 147 | break 148 | -------------------------------------------------------------------------------- /translations/sv/src/hejsan.py: -------------------------------------------------------------------------------- 1 | # Det här programmet säger hej och frågar efter ett namn. 2 | print('Hejsan världen!') 3 | print('Vad heter du?') 4 | namn = input() 5 | print('Trevligt att träffas, ' + namn) 6 | -------------------------------------------------------------------------------- /translations/sv/src/kollisionsdetektering.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | def överlapparRektanglar(rektangel1, rektangel2): 5 | for a, b in [(rektangel1, rektangel2), (rektangel2, rektangel1)]: 6 | # Kontrollera om a:s hörn är inuti b 7 | if ((ärPunktInutiRektangel(a.left, a.top, b)) or 8 | (ärPunktInutiRektangel(a.left, a.bottom, b)) or 9 | (ärPunktInutiRektangel(a.right, a.top, b)) or 10 | (ärPunktInutiRektangel(a.right, a.bottom, b))): 11 | return True 12 | 13 | return False 14 | 15 | def ärPunktInutiRektangel(x, y, rect): 16 | if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom): 17 | return True 18 | else: 19 | return False 20 | 21 | 22 | # initiera pygame 23 | pygame.init() 24 | huvudklocka = pygame.time.Clock() 25 | 26 | # initiera fönstret 27 | FÖNSTERBREDD = 400 28 | FÖNSTERHÖJD = 400 29 | fönsteryta = pygame.display.set_mode((FÖNSTERBREDD, FÖNSTERHÖJD), 0, 32) 30 | pygame.display.set_caption('Kollisionsdetektering') 31 | 32 | # skapa riktningskonstanter 33 | NER_VÄNSTER = 1 34 | NER_HÖGER = 3 35 | UPP_VÄNSTER = 7 36 | UPP_HÖGER = 9 37 | 38 | HASTIGHET = 4 39 | 40 | # skapa färgkonstanter 41 | SVART = (0, 0, 0) 42 | GRÖN = (0, 255, 0) 43 | VIT = (255, 255, 255) 44 | 45 | # skapa studsbollen och matbitarnas datastruktur 46 | matbitsräknare = 0 47 | NY_MATBIT = 40 48 | MATBITSTORLEK = 20 49 | studsboll = {'rektangel':pygame.Rect(300, 100, 50, 50), 'riktning':UPP_VÄNSTER} 50 | matbitar = [] 51 | for i in range(20): 52 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - MATBITSTORLEK), random.randint(0, FÖNSTERHÖJD - MATBITSTORLEK), MATBITSTORLEK, MATBITSTORLEK)) 53 | 54 | # kör spelslingan 55 | while True: 56 | # kontrollera om händelsen QUIT inträffat 57 | for event in pygame.event.get(): 58 | if event.type == QUIT: 59 | pygame.quit() 60 | sys.exit() 61 | 62 | matbitsräknare += 1 63 | if matbitsräknare >= NY_MATBIT: 64 | # addera mera matbitar 65 | matbitsräknare = 0 66 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - MATBITSTORLEK), random.randint(0, FÖNSTERHÖJD - MATBITSTORLEK), MATBITSTORLEK, MATBITSTORLEK)) 67 | 68 | # rita svart bakgrund på ytan 69 | fönsteryta.fill(SVART) 70 | 71 | # flytta studsbollens datastruktur 72 | if studsboll['riktning'] == NER_VÄNSTER: 73 | studsboll['rektangel'].left -= HASTIGHET 74 | studsboll['rektangel'].top += HASTIGHET 75 | if studsboll['riktning'] == NER_HÖGER: 76 | studsboll['rektangel'].left += HASTIGHET 77 | studsboll['rektangel'].top += HASTIGHET 78 | if studsboll['riktning'] == UPP_VÄNSTER: 79 | studsboll['rektangel'].left -= HASTIGHET 80 | studsboll['rektangel'].top -= HASTIGHET 81 | if studsboll['riktning'] == UPP_HÖGER: 82 | studsboll['rektangel'].left += HASTIGHET 83 | studsboll['rektangel'].top -= HASTIGHET 84 | 85 | # kontrollera om studsbollen har hamnat utanför fönstret 86 | if studsboll['rektangel'].top < 0: 87 | # studsbollen har passerat ovansidan 88 | if studsboll['riktning'] == UPP_VÄNSTER: 89 | studsboll['riktning'] = NER_VÄNSTER 90 | if studsboll['riktning'] == UPP_HÖGER: 91 | studsboll['riktning'] = NER_HÖGER 92 | if studsboll['rektangel'].bottom > FÖNSTERHÖJD: 93 | # studsbollen har passerat undersidan 94 | if studsboll['riktning'] == NER_VÄNSTER: 95 | studsboll['riktning'] = UPP_VÄNSTER 96 | if studsboll['riktning'] == NER_HÖGER: 97 | studsboll['riktning'] = UPP_HÖGER 98 | if studsboll['rektangel'].left < 0: 99 | # studsbollen har passerat vänster sida 100 | if studsboll['riktning'] == NER_VÄNSTER: 101 | studsboll['riktning'] = NER_HÖGER 102 | if studsboll['riktning'] == UPP_VÄNSTER: 103 | studsboll['riktning'] = UPP_HÖGER 104 | if studsboll['rektangel'].right > FÖNSTERBREDD: 105 | # studsbollen har passerat höger sida 106 | if studsboll['riktning'] == NER_HÖGER: 107 | studsboll['riktning'] = NER_VÄNSTER 108 | if studsboll['riktning'] == UPP_HÖGER: 109 | studsboll['riktning'] = UPP_VÄNSTER 110 | 111 | # rita studsbollen på ytan 112 | pygame.draw.rect(fönsteryta, VIT, studsboll['rektangel']) 113 | 114 | # kontrollera om studsbollen korsar någon matbit 115 | for matbit in matbitar[:]: 116 | if överlapparRektanglar(studsboll['rektangel'], matbit): 117 | matbitar.remove(matbit) 118 | 119 | # rita matbitarna 120 | for i in range(len(matbitar)): 121 | pygame.draw.rect(fönsteryta, GRÖN, matbitar[i]) 122 | 123 | # rita fönstret på skärmen 124 | pygame.display.update() 125 | huvudklocka.tick(40) 126 | -------------------------------------------------------------------------------- /translations/sv/src/pickup.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/pickup.wav -------------------------------------------------------------------------------- /translations/sv/src/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asweigart/inventwithpython3rded/a7bf67142b8cfc0ac7cb16e6c7cf76026b3f04b7/translations/sv/src/player.png -------------------------------------------------------------------------------- /translations/sv/src/pygamehejsan.py: -------------------------------------------------------------------------------- 1 | import pygame, sys 2 | from pygame.locals import * 3 | 4 | # skapa pygame 5 | pygame.init() 6 | 7 | # skapa fönstret 8 | fönsteryta = pygame.display.set_mode((500, 400), 0, 32) 9 | pygame.display.set_caption('Hej Sverige!') 10 | 11 | # skapa färgerna 12 | SVART = (0, 0, 0) 13 | VIT = (255, 255, 255) 14 | RÖD = (255, 0, 0) 15 | GRÖN = (0, 255, 0) 16 | BLÅ = (0, 0, 255) 17 | 18 | # skapa fonter 19 | basfont = pygame.font.SysFont(None, 48) 20 | 21 | # skapa texten 22 | text = basfont.render('Hej Sverige!', True, VIT, BLÅ) 23 | textrektangel = text.get_rect() 24 | textrektangel.centerx = fönsteryta.get_rect().centerx 25 | textrektangel.centery = fönsteryta.get_rect().centery 26 | 27 | # rita den vita bakgrunden på ytan 28 | fönsteryta.fill(VIT) 29 | 30 | # rita en grön polygon på ytan 31 | pygame.draw.polygon(fönsteryta, GRÖN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))) 32 | 33 | # rita några blå linjer på ytan 34 | pygame.draw.line(fönsteryta, BLÅ, (60, 60), (120, 60), 4) 35 | pygame.draw.line(fönsteryta, BLÅ, (120, 60), (60, 120)) 36 | pygame.draw.line(fönsteryta, BLÅ, (60, 120), (120, 120), 4) 37 | 38 | # rita en blå cirkel på ytan 39 | pygame.draw.circle(fönsteryta, BLÅ, (300, 50), 20, 0) 40 | 41 | # rita en röd ellips på ytan 42 | pygame.draw.ellipse(fönsteryta, RÖD, (300, 250, 40, 80), 1) 43 | 44 | # rita textens bakgrundsrektangel på ytan 45 | pygame.draw.rect(fönsteryta, RÖD, (textrektangel.left - 20, textrektangel.top - 20, textrektangel.width + 40, textrektangel.height + 40)) 46 | 47 | # hämta en pixelmatris från ytan 48 | pixelmatris = pygame.PixelArray(fönsteryta) 49 | pixelmatris[480][380] = SVART 50 | del pixelmatris 51 | 52 | # rita texten på ytan 53 | fönsteryta.blit(text, textrektangel) 54 | 55 | # rita fönstret på skärmen 56 | pygame.display.update() 57 | 58 | # kör spelslingan 59 | while True: 60 | for event in pygame.event.get(): 61 | if event.type == QUIT: 62 | pygame.quit() 63 | sys.exit() 64 | -------------------------------------------------------------------------------- /translations/sv/src/pygameinmatning.py: -------------------------------------------------------------------------------- 1 | import pygame, sys, random 2 | from pygame.locals import * 3 | 4 | # initiera pygame 5 | pygame.init() 6 | huvudklocka = pygame.time.Clock() 7 | 8 | # initiera fönstret 9 | FÖNSTERBREDD = 400 10 | FÖNSTERHÖJD = 400 11 | fönsteryta = pygame.display.set_mode((FÖNSTERBREDD, FÖNSTERHÖJD), 0, 32) 12 | pygame.display.set_caption('Inmatning') 13 | 14 | # skapa färgkonstanter 15 | SVART = (0, 0, 0) 16 | GRÖN = (0, 255, 0) 17 | VIT = (255, 255, 255) 18 | 19 | # skapa spelaren och matbitarnas datastruktur 20 | matbitsräknare = 0 21 | NY_MATBIT = 40 22 | MATBITSTORLEK = 20 23 | spelare = pygame.Rect(300, 100, 50, 50) 24 | matbitar = [] 25 | for i in range(20): 26 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - MATBITSTORLEK), random.randint(0, FÖNSTERHÖJD - MATBITSTORLEK), MATBITSTORLEK, MATBITSTORLEK)) 27 | 28 | # skapa rörelsevariabler 29 | flyttaVänster = False 30 | flyttaHöger = False 31 | flyttaUpp = False 32 | flyttaNer = False 33 | 34 | HASTIGHET = 6 35 | 36 | 37 | # kör spelslingan 38 | while True: 39 | # kontrollera händelser 40 | for event in pygame.event.get(): 41 | if event.type == QUIT: 42 | pygame.quit() 43 | sys.exit() 44 | if event.type == KEYDOWN: 45 | # uppdatera tangentbordsvariablerna 46 | if event.key == K_LEFT or event.key == ord('a'): 47 | flyttaHöger = False 48 | flyttaVänster = True 49 | if event.key == K_RIGHT or event.key == ord('d'): 50 | flyttaVänster = False 51 | flyttaHöger = True 52 | if event.key == K_UP or event.key == ord('w'): 53 | flyttaNer = False 54 | flyttaUpp = True 55 | if event.key == K_DOWN or event.key == ord('s'): 56 | flyttaUpp = False 57 | flyttaNer = True 58 | if event.type == KEYUP: 59 | if event.key == K_ESCAPE: 60 | pygame.quit() 61 | sys.exit() 62 | if event.key == K_LEFT or event.key == ord('a'): 63 | flyttaVänster = False 64 | if event.key == K_RIGHT or event.key == ord('d'): 65 | flyttaHöger = False 66 | if event.key == K_UP or event.key == ord('w'): 67 | flyttaUpp = False 68 | if event.key == K_DOWN or event.key == ord('s'): 69 | flyttaNer = False 70 | if event.key == ord('x'): 71 | spelare.top = random.randint(0, FÖNSTERHÖJD - spelare.height) 72 | spelare.left = random.randint(0, FÖNSTERBREDD - spelare.width) 73 | 74 | if event.type == MOUSEBUTTONUP: 75 | matbitar.append(pygame.Rect(event.pos[0], event.pos[1], MATBITSTORLEK, MATBITSTORLEK)) 76 | 77 | matbitsräknare += 1 78 | if matbitsräknare >= NY_MATBIT: 79 | # addera mera matbitar 80 | matbitsräknare = 0 81 | matbitar.append(pygame.Rect(random.randint(0, FÖNSTERBREDD - MATBITSTORLEK), random.randint(0, FÖNSTERHÖJD - MATBITSTORLEK), MATBITSTORLEK, MATBITSTORLEK)) 82 | 83 | # rita svart bakgrund på ytan 84 | fönsteryta.fill(SVART) 85 | 86 | # flytta spelaren 87 | if flyttaNer and spelare.bottom < FÖNSTERHÖJD: 88 | spelare.top += HASTIGHET 89 | if flyttaUpp and spelare.top > 0: 90 | spelare.top -= HASTIGHET 91 | if flyttaVänster and spelare.left > 0: 92 | spelare.left -= HASTIGHET 93 | if flyttaHöger and spelare.right < FÖNSTERBREDD: 94 | spelare.right += HASTIGHET 95 | 96 | # rita spelaren på ytan 97 | pygame.draw.rect(fönsteryta, VIT, spelare) 98 | 99 | # kontrollera om spelaren överlappar med någon matbit. 100 | for matbit in matbitar[:]: 101 | if spelare.colliderect(matbit): 102 | matbitar.remove(matbit) 103 | 104 | # rita matbitarna 105 | for i in range(len(matbitar)): 106 | pygame.draw.rect(fönsteryta, GRÖN, matbitar[i]) 107 | 108 | # rita fönstret på skärmen 109 | pygame.display.update() 110 | huvudklocka.tick(40) 111 | -------------------------------------------------------------------------------- /translations/sv/src/slantsingling.py: -------------------------------------------------------------------------------- 1 | import random 2 | print('Jag kommer att singla slant 1000 gånger. Gissa hur många gånger det blir krona? (Tryck enter för att börja)') 3 | input() 4 | singlingar = 0 5 | krona = 0 6 | while singlingar < 1000: 7 | if random.randint(0, 1) == 1: 8 | krona = krona + 1 9 | singlingar = singlingar + 1 10 | 11 | if singlingar == 900: 12 | print('900 singlingar och det har blivit krona ' + str(krona) + ' gånger.') 13 | if singlingar == 100: 14 | print('Vid 100 singlingar så har det blivit krona ' + str(krona) + ' gånger.') 15 | if singlingar == 500: 16 | print('Halva jobbet gjort och det har blivit krona ' + str(krona) + ' gånger.') 17 | 18 | print() 19 | print('Av 1000 slantsinglingar så blev det krona ' + str(krona) + ' gånger!') 20 | print('Var du nära?') 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /translations/sv/src/vitsar.py: -------------------------------------------------------------------------------- 1 | print('Vad får du om du korsar en snögubbe med en vampyr?') 2 | input() 3 | print('Frostbett!') 4 | print() 5 | print('Vad kallar tandläkare det som \'tandtrollen\' gör i astronauters tänder?') 6 | input() 7 | print('Svarta hål!') 8 | print() 9 | print('Knack knack.') 10 | input() 11 | print('Vem där?') 12 | input() 13 | print('Avbrytande kon.') 14 | input() 15 | print('Vadå avbrytan', end='') 16 | print('-MUUU!') 17 | -------------------------------------------------------------------------------- /translations/sv/sv_chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | Se till att du installerar Python 3 och inte Python 2! 3 | -------------------------------------------------------------------------------- /translations/sv/sv_chapter4.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 4-2: 2 | ...hoppa in i while-blocket till denna rad. 3 | ...hoppa förbi while-blocket till denna rad. 4 | 5 | Fig 4-3: 6 | brus 7 | nyckelordet if 8 | villkor 9 | nyckelordet while 10 | loopar inte 11 | loopar 12 | -------------------------------------------------------------------------------- /translations/sv/sv_chapter6.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 6-1: 2 | nyckelordet def 3 | parenteser 4 | funktionens namn 5 | kolon 6 | 7 | Fig 6-2: 8 | Start 9 | Visa introduktion 10 | Spelaren väljer en grotta 11 | Kolla om draken är vänlig eller hungrig 12 | Spelaren vinner 13 | Spelaren förlorar 14 | Fråga om ny spelomgång 15 | Slut 16 | -------------------------------------------------------------------------------- /translations/zh-cn/README.md: -------------------------------------------------------------------------------- 1 | Translators 2 | =========== 3 | 4 | Beta Kuang https://github.com/beta 5 | 6 | (You can always check the commit history of the files in this folder to find other translators, if this README is not up to date.) 7 | 8 | Title 9 | ===== 10 | 11 | (Put translated book title here.) 12 | 13 | General Notes 14 | ============= 15 | 16 | (Add notes for other translators here.) -------------------------------------------------------------------------------- /translations/zh-cn/chapter1.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 1-1: 2 | 确保安装的是 Python 3,而不是 Python 2! -------------------------------------------------------------------------------- /translations/zh-cn/chapter1.txt: -------------------------------------------------------------------------------- 1 | 第一章 2 | 安装 Python 3 | 4 | 本章中包含的内容: 5 | • 下载和安装 Python 解释器 6 | • 如何使用本书 7 | • 本书位于http://inventwithpython.com的网站 8 | 9 | 你好!这本书将通过制作视频游戏来教会你编程。只要你弄明白本书中的游戏是如何运作的,你就可以创造你自己的游戏了。你只需要一台电脑、一个叫 Python 解释器的软件,以及这本书。Python 解释器可以从网络上免费下载。 10 | 11 | 当我还是个孩子的时候,有一本和本书类似的书教会了我写程序和游戏,而且有趣又简单。现在我长大了,我仍然从编程中获得乐趣并以之为生。但即使你长大后不会成为程序员,编程也依然是一项有用的、有趣的、值得掌握的技能。 12 | 13 | 计算机令人惊奇,而学会为它们编程序并不像人们所想的那样困难。如果你能读懂这本书,你就能为电脑编写程序。计算机程序是一组计算机能够理解的指令,就好像故事书是一组读者可以理解的句子一样。既然视频游戏也是计算机程序,它们也是由指令构成的。 14 | 15 | 要给计算机下指令,你需要用计算机能够理解的语言编写程序。本书将教给你一门名叫 Python 的编程语言,除此之外还有很多的编程语言,有 BASIC、Java、JavaScript、PHP 和 C++ 等等。 16 | 17 | 当我还小的时候,BASIC 是通常要学的第一门语言,然而自那以后,诸如 Python 的新的编程语言不断地被创造出来。Python 甚至比 BASIC 更容易学!然而它仍然是一门被专业程序员使用的严肃的语言,许多人不论在工作中还是写着玩的时候都会用 Python。 18 | 19 | 和 Xbox、PlayStation 或者 Wii 的游戏相比,你照着这本书写出的程序看起来非常简单,因为它们是用来教你编程的基础知识的,这些游戏并没有华丽的图像。它们是故意被设计得这么简单,让你能专注于学习编程。游戏不一定要复杂才有趣。 20 | 21 | 下载和安装 Python 22 | 23 | 你需要安装一个名叫 Python 解释器的软件,这个解释器能够理解你用 Python 语言写的程序。从现在起,我会把“Python 解释器软件”简称为“Python”。 24 | 25 | 注意!确保安装的是 Python 3,而不是 Python 2。本书中的程序使用 Python 3 编写,如果你尝试在 Python 2 中运行它们,你会得到一堆错误。这非常重要,我在图 1-1 中画了一只企鹅提醒你安装 Python 3,你一定不会忽略掉这条提示。 26 | 27 | 图 1-1: 一只告诉你要安装 Python 3 的怪企鹅。 28 | 29 | 在 Windows 上,下载 Python 安装程序(文件的后缀名是 .msi)然后双击运行。按照安装程序在屏幕上显示的如下指示来安装 Python: 30 | 31 | 1. 选择“为所有用户安装”然后点击“下一步”; 32 | 2. 安装到 C:\Python34 文件夹然后点击“下一步”; 33 | 3. 点击“下一步”来跳过自定义 Python 的部分。 34 | 35 | 在 Mac OS X 上,从网站上下载适合你所用的 OS X 版本的 .dmg 文件然后双击打开。按照安装程序在屏幕上显示的如下指令来安装 Python: 36 | 37 | 1. 当 DMG 包在新窗口中打开后,双击 Python.mpkg 文件。你可能需要输入管理员密码; 38 | 2. 点击“继续”跳过欢迎部分,然后点击“同意”来接受协议; 39 | 3. 选择 HD Macintosh(或者其他你的硬盘对应的名字)然后点击“安装”。 40 | 41 | 如果你运行 Ubuntu,你可以从 Ubuntu 软件中心按照以下步骤安装 Python: 42 | 43 | 1. 打开 Ubuntu 软件中心; 44 | 2. 在窗口右上角的搜索栏中输入 Python; 45 | 3. 选择 IDLE(使用 Python 3.4)或者其他最新的版本; 46 | 4. 点击“安装”。你可能需要输入管理员密码来完成安装。 47 | 48 | 运行 IDLE 49 | 50 | IDLE 是英文 Interactive DeveLopment Environment 的缩写,意思是交互式开发环境。开发环境是用来写 Python 程序的、类似文字处理程序的软件。在不同的系统上运行 IDLE 的方法是不同的。 51 | 52 | 在 Windows 上,点击左下角的开始按钮,输入 IDLE 然后选择 IDLE (Python GUI)。 53 | 54 | 在 Mac OS X 上,打开 Finder 窗口,点击应用程序,然后点击 Python 3.4,最后点击 IDLE 图标。 55 | 56 | 在 Ubuntu 或 Linux 上,打开一个终端窗口输入“idle3”。你大概也可以点击屏幕上方的应用程序,然后选择编程中的 IDLE 3。 57 | 58 | 第一次运行 IDLE 出现的窗口是交互式终端,如图 1-2 所示。你可以在交互式终端的“>>>”提示符之后输入 Python 指令,Python 就可以执行它们。在显示完指令的结果之后,一个新的“>>>”提示符就会出现并等待你的下一条指令。 59 | 60 | 图1-2:在 Windows、OS X 和 Ubuntu Linux 上的 IDLE 交互终端 61 | 62 | 如何使用本书 63 | 64 | 本书中的大多数章节都会以该章特色程序的示例运行开始,让你看到程序运行时的样子。用户输入的内容用粗体字显示。 65 | 66 | 你应该亲自把程序代码输入到 IDLE 文件编辑器中,而不是下载或者赋值/粘贴这些程序。如果你花时间亲自编写代码,你会对编程留下更深的印象。 67 | 68 | 行号和空格 69 | 70 | 在输入本书中的源代码时,不要输入每行开头处的行号。例如,如果你再本书中看到如下代码: 71 | 72 | 9. number = random.randint(1, 20) 73 | 74 | 你不需要输入左侧的“9.”以及在它之后的空格。只需要输入: 75 | 76 | number = random.randint(1, 20) 77 | 78 | 这些行号只是为了方便在书中指明某一行,它们并不是程序源代码的一部分。 79 | 80 | 除了行号之外,原样输入代码的内容。注意,有很多行代码开头都缩进了四或八个空格。IDLE 中的每个字符都是一样宽的,因此可以通过数上一行或下一行的字符个数来确定空格的数量。 81 | 82 | 例如,下面的代码中空格用黑色正方形 ▪ 标记出来以便让你看到: 83 | 84 | while guesses < 10: 85 | ▪▪▪▪if number == 42: 86 | ▪▪▪▪▪▪▪▪print('Hello') 87 | 88 | 本书中的文字环绕 89 | 90 | 一些指令的长度过长,在书页的一行中无法完全显示,会延伸到下一行。当你输入这样的代码的时候,全都输入到一行,不要按回车键。根据代码左侧的行号可以判断是否出现了一条新的指令,例如,下面的代码只有两条指令: 91 | 92 | 1. print('这是第一条指令!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 93 | xxxxxxxxxxxx') 94 | 2. print('这是第二条指令,而不是第三条指令。') 95 | 96 | 第一条指令延伸到了下一行,让代码看起来好像一共有三条指令。那只是因为本书的书页不够宽,第一条指令显示不完整罢了。 97 | 98 | 寻找在线帮助 99 | 100 | 本书的网站是 http://inventwithpython.com/zh-cn,你可以在网站中找到与本书相关的各种资源。书中有些链接使用了短域名 invpy.com/zh-cn。 101 | 102 | 本书的网站 http://reddit.com/r/inventwithpython 是一个询问与本书有关的编程问题的好地方。一般的 Python 问题请到 LearnProgramming 和 LearnPython 网站提问,地址分别是 http://reddit.com/r/learnprogramming 和 http://reddit.com/r/learnpython。 103 | 104 | 你还可以将你的编程问题发送给我,邮箱地址是 al@inventwithpython.com。 105 | 106 | 记住,让别人能更容易地帮助你解决编程问题,有很多好方法。阅读这些网站的常见问题(FAQ)部分了解提问的正确方式。在询问编程问题是,参考以下规则: 107 | 108 | • 如果你输入本书中的程序但发生了错误,首先用在线纠错工具(http://invpy.com/zh-cn/diff)检查你的输入。复制你的代码并粘贴到纠错工具中,从而找出你的代码与书中代码的不同之处。 109 | • 当你描述错误时,解释清楚你究竟要做什么。这会让帮助你的人知道你是否采用了正确的方法。 110 | • 复制并粘贴完整的错误信息和代码。 111 | • 搜索网络,看看别人是否已经问过(并回答过)你的问题。 112 | • 说清楚为了解决问题你尝试了哪些方法。这能让别人知道你为了自己解决问题已经花了一番功夫。 113 | • 礼貌提问。不要强求帮助或者要求帮助者作出快速的回答。 114 | 115 | 询问别人“为什么我的程序不能运行?”并不能为他们提供任何信息。告诉他们你想做什么、你遇到的具体问题以及你的操作系统和版本。 -------------------------------------------------------------------------------- /translations/zh-cn/chapter2.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 2-3: 2 | 值 3 | 运算符 4 | 表达式 5 | 6 | Fig 2-4: 7 | spam 8 | 9 | Fig 2-5: 10 | eggs 11 | fizz 12 | -------------------------------------------------------------------------------- /translations/zh-cn/chapter3.figures.txt: -------------------------------------------------------------------------------- 1 | None. -------------------------------------------------------------------------------- /translations/zh-cn/chapter4.figures.txt: -------------------------------------------------------------------------------- 1 | Fig 4-2: 2 | ...go inside the while-block to here. 3 | ...go past the while-block to here. 4 | 5 | Fig 4-3: 6 | fizzy 7 | if keyword 8 | condition 9 | while keyword 10 | doesn't loop 11 | loops 12 | --------------------------------------------------------------------------------