├── .DS_Store ├── Fall20 ├── .DS_Store ├── FrequentlyAskedQuestions (FAQ).md ├── Guide.md ├── README.md ├── figures │ ├── ChangeTheme.png │ ├── HTML_Browser.png │ ├── HTML_Explorer.png │ ├── Maintxt.png │ ├── Teaching.Codes New Version.png │ ├── Teaching.Codes Uninstall.png │ ├── Teaching.Codes Version 1212JB.png │ ├── commit_and_push_failed1.png │ ├── commit_and_push_failed2.png │ ├── connection.PNG │ └── could not open.PNG ├── week01 │ ├── README.md │ └── Solutions.md ├── week02 │ ├── README.md │ └── Solutions.md ├── week03 │ ├── README.md │ └── Solutions.md ├── week04 │ ├── README.md │ └── Solutions.md ├── week05 │ ├── README.md │ └── Solutions.md ├── week06 │ ├── README.md │ └── Solutions.md ├── week07 │ ├── README.md │ └── Solutions.md ├── week08 │ ├── README.md │ └── Solutions.md ├── week09 │ ├── README.md │ └── Solutions.md └── week10 │ ├── README.md │ └── Solutions.md ├── Fall21 ├── .DS_Store ├── week01 │ ├── README.md │ └── Solutions.md ├── week02 │ ├── README.md │ ├── Solutions.md │ └── q9.png ├── week03 │ ├── README.md │ └── Solutions.md ├── week04 │ ├── README.md │ └── Solutions.md ├── week05 │ ├── README.md │ └── Solutions.md ├── week06 │ ├── README.md │ └── Solution.md ├── week07 │ ├── README.md │ └── Solutions.md ├── week08 │ ├── README.md │ └── Solutions.md ├── week09 │ ├── README.md │ └── Solutions.md └── week10 │ ├── README.md │ └── Solutions.md ├── Fall24 ├── .DS_Store ├── project1 │ └── solution.py ├── project2 │ ├── .DS_Store │ └── solution.py ├── project3 │ ├── .DS_Store │ └── solution.py ├── week01 │ ├── .DS_Store │ ├── Cmpe 150 Lab 1_ Introduction.pdf │ ├── additional │ │ ├── README.md │ │ └── Solutions.md │ ├── questions.py │ └── solutions.py ├── week02 │ ├── .DS_Store │ ├── Cmpe 150 Lab 2_ Functions.pdf │ ├── functions.md │ ├── functions_solution.py │ ├── turtle_example.py │ └── turtle_example_solution.py ├── week03 │ ├── .DS_Store │ ├── Cmpe 150 Lab 3_ File I_O.pdf │ ├── IO.py │ ├── IO_solution.py │ ├── additional │ │ ├── .DS_Store │ │ ├── drawingFlower.md │ │ └── drawing_flower_solution.py │ ├── drawingWithInput.md │ ├── drawing_with_input_solution.py │ ├── drawing_with_input_solution_without_for.py │ └── onlineSession │ │ ├── Q1.py │ │ ├── Q2.py │ │ ├── Q3.py │ │ ├── Q4.py │ │ ├── Q5.py │ │ ├── Q6.py │ │ ├── Q7.py │ │ └── Q8.py ├── week04 │ ├── .DS_Store │ ├── Cmpe 150 Lab 4_ IfElse.pdf │ ├── Cmpe 150 Lab 4_ Recursion.pdf │ ├── additional │ │ ├── .DS_Store │ │ ├── README.md │ │ └── additional_solutions.py │ ├── fibonacci.md │ ├── fibonacci_solution.py │ ├── ifelse.py │ ├── ifelse_solution.py │ └── onlineSession │ │ ├── Q1.py │ │ ├── Q2.py │ │ ├── Q3.py │ │ ├── Q4.py │ │ ├── Q5.py │ │ ├── Q6.py │ │ ├── Q7.py │ │ └── Q8.py ├── week05 │ ├── .DS_Store │ ├── Cmpe 150 Lab 5_ For Loops.pdf │ ├── ForLoopQuestions.md │ ├── additional │ │ ├── ForLoopAdditionalQuestions.md │ │ └── additional_solutions.py │ ├── for_loop_solutions.py │ ├── house.py │ └── house_solution.py ├── week06 │ ├── .DS_Store │ ├── Cmpe 150 Lab 6_ Lists and Tuples.pdf │ ├── ListsTuplesQuestions.md │ ├── lists_tuples_solutions.py │ └── onlineSession │ │ ├── .DS_Store │ │ ├── forLoops │ │ ├── Q1.py │ │ ├── Q2.py │ │ └── Q3.py │ │ └── listsTuples │ │ ├── Q1.py │ │ ├── Q2.py │ │ └── Q3.py ├── week07 │ ├── .DS_Store │ ├── Cmpe 150 Lab 7_ Dictionaries.pdf │ ├── Dictionaries.md │ ├── dictionary_solutions.py │ └── random_examples.py ├── week08 │ ├── .DS_Store │ ├── Cmpe 150 Lab 8_ While Loops.pdf │ ├── WhileLoops.md │ └── while_loop_solutions.py ├── week09 │ ├── .DS_Store │ ├── Cmpe 150 Lab 9_ Strings.pdf │ ├── Strings.md │ └── string_solutions.py ├── week10 │ ├── .DS_Store │ ├── Cmpe 150 Lab 10_ Sets.pdf │ ├── Sets.md │ └── set_solutions.py ├── week11 │ ├── AdvancedListsDictionariesTuples.md │ └── advanced_list_and_dictionary_solutions.py └── week12 │ ├── AnimatingShapes.md │ └── animating_shape_solutions.py ├── PyCharm Installation Guide.pdf ├── README.md ├── Spring21 ├── .DS_Store ├── figures │ ├── 1616341138563.png │ ├── 1616342184949.png │ ├── 1616342517499.png │ ├── ChangeTheme.png │ ├── HTML_Browser.png │ ├── HTML_Explorer.png │ ├── Maintxt.png │ ├── PythonInstaller.png │ ├── Teaching.Codes New Version.png │ ├── Teaching.Codes Uninstall.png │ ├── Teaching.Codes Version 1212JB.png │ ├── commit_and_push_failed1.png │ ├── commit_and_push_failed2.png │ ├── connection.PNG │ ├── could not open.PNG │ ├── project-guide │ │ ├── 1618485979513.png │ │ ├── 1618486104949.png │ │ ├── 1618486398394.png │ │ ├── 1618486497781.png │ │ ├── 1618486752521.png │ │ ├── 1618486890025.png │ │ ├── 1618487070207.png │ │ ├── 1618487098652.png │ │ ├── 1618487165943.png │ │ ├── 1618487273664.png │ │ ├── 1618487440503.png │ │ └── 1618487934948.png │ ├── python-customize.png │ ├── python-final.png │ ├── python-optional.png │ └── team-fixed.png ├── week01 │ ├── README.md │ └── figures │ │ └── moodle.png ├── week02 │ ├── README.md │ └── Solutions.md ├── week03 │ ├── README.md │ └── Solutions.md ├── week04 │ ├── README.md │ └── Solutions.md ├── week05 │ ├── README.md │ └── Solutions.md ├── week06 │ ├── README.md │ └── Solutions.md ├── week07 │ ├── README.md │ └── Solutions.md ├── week08 │ ├── README.md │ └── Solutions.md ├── week09 │ ├── README.md │ └── Solutions.md ├── week10 │ ├── README.md │ └── Solutions.md ├── week11 │ ├── README.md │ ├── Solutions.md │ └── data │ │ └── paragraph.txt └── week12 │ ├── Exploring 'Game of Thrones' Battles.ipynb │ ├── External Libraries.md │ ├── README.md │ ├── Solutions.md │ ├── Widely used Python libraries Numpy and Pandas.ipynb │ └── figures │ ├── 1623750783722.png │ ├── 1623751368006.png │ └── 1623752067689.png ├── Spring22 ├── ReadME └── python2022spring22 │ ├── week10 │ ├── README.md │ ├── ps7 chapter list week10.pptx │ └── solutions.md │ ├── week12 │ ├── README.md │ ├── Solutions.md │ └── ps8 chapter dict week12.pptx │ ├── week4 │ ├── Solutions.md │ ├── lab3.pdf │ └── questions.md │ ├── week6 │ ├── README.md │ ├── Solutions.md │ └── chapter4.pdf │ ├── week7 │ ├── README.md │ ├── Solutions.md │ └── cmpe150-chp4-p2.pptx │ └── week9 │ ├── README.md │ ├── Solutions.md │ └── string.pptx └── figures ├── 1616341138563.png ├── 1616342184949.png ├── 1616342517499.png ├── ChangeTheme.png ├── HTML_Browser.png ├── HTML_Explorer.png ├── Maintxt.png ├── TC.png ├── Teaching.Codes New Version.png ├── Teaching.Codes Uninstall.png ├── Teaching.Codes Version 1212JB.png ├── commit_and_push_failed1.png ├── commit_and_push_failed2.png ├── connection.PNG ├── correspondence.png ├── could not open.PNG ├── project-guide ├── 1618485979513.png ├── 1618486104949.png ├── 1618486398394.png ├── 1618486497781.png ├── 1618486752521.png ├── 1618486890025.png ├── 1618487070207.png ├── 1618487098652.png ├── 1618487165943.png ├── 1618487273664.png ├── 1618487440503.png └── 1618487934948.png ├── python-customize.png ├── python-final.png └── python-optional.png /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/.DS_Store -------------------------------------------------------------------------------- /Fall20/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/.DS_Store -------------------------------------------------------------------------------- /Fall20/FrequentlyAskedQuestions (FAQ).md: -------------------------------------------------------------------------------- 1 | # Frequently Asked Question (FAQ) 2 | 3 | 1. How can I install the software required for this course? 4 | 5 | * Follow the [Installation Guide](InstallationGuide.md). 6 | 7 | 2. How can I update Teaching Codes Plugin? 8 | 9 | * Follow the [Teaching Codes Update Guide](TeachingCodesGuide.md) 10 | 11 | 3. How can I open/submit a project? 12 | 13 | * Follow the [Teaching Codes Guide](TeachingCodesGuide.md) 14 | 15 | 4. I encountered an error during installation/using Teaching Codes, how can I get help? 16 | 17 | * Check the questions/solutions in this document and then Technical Support Forum on Moodle. If you can't find the solution, send an email to cmpe150.mail@gmail.com. 18 | 19 | 7. Teaching.Codes Plugin displays 'Nothing to show' 20 | * If you have a Macbook with M1 chip 21 | 22 | * Make sure that you install PyCharm 2021.2.2 for Intel with Rosetta 2. 23 | * Then follow the next steps in [Installation Guide](InstallationGuide.md) 24 | * You may also have to disable SIP following [this link](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection). 25 | * Otherwise, 26 | * Make sure you do not extract the Teaching.Codes zip file. 27 | * Download the Teaching.Codes zip using Chrome instead of Safari. 28 | * Then, reinstall the plugin by following [Teaching.Codes guide](TeachingCodesGuide.md) 29 | 8. I can't see the button names in the plugin 30 | 31 | * Change the theme by following these steps: 32 | 33 | * Inside PyCharm, for Windows, click ***File-->Settings***; for MacOS, click ***PyCharm-->Preferences*** and find ***Appearance&Behavior*** on the left. 34 | * Go into **Appearance** under ***Appearance&Behavior*** 35 | * Change Theme from Intellij Light to something else. (**Darcula** seems fine.) 36 | * Click **OK** 37 | 38 | ![](figures/ChangeTheme.png) 39 | 9. Teaching.Codes plugin disappeared 40 | * To open the plugin, click *View > Tool Windows > Teaching.Codes* 41 | 42 | ![](figures/TC.png) 43 | 44 | 10. I have deleted the contents of **Main.py** 45 | * Restore it from **Main.py.txt** under corresponding question's **src** folder 46 | 47 | ![](figures/Maintxt.png) 48 | 49 | 11. I can't see the Question description 50 | * Open the **Question.html** under **WebContent** in a browser 51 | * Right click on **Question.html** file 52 | * Click **Open in Browser.** 53 | 54 | 55 | 56 | 12. If there are multiple questions and you see the same description for both questions or still blank page. 57 | 58 | * Right click on **Question.html** file 59 | * Choose "**Show in Explorer/Finder**". This step open the folder that contains the html file. 60 | 61 | 62 | 63 | * From the folder, open the html file. 64 | 65 | 13. I can't see the Exam Results 66 | 67 | * Log out, and log in to the Teaching.Codes plugin. 68 | * Select the class from the Navigator. Wait a while for the class to load. 69 | * Click the ExamResults tab. When you click Open under a question, if nothing is happening: 70 | * Click the Projects tab on the left of ExamResults 71 | * Then, go into ExamResults once again. Now, when you click Open, you should be able to see your results. 72 | 73 | 14. What counts as **cheating**: 74 | * **Information exchange between students:** Giving and Receiving information to/from your colleagues both count as cheating. 75 | * **Using codes from any source other than the materials of our course:** You can consult internet or books to learn and improve your programming skills. But you shouldn't use any material that is not your own work in the projects and exams. 76 | -------------------------------------------------------------------------------- /Fall20/README.md: -------------------------------------------------------------------------------- 1 | # CmpE150 - Fall 2020 2 | 3 | Bogazici University CmpE 150 Introduction to Computing (Python programming language) Notes 4 | 5 | **E-mails:** 6 | 7 | - [burak.suyunu@boun.edu.tr](mailto:burak.suyunu@boun.edu.tr) 8 | - [gokce.uludogan@boun.edu.tr](mailto:gokce.uludogan@boun.edu.tr) 9 | - [zeynep.yirmibesoglu@boun.edu.tr](mailto:zeynep.yirmibesoglu@boun.edu.tr) 10 | 11 | **Additional Materials** 12 | 13 | - http://www.pythontutor.com/visualize.html 14 | 15 | 16 | ### [Week 1](week01/) 17 | 18 | - Variables 19 | - Expressions 20 | - Statements 21 | 22 | ### [Week 2](week02/) 23 | 24 | - Conditional Execution 25 | 26 | ### [Week 3](week03/) 27 | 28 | - Loops and Iterations 29 | 30 | ### [Week 4](week04/) 31 | 32 | - Nested Loops 33 | 34 | ### [Week 5](week05/) 35 | 36 | - Functions 37 | 38 | ### [Week 6](week06/) 39 | 40 | - Lists and Tuples 41 | 42 | ### [Week 7](week07/) 43 | 44 | - Lists and Tuples 45 | 46 | ### [Week 8](week08/) 47 | 48 | - Strings 49 | 50 | ### [Week 9](week09/) 51 | 52 | - Strings and Files 53 | 54 | ### [Week 10](week10/) 55 | 56 | - Dictionaries and Sets 57 | -------------------------------------------------------------------------------- /Fall20/figures/ChangeTheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/ChangeTheme.png -------------------------------------------------------------------------------- /Fall20/figures/HTML_Browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/HTML_Browser.png -------------------------------------------------------------------------------- /Fall20/figures/HTML_Explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/HTML_Explorer.png -------------------------------------------------------------------------------- /Fall20/figures/Maintxt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/Maintxt.png -------------------------------------------------------------------------------- /Fall20/figures/Teaching.Codes New Version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/Teaching.Codes New Version.png -------------------------------------------------------------------------------- /Fall20/figures/Teaching.Codes Uninstall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/Teaching.Codes Uninstall.png -------------------------------------------------------------------------------- /Fall20/figures/Teaching.Codes Version 1212JB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/Teaching.Codes Version 1212JB.png -------------------------------------------------------------------------------- /Fall20/figures/commit_and_push_failed1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/commit_and_push_failed1.png -------------------------------------------------------------------------------- /Fall20/figures/commit_and_push_failed2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/commit_and_push_failed2.png -------------------------------------------------------------------------------- /Fall20/figures/connection.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/connection.PNG -------------------------------------------------------------------------------- /Fall20/figures/could not open.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall20/figures/could not open.PNG -------------------------------------------------------------------------------- /Fall20/week01/README.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | ## Question 1 4 | 5 | Write a program that takes 3 integers from the user and then prints the sum, mean and multiple of the numbers. 6 | 7 | | Input | Output | 8 | | -------- | ---------------- | 9 | | 13 27 14 | 54 18.00 4914| 10 | 11 |
12 | 13 | ## Question 2 14 | 15 | Using the formula below of compound interest, take the **principal amount (A)**, **interest rate (i)** (per month) and **duration (n)** (months) and print the final amount. 16 | 17 | 18 | 19 | 20 | | Input | Output | 21 | | --------- | ------- | 22 | | 1000 12 5 | 1762.34 | 23 | | 500 12 5 | 881.17 | 24 | 25 |
26 | 27 | ## Question 3 28 | 29 | Write a program which takes radius of a circle from user and calculate the perimeter and surface of the defined circle. 30 | 31 | **You can get the value of pi from math module (from math import pi)** 32 | 33 | | Input | Output | 34 | | ----- | --------------------------- | 35 | | 4 | 25.1327412287 50.2654824574 | 36 | | 8 | 50.2654824574 201.06192983 | 37 | 38 |
39 | 40 | ## Question 4 41 | 42 | Write a program that takes a positive number from user and calculate the sum from 0 to that positive number. 43 | 44 | **You do not need to use any loops or developed coding** 45 | 46 | | Input | Output | 47 | | ----- | ------ | 48 | | 10 | 55 | 49 | | 5 | 15 | 50 | 51 |
52 | 53 | ## Question 5 54 | 55 | Write a program which takes the values in **Ohm** of two parallel resistances and the generator's voltage in **Volt** respectively and print the currents that passes by each resistance. 56 | 57 | 58 | 59 | 60 | | Input | Output | 61 | | ------ | ------ | 62 | | 2 8 40 | 20 5 | 63 | | 5 5 10 | 2 2 | 64 | 65 |
66 | 67 | ## Question 6 68 | 69 | Write a program which replaces the values of two integers. 70 | 71 | | Input | Output | 72 | | ----- | ------ | 73 | | 5 10 | 10 5 | 74 | 75 |
76 | 77 | ## Question 7 78 | 79 | Write a program which takes a character and prints its ASCII value. 80 | 81 | | Input | Output | 82 | | ----- | ------ | 83 | | A | 65 | 84 | | E | 69 | 85 | 86 |
87 | 88 | ## Question 8 89 | 90 | Write a program which takes a lowercase letter as input and print the uppercase version of the given letter. 91 | 92 | | Input | Output | 93 | | ----- | ------ | 94 | | a | A | 95 | | b | B | 96 | | B | B | 97 | 98 |
99 | 100 | ## Question 9 101 | 102 | Write a program that calculates the volume of a sphere by taking its radius from user. 103 | 104 | | Input | Output | 105 | | ----- | ------------- | 106 | | 3 | 113.097335529 | 107 | | 6 | 904.778684234 | 108 | 109 |
110 | 111 | ## Question 10 112 | 113 | Write a program that calculates the amount of seconds in a given period of years, months, days, hours and minutes respectively. 114 | 115 | * 1 year = 365 days 116 | * 1 month = 30 days 117 | 118 | | Input | Output | 119 | | --------- | --------- | 120 | | 5 2 4 3 0 | 163220400 | 121 | | 1 1 1 1 1 | 34218060 | 122 | 123 |
124 | 125 | ## Question 11 126 | 127 | Write a program that takes 3 integers from the user and then prints the sum of odd numbers. 128 | 129 | | INPUT | OUTPUT | 130 | | ------ | ------ | 131 | | 3 4 5 | 8 | 132 | | 2 2 4 | 0 | 133 | | 1 9 15 | 25 | -------------------------------------------------------------------------------- /Fall20/week01/Solutions.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | ## Q1 4 | 5 | ```python 6 | num1 = int(input("Please enter first number: ")) 7 | num2 = int(input("Please enter second number: ")) 8 | num3 = int(input("Please enter third number: ")) 9 | 10 | print("Sum is: " + str(num1+num2+num3)) 11 | print("Mean is: %.2f" % ((num1+num2+num3)/3)) 12 | print("Multiple is: %d" % (num1*num2*num3)) 13 | ``` 14 | 15 |
16 | 17 | ## Q2 18 | ```python 19 | A = int(input("Plese enter the principal amount: ")) 20 | i = int(input("Plese enter the interest rate per month: ")) 21 | n = int(input("Plese enter the duration in months: ")) 22 | 23 | print("Final amount is: " + str(A*(1+i/100)**n)) 24 | ``` 25 | 26 |
27 | 28 | ## Q3 29 | ```python 30 | from math import pi 31 | 32 | r = int(input("Plese enter a radius: ")) 33 | 34 | print("The perimeter of the circle with given radius is: " + str(2*pi*r)) 35 | print("The surface of the circle with given radius is: " + str(pi*r**2)) 36 | ``` 37 | 38 |
39 | 40 | ## Q4 41 | ```python 42 | n = int(input("Plese enter a number: ")) 43 | 44 | print("The sum till the given number is: " + str((n*(n+1))/2)) 45 | 46 | ``` 47 | 48 |
49 | 50 | ## Q5 51 | ```python 52 | r1 = int(input("Plese enter the value of first resistance in OHMs: ")) 53 | r2 = int(input("Plese enter the value of first resistance in OHMs: ")) 54 | v = int(input("Plese enter the value of tension voltage in volts: ")) 55 | 56 | print("The current in R1 is: " + str(v/r1)) 57 | print("The current in R2 is: " + str(v/r2)) 58 | ``` 59 | 60 |
61 | 62 | ## Q6 63 | ```python 64 | a = int(input("Plese enter the first number: ")) 65 | b = int(input("Plese enter the second number: ")) 66 | 67 | # Version 1 (Classic Swap): 68 | temp = a 69 | a = b 70 | b = temp 71 | 72 | # Version 2 (Without using extra variable): 73 | # a = a + b 74 | # b = a - b 75 | # a = a - b 76 | 77 | # Version 3 (Python Variation): 78 | # a, b = b, a 79 | 80 | print("Here they are inversed: " + str(a) + " " + str(b)) 81 | ``` 82 | 83 |
84 | 85 | ## Q7 86 | ```python 87 | ch = (input("Enter a character: ")) 88 | 89 | print("The ascii value of " + ch + " is: " + str(ord(ch))) 90 | ``` 91 | 92 |
93 | 94 | ## Q8 95 | ```python 96 | ll = input("Plese enter a lowercase letter: ") 97 | 98 | ul = chr(ord(ll) + ord("A") - ord("a")) 99 | 100 | print("Here is the upparcase version: " + ul) 101 | ``` 102 | 103 |
104 | 105 | ## Q9 106 | ```python 107 | import math 108 | 109 | r = int(input("Plese enter a radius: ")) 110 | 111 | print("The volume of the sphere with the given radius is: " + str(4.0/3*math.pi*math.pow(r,3))) 112 | ``` 113 | 114 |
115 | 116 | ## Q10 117 | ```python 118 | y = int(input("Plese enter the amount of years: ")) 119 | mo = int(input("Plese enter the amount of months: ")) 120 | d = int(input("Plese enter the amount of days: ")) 121 | h = int(input("Plese enter the amount of hours: ")) 122 | mi = int(input("Plese enter the amount of minutes: ")) 123 | 124 | summ = 0 125 | 126 | summ += y * 365 * 24 * 60 * 60 127 | summ += mo * 30 * 24 * 60 * 60 128 | summ += d * 24 * 60 * 60 129 | summ += h * 60 * 60 130 | summ += mi * 60 131 | 132 | print("Given duration is: " + str(summ)+" seconds.") 133 | ``` 134 | 135 |
136 | 137 | ## Q11 138 | ```python 139 | a = int(input("Please enter the first number: ")) 140 | b = int(input("Please enter the second number: ")) 141 | c = int(input("Please enter the third number: ")) 142 | 143 | print(a * (a % 2) + b * (b % 2) + c * (c % 2)) 144 | ``` 145 | -------------------------------------------------------------------------------- /Fall20/week02/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | ```python 4 | number = float(input()) 5 | if number >= 0: 6 | print(number) 7 | else: 8 | print(-number) 9 | ``` 10 | 11 | ## Question 2 12 | 13 | ```python 14 | num1 = int(input()) 15 | num2 = int(input()) 16 | if num1 % num2 == 0: 17 | print(num1//num2) 18 | else: 19 | print(num1%num2) 20 | ``` 21 | 22 | ## Question 3 23 | 24 | ```python 25 | a = int(input()) 26 | b = int(input()) 27 | c = int(input()) 28 | if a > b and b > c: 29 | print(c, a) 30 | elif a > c and c > b: 31 | print(b, a) 32 | elif b > c and c > a: 33 | print(a, b) 34 | elif b > a and a > c: 35 | print(c, b) 36 | elif c > a and a > b: 37 | print(b, c) 38 | else: 39 | print(a, c) 40 | ``` 41 | 42 | 43 | 44 | ```python 45 | a = int(input()) 46 | b = int(input()) 47 | c = int(input()) 48 | max_num, min_num = None, None 49 | if (a >= b) and (a >= c): 50 | max_num = a 51 | elif (b >= a) and (b >= c): 52 | max_num = b 53 | else: 54 | max_num = c 55 | 56 | if (a <= b) and (a <= c): 57 | min_num = a 58 | elif (b <= a) and (b <= c): 59 | min_num = b 60 | else: 61 | min_num = c 62 | 63 | print(min_num, max_num) 64 | ``` 65 | 66 | 67 | 68 | ```python 69 | a = int(input()) 70 | b = int(input()) 71 | c = int(input()) 72 | 73 | max_num = a if a > b else b 74 | max_num = c if c > max_num else max_num 75 | 76 | min_num = a if a < b else b 77 | min_num = c if c < min_num else min_num 78 | 79 | print(min_num, max_num) 80 | ``` 81 | 82 | 83 | 84 | ## Question 4 85 | 86 | ```python 87 | num_input = int(input()) 88 | if num_input % 2 == 0: 89 | print('Divisible by 2') 90 | if num_input % 3 == 0: 91 | print('Divisible by 3') 92 | if num_input % 5 == 0: 93 | print('Divisible by 5') 94 | 95 | ``` 96 | 97 | ## Question 5 98 | 99 | ```python 100 | age = int(input()) 101 | if age >= 0 and age <= 17: 102 | print('Child') 103 | elif age >= 18 and age <= 64: 104 | print('Can Work') 105 | elif age >= 65: 106 | print('Retired') 107 | ``` 108 | 109 | ## Question 6 110 | 111 | ```python 112 | year = int(input()) 113 | 114 | if year % 400 == 0: 115 | print('Leap year') 116 | elif year % 100 == 0: 117 | print('Not a leap year') 118 | elif year % 4 == 0: 119 | print('Leap year') 120 | else: 121 | print('Not a leap year') 122 | 123 | ``` 124 | 125 | ```python 126 | year = int(input()) 127 | 128 | if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): 129 | print('Leap year') 130 | else: 131 | print('Not a leap year') 132 | ``` 133 | 134 | ## Question 7 135 | 136 | ```python 137 | mt = int(input()) 138 | lab = int(input()) 139 | ass = int(input()) 140 | proj = int(input()) 141 | final = int(input()) 142 | overall_grade = mt * 0.2 + lab * 0.1 + ass * 0.15 + proj * 0.25 + final * 0.3 143 | if overall_grade >= 75: 144 | print('A') 145 | elif overall_grade >= 55: 146 | print('B') 147 | elif overall_grade >= 35: 148 | print('C') 149 | else: 150 | print('F') 151 | ``` 152 | 153 | ## Question 8 154 | 155 | ```python 156 | mass = int(input()) 157 | height = float(input()) 158 | bmi = mass / height ** 2 159 | print('%.1f' % bmi) 160 | if bmi <= 15: 161 | print('Very severely underweight') 162 | elif bmi <= 16: 163 | print('Severely underweight') 164 | elif bmi <= 18.5: 165 | print('Underweight') 166 | elif bmi <= 25: 167 | print('Normal (healthy weight)') 168 | elif bmi <= 30: 169 | print('Overweight') 170 | elif bmi <= 35: 171 | print('Obese Class I (Moderately obese)') 172 | elif bmi <= 40: 173 | print('Obese Class II (Severely obese)') 174 | else: 175 | print('Obese Class III (Very severely obese)') 176 | ``` 177 | 178 | ## Question 9 179 | 180 | ```python 181 | a = int(input()) 182 | b = int(input()) 183 | 184 | if a % b == 0 or b % a == 0: 185 | print('Multiple') 186 | else: 187 | print('Not Multiple') 188 | ``` 189 | 190 | ## Question 10 191 | 192 | ```python 193 | import math 194 | a = float(input()) 195 | b = float(input()) 196 | c = float(input()) 197 | disc = b ** 2 - 4 * a * c 198 | if disc > 0: 199 | print((-b + math.sqrt(disc)) / 2 * a, (-b - math.sqrt(disc)) / 2 * a) 200 | elif disc == 0: 201 | print((-b + math.sqrt(disc)) / 2 * a) 202 | ``` 203 | 204 | -------------------------------------------------------------------------------- /Fall20/week05/Solutions.md: -------------------------------------------------------------------------------- 1 | # Q1 2 | 3 | ```python 4 | def is_leap_year(year): 5 | if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): 6 | return True 7 | else: 8 | return False 9 | leap = is_leap_year(1904) 10 | if leap: 11 | print('leap year') 12 | else: 13 | print('not a leap year') 14 | ``` 15 | 16 | # Q2 17 | 18 | ```python 19 | def calculate_cost(cost, is_student): 20 | if is_student: 21 | cost /= 2 22 | return cost 23 | print(calculate_cost(10, True)) 24 | ``` 25 | 26 | # Q3 27 | 28 | ## a 29 | 30 | ```python 31 | def power(number, n=2): 32 | result = 1 33 | for i in range(n): 34 | result *= number 35 | return result 36 | print(power(5)) 37 | print(power(3, 2)) 38 | print(power(4, 3)) 39 | ``` 40 | 41 | ## b 42 | 43 | ```python 44 | def print_powers(number): 45 | for i in range(6): 46 | print(power(number, i+1)) 47 | print_powers(3) 48 | ``` 49 | 50 | # Q4 51 | 52 | ```python 53 | def is_prime(number): 54 | for i in range(2, number): 55 | if number % i == 0: 56 | return False 57 | return True 58 | print(is_prime(7)) 59 | print(is_prime(12)) 60 | ``` 61 | 62 | # Q5 63 | 64 | ```python 65 | def is_super(number): 66 | for i in range(2, number): 67 | if number % i == 0 and not is_prime(i): 68 | return False 69 | return True 70 | 71 | res = is_super(15) 72 | if res: 73 | print('Suuuper') 74 | else: 75 | print(':(') 76 | ``` 77 | 78 | # Q6 79 | 80 | ```python 81 | def abundant_number(number): 82 | sum_divisors = 0 83 | for i in range(1, number): 84 | if number % i == 0: 85 | sum_divisors += i 86 | if sum_divisors > number: 87 | return True 88 | else: 89 | return False 90 | 91 | def numbers_in_range(lower, upper): 92 | flag = 1 93 | for i in range(lower, upper + 1): 94 | if abundant_number(i): 95 | flag = 0 96 | print(i, end=' ') 97 | if flag: 98 | print('no abundant number') 99 | 100 | numbers_in_range(3, 10) 101 | numbers_in_range(10, 40) 102 | ``` 103 | 104 | # Q7 105 | 106 | ```python 107 | def is_relatively_prime(a, b): 108 | isrltprime = True 109 | 110 | for i in range(2,a+1): 111 | if a % i == 0 and b % i == 0: 112 | isrltprime = False 113 | 114 | if isrltprime: 115 | print("Relatively Prime") 116 | else: 117 | print("Not Relatively Prime") 118 | 119 | is_relatively_prime(2, 5) 120 | is_relatively_prime(12, 8) 121 | ``` 122 | 123 | # Q8 124 | 125 | ## a 126 | 127 | ```python 128 | def modulus(a, b): 129 | while a > b: 130 | a -= b 131 | return a 132 | 133 | print(modulus(17, 3)) 134 | print(modulus(27, 5)) 135 | ``` 136 | 137 | ## b & c 138 | 139 | ```python 140 | def gcd(a, b): 141 | if a < b: 142 | a, b = b, a 143 | while b != 0: 144 | mod = a % b 145 | a, b = b, mod 146 | return a 147 | 148 | def lcm(a, b): 149 | return a * b // gcd(a, b) 150 | 151 | print(gcd(2, 5)) # 1 152 | print(gcd(12, 8)) # 4 153 | 154 | print(lcm(2, 5)) # 10 155 | print(lcm(12, 8)) # 24 156 | ``` 157 | 158 | # Q9 159 | 160 | ```python 161 | def is_square(n): 162 | if n >= 0: 163 | root = n ** (1 / 2) 164 | if root == int(root): 165 | return True 166 | else: 167 | return False 168 | return False 169 | ``` 170 | 171 | # Q10 172 | 173 | ```python 174 | def multiply(*args): 175 | result = 1 176 | for i in args: 177 | result *= i 178 | return result 179 | 180 | print(multiply(42,96)) 181 | ``` 182 | 183 | -------------------------------------------------------------------------------- /Fall20/week06/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Reverse 2 | 3 | ```python 4 | N = int(input()) 5 | 6 | list1 = list() 7 | for i in range(N): 8 | list1.append(int(input())) 9 | 10 | # a 11 | print(list1[::-1]) 12 | 13 | # b 14 | list1 = list1[::-1] 15 | # list1.reverse() 16 | print(list1) 17 | ``` 18 | 19 | ## Question 2 - Let's Count 20 | 21 | ```python 22 | def find_freq(list1): 23 | freq = [0] * 100 24 | for l in list1: 25 | freq[l] += 1 26 | for i, f in enumerate(freq): 27 | if f > 0: 28 | print(str(i) + ' --> ' + str(f)) 29 | 30 | 31 | find_freq([5, 10, 2, 5, 50, 5, 10, 1, 2, 2]) 32 | ``` 33 | 34 | ## Question 3 - Inception 35 | 36 | ```python 37 | N = int(input()) 38 | M = int(input()) 39 | 40 | list1 = list() 41 | for i in range(N): 42 | list1.append(int(input())) 43 | 44 | list2 = list() 45 | for i in range(M): 46 | list2.append(int(input())) 47 | 48 | for j in range(len(list2) - len(list1)): 49 | isFound = True 50 | for i in range(len(list1)): 51 | if list1[i] != list2[j + i]: 52 | isFound = False 53 | break 54 | 55 | if isFound: 56 | print(j) 57 | break 58 | ``` 59 | 60 | ## Question 4 - Pairs 61 | 62 | ```python 63 | def find_pairs(list1, X): 64 | for i, l1 in enumerate(list1): 65 | for l2 in list1[i + 1:]: 66 | if l1 + l2 == X: 67 | print("(%d, %d)" % (l1, l2)) 68 | 69 | 70 | find_pairs([2, 4, 3, 5, 7, 8, 9], 7) 71 | ``` 72 | 73 | ## Question 5 - fix34 74 | 75 | ```python 76 | N = int(input()) 77 | list1 = list() 78 | for i in range(N): 79 | list1.append(int(input())) 80 | 81 | for i in range(len(list1)): 82 | if list1[i] == 3: 83 | for j in range(len(list1)): 84 | if list1[j] == 4 and list1[j - 1] != 3: 85 | list1[i + 1], list1[j] = list1[j], list1[i + 1] 86 | 87 | print(list1) 88 | ``` 89 | 90 | ## Question 6 - Bubble Sort 91 | 92 | ```python 93 | def bubbleSort(arr): 94 | n = len(arr) 95 | 96 | # Traverse through all array elements 97 | for i in range(n - 1): 98 | # range(n) also work but outer loop will repeat one time more than needed. 99 | 100 | # Last i elements are already in place 101 | for j in range(0, n - i - 1): 102 | 103 | # traverse the array from 0 to n-i-1 104 | # Swap if the element found is greater 105 | # than the next element 106 | if arr[j] > arr[j + 1]: 107 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 108 | 109 | # temp = arr[j] 110 | # arr[j] = arr[j+1] 111 | # arr[j+1] = temp 112 | 113 | return arr 114 | 115 | 116 | print(bubbleSort([4, 2, 8, 6, 7, 3, 1, 5])) 117 | ``` 118 | 119 | ## Question 7 - Concatwise 120 | 121 | ```python 122 | def concatwise(list1, list2): 123 | return [i + j for i, j in zip(list1, list2)] 124 | 125 | 126 | list1 = ["M", "na", "i", "Pat"] 127 | list2 = ["y", "me", "s", "rick"] 128 | print(concatwise(list1, list2)) 129 | ``` 130 | 131 | ## Question 8 - Combine Reverse 132 | 133 | ```python 134 | def combine_reverse(list1, list2): 135 | for x, y in zip(list1, list2[::-1]): 136 | print(x, y) 137 | 138 | 139 | list1 = [10, 20, 30, 40] 140 | list2 = [100, 200, 300, 400] 141 | combine_reverse(list1, list2) 142 | ``` 143 | 144 | ## Question 9 - Remove X 145 | 146 | ```python 147 | list1 = [5, 20, 15, 20, 25, 50, 20] 148 | 149 | 150 | def removeValue(sampleList, val): 151 | return [value for value in sampleList if value != val] 152 | 153 | 154 | resList = removeValue(list1, 20) 155 | print(resList) 156 | ``` -------------------------------------------------------------------------------- /Fall20/week10/Solutions.md: -------------------------------------------------------------------------------- 1 | # Dictionaries 2 | 3 | ## Question 1 - Split the Bill 4 | ```python 5 | # https://www.codewars.com/kata/5641275f07335295f10000d0/python 6 | group = { 7 | 'A': 20, 8 | 'B': 15, 9 | 'C': 10 10 | } 11 | 12 | def split_the_bill(x): 13 | diff = sum(x.values())/float(len(x)) 14 | return {k: x[k]-diff for k in x} 15 | 16 | print(split_the_bill(group)) 17 | ``` 18 | 19 | ## Question 2 - Different Types 20 | This was from another school's intro to computing question. It was due to 10.11. 21 | ```python 22 | def separate(my_list): 23 | my_dict = dict() 24 | for i in my_list: 25 | if type(i) in my_dict: 26 | my_dict[type(i)].append(i) 27 | else: 28 | my_dict[type(i)] = [i] 29 | return my_dict 30 | 31 | original_list = [10, 4.20, False, 'Word', 'CMPE150', 30, 3.5, 9.99, 'oblivion', True, 68, 88, "88"] 32 | seperated_list = separate(original_list) 33 | 34 | for k,v in seperated_list.items(): 35 | print(k," -> ",v) 36 | ``` 37 | 38 | ## Question 3 - Sorting Dictionary 39 | 40 | ```python 41 | def sort_dict(d): 42 | return sorted(d.items(), key=lambda x: x[1], reverse=True) 43 | 44 | print(sort_dict({3:1, 2:2, 1:3})) 45 | ``` 46 | 47 | ## Question 4 - Letter Count 48 | 49 | ```python 50 | sentence = input() 51 | my_dict = dict() 52 | total_letter =0 53 | for letter in sentence: 54 | if letter.isalpha(): 55 | letter = letter.lower() 56 | total_letter+=1 57 | if letter not in my_dict: 58 | my_dict[letter] = 1 59 | else: 60 | my_dict[letter] += 1 61 | 62 | sorted_dict = sorted(my_dict.items(), key=lambda x: (-x[1],x[0])) 63 | for k,v in sorted_dict: 64 | print(k,"->","{:.2f}".format(v/total_letter)) 65 | 66 | ``` 67 | 68 | ## Question 5 - Dictionary Merge 69 | ```python 70 | def merge(*dicts): 71 | mydict = dict() 72 | for d in dicts: 73 | for k, v in d.items(): 74 | if k in mydict: 75 | mydict[k].append(d[k]) 76 | else: 77 | mydict[k] = [v] 78 | return mydict 79 | 80 | print(merge({"A": 1, "B": 2} , {"A": 3})) 81 | ``` 82 | 83 | 84 | ## Question 6 - Zip Two Lists 85 | 86 | ```python 87 | list1 = ["melih", "burak", "ahmet", "recep", "melis"] 88 | list2 = [1,2,3,4,5] 89 | def dict_2_lists(list1, list2): 90 | return dict(zip(list1, list2)) 91 | 92 | print(dict_2_lists(list1,list2)) 93 | 94 | 95 | ``` 96 | 97 | 98 | # Sets 99 | 100 | ## Question 1 - List to Distinct 101 | 102 | ```python 103 | def distinct_elements(lst): 104 | return list(set(lst)) 105 | distinct_list = distinct_elements([3,5,4,4,7,11,2,8]) 106 | print(distinct_list) 107 | ``` 108 | 109 | ## Question 2 - Set Operations 110 | 111 | ```python 112 | A = {1, 2, 3, 4, 5, 6} 113 | B = {1, 1, 2, 7, 11} 114 | 115 | def set_operations(set1, set2): 116 | print("A ∪ B = {}".format(set1.union(set2))) 117 | print("A ∩ B = {}".format(set1.intersection(set2))) 118 | print("A / B = {}".format(set1.difference(set2))) 119 | print("B / A = {}".format(set2.difference(set1))) 120 | 121 | set_operations(A, B) 122 | 123 | ``` 124 | 125 | ## Question 3 - Diff 126 | 127 | ```python 128 | def list_values(list1, list2): 129 | print('Missing values in list1', set(list2).difference(set(list1))) 130 | print('Additional values in list1', set(list1).difference(set(list2))) 131 | 132 | 133 | lst1 = [1, 2, 3, 4, 5, 6] 134 | lst2 = [4, 5, 6, 7, 8] 135 | list_values(lst1, lst2) 136 | ``` 137 | 138 | ## Question 4 - Distinct String 139 | 140 | ```python 141 | def is_distinct(string): 142 | return len(set(string)) == len(string) 143 | 144 | 145 | print(is_distinct('violate')) 146 | ``` 147 | 148 | ## Question 5 - Numgram 149 | 150 | ```python 151 | def is_numgram(string): 152 | numbers = ''.join([str(i) for i in list(range(10))]) 153 | common_digits = set(string).intersection(set(numbers)) 154 | return len(common_digits) == len(numbers) 155 | 156 | 157 | numgram_result = is_numgram('SAS102BAD347 HELP5689') 158 | if numgram_result: 159 | print('Numgram') 160 | else: 161 | print('Not a numgram') 162 | ``` 163 | -------------------------------------------------------------------------------- /Fall21/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall21/.DS_Store -------------------------------------------------------------------------------- /Fall21/week01/README.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | **a)** Create two integer variables, and print them 4 | 5 | **b)** Take two integers from the user, and print them 6 | 7 | **c)** Take two integers from the user (a, b), and then print their sum, difference, product, power and remainder. 8 | 9 | | Input | Output | 10 | | ----- | ---------------- | 11 | | 13 5 | 18 8 65 371293 3 | 12 | 13 | ## Question 2 14 | 15 | **a)** Create an integer, a float, and a string variable. Print their types, using the type() function. 16 | 17 | **b)** Take an integer, a float, and a string variable from the user. Print the variables. 18 | 19 | ## Question 3 20 | 21 | Write a program that takes 3 integers from the user and then prints the sum, mean and multiple of the numbers. 22 | 23 | | Input | Output | 24 | | -------- | ------------- | 25 | | 13 27 14 | 54 18.00 4914 | 26 | 27 | ## Question 4 28 | 29 | Using the formula below of compound interest, take the **principal amount (A)**, **interest rate (i)** (per month) and **duration (n)** (months) and print the final amount. 30 | 31 | 32 | 33 | 34 | | Input | Output | 35 | | --------- | ------- | 36 | | 1000 12 5 | 1762.34 | 37 | | 500 12 5 | 881.17 | 38 | 39 | ## Question 5 40 | 41 | Guess the outcome of each statement. Then check the results. 42 | 43 | Hint: You can multiply strings with integers. It basically performs the concatenation operation n many times. 44 |
45 | 46 | - print(int('6') + int('4'))
47 | - print('1' + '4')
48 | - print(int(3.9)) 49 | - print(str(5.3) + '2.7')
50 | - print(int('5') * str(0.6))
51 | - print(float('3' + '8.6'))
52 | - print(3.5 + 6.7)
53 | - print(2 ** 3 ** 2 / 32) 54 | - print(str(4.4) + str(7.3))
55 | - print(int(6.5) + float('6.5'))
56 | - print(int(4.5 + 3.2))
57 | - print(int(3.2) + int(float(str(3.2))))
58 | 59 | Remarks: 60 |
61 | 62 | 63 | - Observe that float-to-int type conversion is not a rounding operation. int(3.9) = 3. To round floats, we will use a built-in function called round(). Stay tuned!
64 | - As you see, we can multiply strings with integers, but not floats. What does 3.14 times "pi" mean, anyway?
65 | - Exponent operator ** has right-to-left associativity.
66 |
67 |
68 | 69 | ## Question 6 70 | 71 | Write a program that calculates the amount of seconds in a given period of years, months, days, hours and minutes respectively. 72 | 73 | * 1 year = 365 days 74 | * 1 month = 30 days 75 | 76 | | Input | Output | 77 | | --------- | --------- | 78 | | 5 2 4 3 0 | 163220400 | 79 | | 1 1 1 1 1 | 34218060 | 80 | 81 | ## Question 7 82 | 83 | There is a cash machine with an infinite supply of 5tl banknotes and 1tl coins inside it. 84 | 85 | Write a function that takes an integer representing the amount of money requested by a customer. The function then prints the number of banknotes and coins given to the customer. (Machine must prefer giving away banknotes instead of coins if possible) 86 | 87 | | Input | Output | 88 | | ----- | ---------------------------------------- | 89 | | 57 | 5tl banknotes: 11
1tl banknotes: 2 | 90 | | 269 | 5tl banknotes: 53
1tl banknotes: 4 | 91 | 92 | ## Question 8 93 | 94 | Write a function that takes a radius and returns the volume of the sphere. 95 | 96 | | Input | Output | 97 | | ----- | ------------- | 98 | | 3 | 113.097335529 | 99 | | 6 | 904.778684234 | 100 | 101 | ## Question 9 102 | 103 | Write a function called `power` that takes two integer parameter as **number** and **n**. The function should return the **nth** power of **number**. 104 | 105 | | Input | Output | 106 | | ----- | ------ | 107 | | 5 2 | 25 | 108 | | 3 2 | 9 | 109 | | 4 3 | 64 | 110 | 111 | ## Question 10 & 11 requires knowledge of Boolean expressions and they are for those with Python background. Solve them without using if statements. 112 | 113 | ## Question 10 114 | 115 | Write a program that takes 3 integers from the user and then prints the sum of odd numbers. 116 | 117 | | Input | Output | 118 | | ------ | ------ | 119 | | 3 4 5 | 8 | 120 | | 2 2 4 | 0 | 121 | | 1 9 15 | 25 | 122 | 123 | ## Question 11 124 | 125 | When you multiply an integer by itself, the result is a square number. 126 | 127 | Write a function that takes an integer and determines whether it is a square number or not. 128 | 129 | | Input | Output | 130 | | ----- | ------ | 131 | | 25 | True | 132 | | 23 | False | 133 | | 0 | True | 134 | | -1 | False | 135 | -------------------------------------------------------------------------------- /Fall21/week01/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question1 2 | 3 | ### a 4 | 5 | ```python 6 | x = 5 7 | y = 3 8 | print(x) 9 | print(y) 10 | ``` 11 | 12 | ### b 13 | 14 | ```python 15 | x = int(input()) 16 | y = int(input()) 17 | print(x) 18 | print(y) 19 | ``` 20 | 21 | ### c 22 | 23 | ```python 24 | x = int(input()) 25 | y = int(input()) 26 | print(x+y, x-y, x*y, x**y, x%y) 27 | ``` 28 | 29 | ## Question 2 30 | 31 | ### a 32 | 33 | ```python 34 | x = 5 35 | y = 1.7 36 | z = "I am a string!" 37 | print(type(x)) 38 | print(type(y)) 39 | print(type(z)) 40 | ``` 41 | 42 | ### b 43 | 44 | ```python 45 | x = int(input()) 46 | y = float(input()) 47 | z = input() 48 | print(x, y, z) 49 | ``` 50 | 51 | ## Question 3 52 | 53 | ```python 54 | x = int(input()) 55 | y = int(input()) 56 | z = int(input()) 57 | sum = x + y + z 58 | print(sum, sum/3, x * y * z) 59 | ``` 60 | 61 | ## Question 4 62 | 63 | ```python 64 | A = int(input()) 65 | i = int(input()) 66 | n = int(input()) 67 | # print(A * (1 + (i / 100)) ** n) 68 | print('%.2f' % (A * (1 + (i / 100)) ** n)) 69 | ``` 70 | 71 | ## Question 5 72 | 73 | ```python 74 | print(int('6') + int('4')) 75 | print('1' + '4') 76 | print(int(3.9)) 77 | print(str(5.3) + '2.7') 78 | print(int('5') * str(0.6)) 79 | print(float('3' + '8.6')) 80 | print(3.5 + 6.7) 81 | print(2 ** 3 ** 2 / 32) 82 | print(str(4.4) + str(7.3)) 83 | print(int(6.5) + float('6.5')) 84 | print(int(4.5 + 3.2)) 85 | print(int(3.2) + int(float(str(3.2)))) 86 | ``` 87 | 88 | ## Question 6 89 | 90 | ```python 91 | years = int(input()) 92 | months = int(input()) 93 | days = int(input()) 94 | hours = int(input()) 95 | minutes = int(input()) 96 | 97 | total_days = years * 365 + month * 30 + days 98 | total_hours = total_days * 24 + hours 99 | total_minutes = total_hours * 60 + minutes 100 | print(total_minutes * 60) 101 | ``` 102 | 103 | ## Question 7 104 | 105 | ```python 106 | # as a program 107 | # money = int(input()) 108 | # print('5tl banknotes:', money / 5) 109 | # print('1tl banknotes:', money % 5) 110 | # with functions 111 | def to_banknotes(money): 112 | print('5tl banknotes:', money / 5) 113 | print('1tl banknotes:', money % 5) 114 | 115 | to_banknotes(57) 116 | to_banknotes(269) 117 | ``` 118 | 119 | ## Question 8 120 | 121 | ```python 122 | def volume(radius): 123 | return 4 / 3 * radius ** 3 * 3 124 | 125 | print(volume(3)) 126 | result = volume(6) 127 | print(result) 128 | ``` 129 | 130 | ## Question 9 131 | 132 | ```python 133 | def power(number, n): 134 | return number ** n 135 | 136 | print(power(5, 2)) 137 | print(power(3, 2)) 138 | ``` 139 | 140 | ## Question 10 141 | 142 | ```python 143 | a = int(input()) 144 | b = int(input()) 145 | c = int(input()) 146 | 147 | print(a * (a % 2) + b * (b % 2) + c * (c % 2)) 148 | ``` 149 | 150 | ## Question 11 151 | 152 | ```python 153 | def is_square(number): 154 | sqroot = number ** 0.5 155 | sqroot_int = int(sqroot) 156 | return number == sqroot_int ** 2 157 | 158 | print(is_square(23)) 159 | print(is_square(25)) 160 | ``` 161 | 162 | -------------------------------------------------------------------------------- /Fall21/week02/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | ```python 4 | X = float(input()) 5 | Y = float(input()) 6 | total = X + Y 7 | percent_X = X/total * 100 8 | percent_Y = Y/total * 100 9 | #print("%.2f%% %.2f%%" % (percent_X, percent_Y)) 10 | print("{:.2f}% {:.2f}%".format(percent_X, percent_Y)) 11 | ``` 12 | 13 | ## Question 2 14 | 15 | ```python 16 | weight = float(input()) 17 | height = int(input()) / 100 18 | bmi = weight / (height ** 2) 19 | # print('%.2f' % bmi) 20 | print("{:.2f}".format(bmi)) 21 | ``` 22 | 23 | ## Question 3 24 | 25 | ```python 26 | x = int(input()) 27 | print((5 ** 5628) % 100 * (x - 1)) 28 | ``` 29 | 30 | ## Question 4 31 | 32 | ```python 33 | a = float(input()) 34 | b = float(input()) 35 | c = float(input()) 36 | 37 | fraction_a = a - a // 1 38 | fraction_b = b - b // 1 39 | fraction_c = c - c // 1 40 | 41 | print(fraction_a, fraction_b, fraction_c) 42 | ``` 43 | 44 | ## Question 5 45 | 46 | ```python 47 | def division(dividend, divisor) 48 | quotient = dividend // divisor 49 | remainder = dividend % divisor 50 | print("quotient =", quotient, "remainder =", remainder) 51 | 52 | division(9, 2) 53 | division(156, 13) 54 | 55 | ``` 56 | 57 | ## Question 6 58 | 59 | ```python 60 | def number_of_bacteria(initial, t1, total_time): 61 | return initial * 2**int(total_time/t1) 62 | print(number_of_bacteria(1, 1, 2)) 63 | print(number_of_bacteria(5, 3, 8)) 64 | ``` 65 | 66 | ## Question 7 67 | 68 | ```python 69 | def distance(x1, y1, x2, y2): 70 | return ((x2-x1)**2 + (y2-y1)**2)**0.5 71 | 72 | print(distance(5, 10, 10, 22)) 73 | ``` 74 | 75 | ## Question 8 76 | 77 | ```python 78 | def laps(r, x1, x2, total_time): 79 | pi = 3.14 80 | circumference = 2 * pi * r 81 | total_run_1 = total_time * x1 82 | total_run_2 = total_time * x2 83 | total_laps1 = int(total_run_1 / circumference) 84 | total_laps2 = int(total_run_2 / circumference) 85 | return total_laps1, total_laps 86 | runner1, runner2 = laps(100, 300, 400, 30) 87 | ``` 88 | 89 | ## Question 9 90 | 91 | ```python 92 | import math 93 | N = 20 94 | C = 5 95 | def find_index(X): 96 | page_index = math.ceil(X / (N*C)) 97 | page_items = X % (N*C) 98 | line_index = math.ceil(page_items / C) 99 | col_index = page_items - (line_index - 1) * C 100 | return page_index, line_index, col_index 101 | num = int(input("Number: ")) 102 | page_ix, line_ix, col_ix = find_index(num) 103 | print(page_ix, line_ix, col_ix) 104 | ``` 105 | 106 | ## Question 10 107 | 108 | ```python 109 | def passer_rating(comp, att, yards, td, inter): 110 | C = (((comp/att * 100)-30) / 20) 111 | Y = (((yards/att)-3) / 4) 112 | T = ((td/att) * 20) 113 | I = (2.375 - ((inter/att) * 35)) 114 | return ((C + Y + T + I) / 6) * 100 115 | comp = int(input()) 116 | att = int(input()) 117 | yards = int(input()) 118 | td = int(input()) 119 | inter = int(input()) 120 | print(passer_rating(cmp, att, yards, td, inter)) 121 | ``` 122 | 123 | ## Question 11 124 | 125 | ```python 126 | def estimated_population(year): 127 | num_year = year - 2021 128 | seconds = 365 * 24 * 60 * 60 # days * hours * minutes * seconds 129 | birth_per_year = seconds // 15 130 | death_per_year = seconds // 20 131 | immigrant_per_year = seconds // 100 132 | return population + num_year * (birth_per_year + immigrant_per_year - death_per_year) 133 | population = 84.5 * (10** 6) 134 | print(estimated_population(2030)) 135 | ``` 136 | 137 | -------------------------------------------------------------------------------- /Fall21/week02/q9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall21/week02/q9.png -------------------------------------------------------------------------------- /Fall21/week03/Solutions.md: -------------------------------------------------------------------------------- 1 | # Loops 2 | 3 | ## Question 1 - Staaaars 4 | 5 | ### Question 1a 6 | 7 | ```python 8 | print('*') 9 | ``` 10 | 11 | ### Question 1b 12 | 13 | ```python 14 | print('**********') 15 | ``` 16 | 17 | ### Question 1c 18 | 19 | ```python 20 | N = int(input()) 21 | 22 | for i in range(N): 23 | print('*') 24 | ``` 25 | 26 | ### Question 1d 27 | 28 | ```python 29 | N = int(input()) 30 | 31 | for i in range(N): 32 | print('*', end='') 33 | ``` 34 | 35 | ## Question 2 - Numbeeeers 36 | 37 | ```python 38 | N = int(input()) 39 | 40 | for i in range(N): 41 | print(i+1, end=' ') 42 | 43 | # OR 44 | 45 | for i in range(1, N+1): 46 | print(i, end=' ') 47 | ``` 48 | 49 | ## Question 3 - Hooping Numbers 50 | 51 | ### Question 3a 52 | 53 | ```python 54 | A = int(input()) 55 | B = int(input()) 56 | t = int(input()) 57 | 58 | for i in range(A, B+1, t): 59 | print(i, end=' ') 60 | ``` 61 | 62 | ### Alternative 63 | 64 | ```python 65 | A, B, t = input().strip().split() 66 | A = int(A) 67 | B = int(B) 68 | t = int(t) 69 | 70 | for i in range(A, B+1, t): 71 | print(i, end=' ') 72 | ``` 73 | 74 | 75 | 76 | ### Question 3b 77 | 78 | ```python 79 | A = int(input()) 80 | B = int(input()) 81 | t = int(input()) 82 | 83 | for i in range(B, A-1, -t): 84 | print(i, end=' ') 85 | ``` 86 | 87 | ### Alternative 88 | 89 | ```python 90 | A, B, t = input().strip().split() 91 | A = int(A) 92 | B = int(B) 93 | t = int(t) 94 | 95 | for i in range(B, A-1, -t): 96 | print(i, end=' ') 97 | ``` 98 | 99 | 100 | 101 | 102 | 103 | ## Question 4 - Numbeeeers 104 | 105 | ```python 106 | A = int(input()) 107 | B = int(input()) 108 | 109 | result = 0 110 | 111 | for i in range(A+1, B): 112 | result += i 113 | 114 | print(result) 115 | ``` 116 | 117 | ## Question 5 - Average Team 118 | 119 | ```python 120 | N = int(input()) 121 | 122 | result = 0 123 | 124 | for _ in range(N): 125 | x = int(input()) 126 | # result = result + x 127 | result += x 128 | 129 | print(result/N) 130 | ``` 131 | 132 | ## Question 6 - Boom Boom POW 133 | 134 | ```python 135 | a = int(input("a: ")) 136 | b = int(input("b: ")) 137 | 138 | result = 1 139 | 140 | for _ in range(b): 141 | result *= a 142 | 143 | print(result) 144 | 145 | ``` 146 | 147 | ## Question 7 - Factorial 148 | 149 | ```python 150 | n = int(input()) 151 | 152 | result = 1 153 | for i in range(n): 154 | result *= i+1 155 | 156 | print(result) 157 | ``` 158 | 159 | ## Question 8 - Sum of Products 160 | 161 | ```python 162 | n = int(input()) 163 | total = 0 164 | 165 | for i in range(n): 166 | x1, x2 = input().strip().split() 167 | total += int(x1) * int(x2) 168 | print(total) 169 | ``` 170 | 171 | 172 | 173 | # Nested Loops 174 | 175 | ## Question 1 - R\*\*\*tangle 176 | 177 | ### Question 1a 178 | 179 | ```python 180 | N = int(input("N: ")) 181 | M = int(input("M: ")) 182 | 183 | for _ in range(N): 184 | for _ in range(M): 185 | print("*", end='') 186 | print() 187 | ``` 188 | 189 | ### Question 1b 190 | 191 | ```python 192 | N = int(input("N: ")) 193 | M = int(input("M: ")) 194 | 195 | for _ in range(M): 196 | print("*", end='') 197 | print() 198 | 199 | for _ in range(N-2): 200 | print("*", end='') 201 | for _ in range(M-2): 202 | print("-", end='') 203 | print("*") 204 | 205 | for _ in range(M): 206 | print("*", end='') 207 | ``` 208 | 209 | ## Question 2 - TriNumber 210 | 211 | ### Question 2a 212 | 213 | ```python 214 | N = int(input()) 215 | 216 | for i in range(1, N+1): 217 | for j in range(i): 218 | print(i, end='') 219 | print() 220 | ``` 221 | 222 | ### Question 2b 223 | 224 | ```python 225 | N = int(input()) 226 | 227 | for i in range(1, N+1): 228 | for j in range(i): 229 | print(j+1, end='') 230 | print() 231 | ``` 232 | 233 | ### Question 2c 234 | 235 | ```python 236 | N = int(input()) 237 | x = int(input()) 238 | 239 | for i in range(1, N+1): 240 | for j in range(1, i+1): 241 | print(x ** j, end=' ') 242 | print() 243 | ``` 244 | 245 | ## Question 3 - TriHard 246 | 247 | ```python 248 | N = int(input()) 249 | 250 | for i in range(1, N+1): 251 | for j in range(N - i): 252 | print('-', end='') 253 | for j in range(i): 254 | print('*', end='') 255 | print() 256 | ``` 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /Fall21/week05/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Fibonacci 2 | 3 | ```python 4 | N = int(input()) 5 | 6 | prev = 0 7 | curr = 1 8 | 9 | for _ in range(3, N+1): 10 | next = prev + curr 11 | prev = curr 12 | curr = next 13 | 14 | if N <= 0: 15 | print("Invalid!") 16 | elif N == 1: 17 | print(prev) 18 | else: 19 | print(curr) 20 | ``` 21 | 22 | ## Question 2 - Second Largest 23 | 24 | ```python 25 | x = int(input()) 26 | largest = 0 27 | second = 0 28 | 29 | while x != 0: 30 | if x > largest: 31 | second = largest 32 | largest = x 33 | elif x > second: 34 | second = x 35 | x = int(input()) 36 | 37 | print(largest-second) 38 | ``` 39 | 40 | ## Question 3 - Digiiiits 41 | 42 | ```python 43 | x = int(input()) 44 | 45 | count = 0 46 | even_sum = 0 47 | 48 | while x > 0: 49 | digit = x % 10 50 | if digit % 2 == 0: 51 | even_sum += digit 52 | count += 1 53 | 54 | x //= 10 55 | 56 | print(count, even_sum) 57 | ``` 58 | 59 | ## Question 4 - Positive Mental Attitude 60 | 61 | ```python 62 | odd_sum = 0 63 | 64 | x = int(input()) 65 | while x >= 0: 66 | if x % 2 == 1: 67 | odd_sum += x 68 | x = int(input()) 69 | 70 | print(odd_sum) 71 | ``` 72 | 73 | ## Question 5 - NoBig 74 | 75 | ```python 76 | total_sum = 0 77 | count = 1 78 | 79 | x = int(input()) 80 | y = int(input()) 81 | total_sum += x 82 | while y <= x: 83 | total_sum += y 84 | count += 1 85 | 86 | x = y 87 | y = int(input()) 88 | 89 | print(total_sum/count) 90 | ``` 91 | 92 | ## Question 6 - Guess 93 | 94 | ```python 95 | import random 96 | 97 | number = random.randint(1,100) 98 | count = 0 99 | 100 | while True: 101 | guess = input("Make your guess: ") 102 | guess = int(guess) 103 | count += 1 104 | 105 | if guess < number: 106 | print("Too low!") 107 | elif guess > number: 108 | print("Too high!") 109 | else: 110 | print("You got it!") 111 | print("And it only took you",count,"tries!") 112 | break 113 | ``` 114 | 115 | ## Question 7 - Sum Facts 116 | 117 | ```python 118 | x = int(input()) 119 | 120 | fact_sum = 0 121 | 122 | while x > 0: 123 | digit = x % 10 124 | fact = 1 125 | for i in range(2, digit+1): 126 | fact *= i 127 | fact_sum += fact 128 | 129 | x //= 10 130 | 131 | print(fact_sum) 132 | ``` 133 | 134 | ## Question 8 - Sum of Digits 135 | 136 | ```python 137 | n = int(input()) 138 | 139 | while n >= 10: 140 | sum = 0 141 | while n: 142 | sum += n%10 143 | n //= 10 144 | n = sum 145 | 146 | print(n) 147 | ``` 148 | 149 | ## Question 9 - Prime factors 150 | 151 | ### Question 9a 152 | 153 | ```python 154 | number = int(input()) 155 | for i in range(1, number + 1): 156 | if number % i == 0: 157 | print(i, end =" ") 158 | 159 | ``` 160 | 161 | ### Question 9b 162 | 163 | ```python 164 | number = int(input()) 165 | for i in range(2, number + 1): 166 | while number % i == 0: 167 | number //= i 168 | print(i, end=" ") 169 | 170 | ``` 171 | 172 | This works because at any point in the loop, number doesn't have any factors smaller than `i`. Therefore, `i` has to be prime if it divides `number`. 173 | 174 | ### Question 9c 175 | 176 | ```python 177 | number = int(input()) 178 | firstPrime = True 179 | for i in range(2, number + 1): 180 | count = 0 181 | while number % i == 0: 182 | number //= i 183 | count += 1 184 | if count > 0: 185 | if firstPrime: 186 | firstPrime = False 187 | else: 188 | print(" * ", end="") 189 | print(i, "^", count, end="") 190 | 191 | ``` 192 | 193 | ## Question 10 - Palindromic Primes 194 | 195 | ```python 196 | def reverse_number(number): 197 | reverse = 0 198 | while num != 0: 199 | digit = num % 10 200 | num = num // 10 201 | reverse = reverse * 10 + digit 202 | return reverse 203 | 204 | def is_prime(number): 205 | if number <= 1: 206 | return False 207 | for i in range(2, number): 208 | if number % i == 0: 209 | return False 210 | return True 211 | start = int(input()) 212 | end = int(input()) 213 | 214 | for i in range(start, end + 1): 215 | if reverse_number(i) == i and is_prime(i): 216 | print(i, end = " ") 217 | 218 | ``` 219 | 220 | -------------------------------------------------------------------------------- /Fall21/week06/README.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | Write a program that takes an integer n and then prints related hailstone sequence until 1. If number is even, divide it by 2. If number is odd, multiply it by 3 and add 1. 4 | 5 | | INPUT | OUTPUT | 6 | | ----- | ---------------------- | 7 | | 20 | 20 10 5 16 8 4 2 1 | 8 | | 12 | 12 6 3 10 5 16 8 4 2 1 | 9 | 10 | ## 11 | 12 | ## Question 2 13 | 14 | Given a positive integer N, calculate the sum of the series that consist of N numbers and goes like: N, NN, NNN... For example if N is 2, we calculate 2 + 22; if N is 5 we calculate 5 + 55 + 555 + 5555 + 55555 15 | 16 | | INPUT | OUTPUT | 17 | | ----- | ------ | 18 | | 2 | 24 | 19 | | 6 | 740736 | 20 | | 3 | 369 | 21 | 22 | ## Question 3 23 | 24 | Binary search is a searching algorithm that finds an element n in a sorted list L of size s. Firstly it compares n to L[s//2]. If n is bigger than L[s//2], it means that n is in upper half of the list. Likewise, if n is smaller than L[s//2], it means n is in lower half of the list. Then, the half of list which does not contain n is discarded. This process repeated until k th step where L[s//2**k] equals to n or list is empty. 25 | 26 | Write a function which implements binary search to find whether or nor a float exists in a list of floats. 27 | 28 | | Input | Output | 29 | | ----------------------------------------- | ------------------------- | 30 | | L = [ 1 , 3 , 4 , 5 , 6] , num = 5 | 5 exists in list | 31 | | L = [ 21 , 13 , 4.4 , 85 , 60] , num = 16 | 16 does not exist in list | 32 | 33 | ## Question 4 34 | 35 | A number is said to be "Disarium" if the sum of its digits raised to their respective positions is the number itself. Write a program that determines whether a number is a Disarium or not. 36 | 37 | 75 ➞ False 38 | 39 | *7^1 + 5^2 = 7 + 25 = 32* 40 | 41 | 135 ➞ True 42 | 43 | *1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135* 44 | 45 | Example Inputs/Outputs: 46 | 47 | 544 ➞ False 48 | 49 | 518 ➞ True 50 | 51 | 466 ➞ False 52 | 53 | 8 ➞ True 54 | 55 | 56 | 57 | 58 | 59 | ## Question 5 60 | 61 | In number theory, [Euler's Totient function](https://en.wikipedia.org/wiki/Euler's_totient_function) counts the positive integers up to a given integer *n* that are relatively prime to n. Write three functions, respectively `gcd(a, b)`, `relatively_prime(a, b)` and `euler_totient(a)`. To find `euler_totient(a)`, count the number of integers between 1 and *n* that are relatively prime with *n*. A number *a* is relatively prime with *b* iff `gcd(a, b) = 1`. To implement `gcd(a, b)`, follow the steps below. Given an integer *n*, print out the `euler_totient(n)`. To find the greates common divisor between *a* and *b*: 62 | 63 | - Repeatedly replace (*a*,*b*) with (*b*,*a %* b) until the second integer in the pair is zero. 64 | - Return the first integer in the pair as the gcd. 65 | 66 | | INPUT | OUTPUT | 67 | | ----- | ------ | 68 | | 10 | 4 | 69 | | 342 | 108 | 70 | | 76 | 36 | 71 | 72 | ## Question 6 73 | 74 | Consider that you need to fill containers to a trans-atlantic bulk carrier. You want to choose containers such that total profit of ships cargo is maximized. However, there is a mass limit the of the cargo. 75 | 76 | Write a function that inputs the ships mass capacity and 2 arrays: weight and profit. weight[i] indicates the mass of container[i] and profit[i] is the profit earned from container[i]. Note: Each container[i] indicates a unique container. 77 | 78 | | Input | Output | 79 | | --------------------------------------------------------- | --------------- | 80 | | weight = [10, 20, 30], profit = [4 , 5 , 60] , limit = 30 | Max Profit = 60 | 81 | 82 | -------------------------------------------------------------------------------- /Fall21/week06/Solution.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | ```python 4 | n = int(input()) 5 | 6 | while n != 1: 7 | print(n,end=" ") 8 | n = n*3 +1 if n %2 else n//2 9 | print(1) 10 | ``` 11 | 12 | ## Question 2 13 | 14 | ```python 15 | N = int(input()) 16 | 17 | my_sum = 0 18 | for i in range(1, N+1): 19 | my_sum *= 10 20 | for j in range(i): 21 | my_sum += N 22 | 23 | print(my_sum) 24 | ``` 25 | 26 | ## Question 3 27 | 28 | ```python 29 | def binary_find(num, L): 30 | while len(L) != 0: 31 | if num == L[len(L)//2]: 32 | return True 33 | elif num > L[len(L)//2]: 34 | L = L[len(L)//2+1:] 35 | else: 36 | L = L[:len(L)//2] 37 | return False 38 | 39 | 40 | ``` 41 | 42 | ## Question 4 43 | 44 | ```python 45 | def reverse(num): 46 | reversed_num = 0 47 | while num > 0: 48 | digit = num % 10 49 | reversed_num = reversed_num * 10 + digit 50 | num = num // 10 51 | return reversed_num 52 | n = int(input()) 53 | reversed = reverse(n) 54 | digit = 1 55 | total = 0 56 | while reversed > 0: 57 | total += (reversed % 10) ** digit 58 | digit += 1 59 | reversed = reversed // 10 60 | print(n == total) 61 | 62 | ``` 63 | 64 | ## Question 5 65 | 66 | ```python 67 | def gcd(a, b): 68 | a = abs(a) 69 | b = abs(b) 70 | 71 | while(b != 0): 72 | rem = a 73 | a = b 74 | b = rem % b 75 | return a 76 | 77 | def relatively_prime(a, b): 78 | return gcd(a, b) ==1 79 | 80 | def euler_totient(n): 81 | cnt = 0 82 | for i in range(n+1): 83 | cnt = cnt + 1 if relatively_prime(i, n) else cnt 84 | return cnt 85 | 86 | a = int(input()) 87 | print(euler_totient(a)) 88 | ``` 89 | 90 | ## Question 6 91 | 92 | ```python 93 | def max(limit, weight, profit): 94 | total_profit = 0 95 | sum = 0 96 | max_profit = -1 97 | max_index = -1 98 | while sum < limit: 99 | for i in range(len(weight)): 100 | profit_per_mass = profit[i]/weight[i] 101 | if profit_per_mass > max_profit: 102 | max_index = i 103 | max_profit = profit_per_mass 104 | if max_index == -1: 105 | break 106 | if sum + weight[max_index] <= weight[max_index]: 107 | total_profit += profit[max_index] 108 | sum += weight[max_index] 109 | profit[max_index] = 0 110 | max_index = -1 111 | max_profit = -1 112 | return total_profit 113 | 114 | weight = [10, 20, 30] 115 | profit = [4 , 5 , 60] 116 | limit = 30 117 | 118 | print(max(limit, weight, profit)) 119 | ``` 120 | 121 | -------------------------------------------------------------------------------- /Fall21/week10/Solutions.md: -------------------------------------------------------------------------------- 1 | # Sets 2 | 3 | ## Question 1 - Set Operations 4 | 5 | ```python 6 | A = {1, 2, 3, 4, 5, 6} 7 | B = {1, 1, 2, 7, 11} 8 | 9 | def set_operations(set1, set2): 10 | print("A ∪ B = {}".format(set1.union(set2))) 11 | print("A ∩ B = {}".format(set1.intersection(set2))) 12 | print("A / B = {}".format(set1.difference(set2))) 13 | print("B / A = {}".format(set2.difference(set1))) 14 | 15 | set_operations(A, B) 16 | ``` 17 | 18 | ## Question 2 - Eligible to graduate? 19 | 20 | ```python 21 | required = {"CmpE150","CmpE160","CmpE220","CmpE250","CmpE260"} 22 | def is_eligible(current): 23 | if len(required.intersection(current)) == len(required): 24 | return "Eligible" 25 | else: 26 | return "Not Eligible" 27 | print(is_eligible({"Cmpe150"})) 28 | ``` 29 | 30 | Alternative: 31 | 32 | ```python 33 | required = {"CmpE150","CmpE160","CmpE220","CmpE250","CmpE260"} 34 | def is_eligible(current): 35 | if required.intersection(current) == required: 36 | return "Eligible" 37 | else: 38 | return "Not Eligible" 39 | print(is_eligible({"Cmpe150"})) 40 | ``` 41 | 42 | ## Question 3 - How good friends can they be? 43 | 44 | ```python 45 | def overall_traits(traits1, traits2): 46 | intersection = traits1.intersection(traits2) 47 | return sum(intersections) 48 | ``` 49 | 50 | ## Question 4 - Distinct 51 | 52 | ```python 53 | def is_distinct(string): 54 | return len(set(string)) == len(string) 55 | 56 | print(is_distinct('violate')) 57 | ``` 58 | 59 | # Files 60 | 61 | ## Question 5 - Reverse Lines 62 | 63 | ```python 64 | filename = input() 65 | input_f = open(filename, 'r') 66 | output_f = open('output.txt', 'w') 67 | for line in input_f: 68 | output_f.write(line[::-1]) 69 | input_f.close() 70 | output_f.close() 71 | ``` 72 | 73 | Alternative: 74 | 75 | ```python 76 | filename = input() 77 | 78 | with open(filename, 'r') as input_f: 79 | lines = input_f.readlines() 80 | 81 | with open('output.txt', 'w') as output_f: 82 | for line in lines: 83 | line = line.strip() 84 | output_f.write(line[::-1] + "\n") 85 | ``` 86 | 87 | ## Question 6 - Pluralize 88 | 89 | ```python 90 | with open('input.txt','r') as f: 91 | words = [line.strip() for line in f.readlines()] 92 | alphas = [word for word in words if word.isalpha()] 93 | 94 | with open('output.txt','w') as f: 95 | f.write("\n".join([word +'s' if word[-1] != 'y' else word[:-1]+'ies' for word in alphas])) 96 | ``` 97 | 98 | Alternative: 99 | 100 | ```python 101 | input_filename = "q6.txt" 102 | output_filename = "pluralWords.txt" 103 | 104 | with open(input_filename, "r") as input_file: 105 | lines = input_file.readlines() 106 | words = [line.strip() for line in lines] 107 | alphas = [word for word in words if word.isalpha()] 108 | 109 | with open(output_filename, "w") as output_file: 110 | for word in alphas: 111 | if word[-1] == "y": 112 | plural_word = word[:-1] + "ies" 113 | else: 114 | plural_word = word + "s" 115 | output_file.write(plural_word + "\n") 116 | ``` 117 | 118 | ## Question 7 - Correct Grades 119 | 120 | ```python 121 | with open("grades.txt", 'r') as f: 122 | mt1 = [str(max(0, int(grade))) for grade in f.readline().split()] 123 | mt2 = [str(max(0, int(grade))) for grade in f.readline().split()] 124 | final = [str(max(0, int(grade))) for grade in f.readline().split()] 125 | 126 | with open("corrected.txt", 'w') as f: 127 | f.write(' '.join(mt1)) 128 | f.write('\n') 129 | f.write(' '.join(mt2)) 130 | f.write('\n') 131 | f.write(' '.join(final)) 132 | ``` 133 | 134 | # List Bonus Question 135 | 136 | ## Question 8 - Bubble Sort 137 | 138 | ```python 139 | def bubble_sort(arr): 140 | n = len(arr) 141 | 142 | # Traverse through all array elements 143 | for i in range(n - 1): 144 | # range(n) also work but outer loop will repeat one time more than needed. 145 | 146 | # Last i elements are already in place 147 | for j in range(0, n - i - 1): 148 | 149 | # traverse the array from 0 to n-i-1 150 | # Swap if the element found is greater 151 | # than the next element 152 | if arr[j] > arr[j + 1]: 153 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 154 | 155 | # temp = arr[j] 156 | # arr[j] = arr[j+1] 157 | # arr[j+1] = temp 158 | 159 | return arr 160 | 161 | 162 | print(bubble_sort([4, 2, 8, 6, 7, 3, 1, 5])) 163 | 164 | #print(sorted([4, 2, 8, 6, 7, 3, 1, 5])) 165 | ``` 166 | 167 | 168 | -------------------------------------------------------------------------------- /Fall24/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/.DS_Store -------------------------------------------------------------------------------- /Fall24/project2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/project2/.DS_Store -------------------------------------------------------------------------------- /Fall24/project3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/project3/.DS_Store -------------------------------------------------------------------------------- /Fall24/week01/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week01/.DS_Store -------------------------------------------------------------------------------- /Fall24/week01/Cmpe 150 Lab 1_ Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week01/Cmpe 150 Lab 1_ Introduction.pdf -------------------------------------------------------------------------------- /Fall24/week01/additional/README.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | ## Question 1: Basic Variable Operations 4 | 5 | a) Create three different integer variables, and print them. 6 | 7 | b) Take two floating-point numbers from the user, and print them. 8 | 9 | c) Take three integers from the user (x, y, z), and then print their sum, product, average, and modulus (using the modulus operator). 10 | 11 | Input: 10 5 3 12 | Output: Sum: 18, Product: 150, Average: 6.0, Modulus of x % y: 0 13 | 14 | 15 |
16 | 17 | ## Question 2: Variable Type Identification and User Input 18 | 19 | a) Create a boolean, a complex number, and a list variable. Print their types using the type() function. 20 | 21 | b) Take a boolean, a complex number, and a list from the user as input. Print the variables along with their types. 22 | 23 | Input: True, 3+4j, [1, 2, 3] 24 | Output: True , (3+4j) , [1, 2, 3] 25 | 26 | 27 |
28 | 29 | ## Question 3: Basic Mathematical Operations 30 | 31 | Write a program that takes 4 integers from the user and prints the sum, geometric mean, and product of the numbers. 32 | 33 | Input: 2 4 8 16 34 | Output: Sum: 30, Geometric Mean: 5.656, Product: 1024 35 | 36 |
37 | 38 | ## Question 4: Compound Interest Calculation 39 | 40 | Use the formula for compound interest to take the principal amount (P), annual interest rate (r) in percentage, and number of years (t) as input. Calculate and print the compound interest for monthly compounding. 41 | 42 | A = P * ( 1 + r/100 * 12)^2 * t where 43 | 44 | A = Final amount after interest 45 | 46 | P = Principal amount (initial investment) 47 | 48 | r = Annual interest rate (in percentage) 49 | 50 | t = Time duration in years 51 | 52 | 53 | Input: 1000 5 2 54 | Output: 1104.94 55 | 56 |
57 | 58 | ## Question 5: Type Conversion and Outcome Prediction 59 | 60 | Guess the outcome of each statement and check the results: 61 | 62 | ``` 63 | print(float('12.34') + 1) 64 | print(5 * 'hello') 65 | print(bool('False')) 66 | print('abc' * int(2.7)) 67 | print(int(7.8) + int('3')) 68 | print('python' + '3') 69 | print(4 ** 2 // 8) 70 | print(str(10.5) + '7') 71 | print(float(2.5 + 3.5)) 72 | print(int('50') * 0.5) 73 | ``` 74 | 75 |
76 | 77 | ## Question 6: Time Conversion 78 | 79 | Write a program that calculates the amount of seconds in a given period of weeks, days, hours, minutes, and seconds. 80 | 81 | Conversion rates: 82 | 83 | 1 week = 7 days 84 | 1 day = 24 hours 85 | 1 hour = 60 minutes 86 | 1 minute = 60 seconds 87 | 88 | 89 | Input: 1 2 3 4 5 90 | Output: Output in seconds: 788645 91 | 92 |
93 | 94 | ## Question 7: Change Calculation 95 | 96 | A vending machine dispenses items in quantities of 20-cent coins and 5-cent coins. Write a function that takes an amount in cents and prints the number of 20-cent coins and 5-cent coins needed to make that amount (use the minimum number of coins possible). 97 | 98 | Input: 145 99 | Output: 20-cent coins: 7, 5-cent coins: 1 100 | 101 |
102 | 103 | 104 | ## Question 8: Custom Power Function 105 | 106 | Write a function called exponent that takes two integer parameters: base and exp. The function should return the expth power of base. 107 | 108 | Input: 2 3 109 | Output: 8 110 | 111 | 112 |
113 | 114 | ## Question 9: Sum of Even Numbers 115 | 116 | Write a program that takes 4 integers from the user and then prints the sum of the even numbers. 117 | 118 | Input: 1 2 3 4 119 | Output: 6 120 | 121 |
122 | 123 | ## Question 10: Perfect Number Check 124 | 125 | Write a function that takes an integer and determines whether it is a perfect number or not. A perfect number is a number that is equal to the sum of its proper divisors (excluding itself). 126 | 127 | Input: 28 128 | Output: True 129 | Input: 15 130 | Output: False 131 | 132 | 133 | -------------------------------------------------------------------------------- /Fall24/week01/questions.py: -------------------------------------------------------------------------------- 1 | ## Question 1: Chatbot 2 | 3 | #Chatbot: Hello there! I’m the CS101 Study Bot. What’s your name? 4 | #User: Ayse 5 | #Chatbot: Great to meet you, Ayse! How many semesters have you been studying Computer Science? 6 | #User: 2 7 | #Chatbot: Ah, “2” semesters, nice! I’m still learning myself. What are you working on right now? 8 | #User: Learning about algorithms. 9 | #Chatbot: “Algorithms”, huh? That’s a challenging topic! I can’t say I know all the algorithms yet, but maybe we can figure it out together? Need help with something specific? 10 | #User: Can you explain sorting algorithms? 11 | #Chatbot: I wish I could, but I’m just a simple chatbot for now. Maybe check out the lecture notes or ask your instructor for more details. I’m here for small talk though! Anything else? 12 | #User: Tell me more about you. 13 | #Chatbot: Well, I was programmed by “Ayse” in a few lines of code for CS101. My job is to chat and keep you company while you study. Have fun with your course, and let’s talk again soon! 14 | 15 | 16 | 17 | 18 | 19 | ## Question 2: 20 | 21 | # You are expected to display each one of the following messages on a new line 22 | # "Cmpe150 requires regular practice" 23 | # "The more I study, the easier it will become" 24 | # 25 | # After these two messages, you should define a function calculate_f to calculate 26 | # and display the result of f = m * a for the given m and a arguments. 27 | # Then you should define getWidth function to return the width of a triangle as explained 28 | # in the question description 29 | 30 | 31 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 32 | 33 | 34 | 35 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 36 | 37 | m = int(input()) 38 | a = int(input()) 39 | calculate_f(m, a) 40 | 41 | triangle_height = int(input()) 42 | triangle_width = getWidth(triangle_height) 43 | print(triangle_width) 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Fall24/week01/solutions.py: -------------------------------------------------------------------------------- 1 | ## Q1 2 | 3 | 4 | print("Hello there! I'm the CS101 Study Bot. What's your name?") 5 | username = input() 6 | 7 | print("Great to meet you, " + username + "! How many semesters have you been studying Computer Science?") 8 | semesters = input() 9 | 10 | print('Ah, "' + semesters + '" semesters, nice! I\'m still learning myself. What are you working on right now?') 11 | current_topic = input() 12 | 13 | print('"' + current_topic + '", huh? That\'s a challenging topic! I can\'t say I know all the algorithms yet, but maybe we can figure it out together? Need help with something specific?') 14 | specific_help = input() 15 | 16 | print('I wish I could, but I\'m just a simple chatbot for now. Maybe check out the lecture notes or ask your instructor for more details. I\'m here for small talk though! Anything else?') 17 | more_info = input() 18 | 19 | print('Well, I was programmed by "' + username + '" in a few lines of code for CS101. My job is to chat and keep you company while you study. Have fun with your course, and let\'s talk again soon!') 20 | 21 | 22 | 23 | ## Q2 24 | 25 | # You are expected to display each one of the following messages on a new line 26 | # "Cmpe150 requires regular practice" 27 | # "The more I study, the easier it will become" 28 | # 29 | # After these two messages, you should define a function calculate_f to calculate 30 | # and display the result of f = m * a for the given m and a arguments. 31 | # Then you should define getWidth function to return the width of a triangle as explained 32 | # in the question description 33 | 34 | 35 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 36 | 37 | print("Cmpe150 requires regular practice.") 38 | print("The more I study, the easier it will become.") 39 | 40 | def calculate_f(m, a): 41 | print(m*a) 42 | 43 | def getWidth(height): 44 | return 2 * height - 1 45 | 46 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 47 | 48 | m = int(input()) 49 | a = int(input()) 50 | calculate_f(m, a) 51 | 52 | triangle_height = int(input()) 53 | triangle_width = getWidth(triangle_height) 54 | print(triangle_width) 55 | 56 | 57 | -------------------------------------------------------------------------------- /Fall24/week02/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week02/.DS_Store -------------------------------------------------------------------------------- /Fall24/week02/Cmpe 150 Lab 2_ Functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week02/Cmpe 150 Lab 2_ Functions.pdf -------------------------------------------------------------------------------- /Fall24/week02/functions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | Write a function that returns the square of a number. 4 | 5 | ## Question 2 6 | 7 | Create a function that checks if a number is even. 8 | 9 | ## Question 3 10 | 11 | Write a function that takes a list of numbers and returns their sum. 12 | 13 | ## Question 4 14 | 15 | Define a function that takes a string and returns it reversed. 16 | 17 | ## Question 5 18 | 19 | Create a function that takes a list and returns the largest number. 20 | 21 | ## Question 6 22 | 23 | Write a function that checks if a word is a palindrome. 24 | 25 | ## Question 7 26 | 27 | Write a function that concatenates two strings. 28 | 29 | ## Question 8 30 | 31 | Define a function that raises a number to a power. 32 | 33 | ## Question 9 34 | 35 | Create a function that returns the absolute value of a number. 36 | 37 | ## Question 10 38 | 39 | Write a function that returns the length of a string. 40 | -------------------------------------------------------------------------------- /Fall24/week02/functions_solution.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def square(number): 4 | # exponentiation operator 5 | 6 | return number ** 2 7 | 8 | 9 | # Example usage: 10 | print(square(5)) # Output: 25 11 | 12 | ''' 13 | #manually calculated using multiplication 14 | def square(number): 15 | return number * number 16 | 17 | # Example usage: 18 | print(square(5)) # Output: 25 19 | 20 | ''' 21 | 22 | ###### 23 | 24 | 25 | def is_even(number): 26 | return number % 2 == 0 27 | 28 | # Example usage: 29 | print(is_even(4)) # Output: True 30 | print(is_even(7)) # Output: False 31 | 32 | 33 | ### 34 | 35 | def sum_of_list(numbers): 36 | return sum(numbers) 37 | 38 | # Example usage: 39 | print(sum_of_list([1, 2, 3, 4])) # Output: 10 40 | 41 | ''' 42 | #iterates through the list to find the total sum 43 | def sum_of_list(numbers): 44 | total = 0 45 | for number in numbers: 46 | total += number 47 | return total 48 | 49 | # Example usage: 50 | print(sum_of_list([1, 2, 3, 4])) # Output: 10 51 | 52 | ''' 53 | ### 54 | 55 | def reverse_string(string): 56 | return string[::-1] 57 | 58 | # Example usage: 59 | print(reverse_string("hello")) # Output: "olleh" 60 | 61 | ''' 62 | #builds a new string character by character in reverse order 63 | def reverse_string(string): 64 | reversed_str = "" 65 | for char in string: 66 | reversed_str = char + reversed_str 67 | return reversed_str 68 | 69 | # Example usage: 70 | print(reverse_string("hello")) # Output: "olleh" 71 | 72 | ''' 73 | 74 | ### 75 | 76 | def find_largest(numbers): 77 | return max(numbers) 78 | 79 | # Example usage: 80 | print(find_largest([1, 3, 7, 0, 5])) # Output: 7 81 | 82 | ''' 83 | # manually checks for the largest element 84 | def find_largest(numbers): 85 | largest = numbers[0] 86 | for number in numbers[1:]: 87 | if number > largest: 88 | largest = number 89 | return largest 90 | 91 | # Example usage: 92 | print(find_largest([1, 3, 7, 0, 5])) # Output: 7 93 | 94 | ''' 95 | 96 | ### 97 | 98 | def is_palindrome(word): 99 | return word == word[::-1] 100 | 101 | # Example usage: 102 | print(is_palindrome("radar")) # Output: True 103 | print(is_palindrome("hello")) # Output: False 104 | 105 | ''' 106 | # uses a loop to compare characters from the start and end of the string 107 | def is_palindrome(word): 108 | length = len(word) 109 | for i in range(length // 2): 110 | if word[i] != word[length - i - 1]: 111 | return False 112 | return True 113 | 114 | # Example usage: 115 | print(is_palindrome("radar")) # Output: True 116 | print(is_palindrome("hello")) # Output: False 117 | 118 | ''' 119 | 120 | 121 | ### 122 | 123 | def concatenate_strings(str1, str2): 124 | return str1 + str2 125 | 126 | # Example usage: 127 | print(concatenate_strings("Hello, ", "world!")) # Output: "Hello, world!" 128 | 129 | 130 | ''' 131 | # combines strings by iterating through each character 132 | def concatenate_strings(str1, str2): 133 | concatenated = "" 134 | for char in str1: 135 | concatenated += char 136 | for char in str2: 137 | concatenated += char 138 | return concatenated 139 | 140 | # Example usage: 141 | print(concatenate_strings("Hello, ", "world!")) # Output: "Hello, world!" 142 | 143 | ''' 144 | 145 | ### 146 | def raise_to_power(base, exponent): 147 | return base ** exponent 148 | 149 | # Example usage: 150 | print(raise_to_power(2, 3)) # Output: 8 151 | 152 | ''' 153 | # uses a loop to multiply the base repeatedly 154 | def raise_to_power(base, exponent): 155 | result = 1 156 | for _ in range(exponent): 157 | result *= base 158 | return result 159 | 160 | # Example usage: 161 | print(raise_to_power(2, 3)) # Output: 8 162 | 163 | ''' 164 | ### 165 | def absolute_value(number): 166 | return abs(number) 167 | 168 | # Example usage: 169 | print(absolute_value(-10)) # Output: 10 170 | 171 | ''' 172 | # manually checks for the sign of the number 173 | def absolute_value(number): 174 | if number < 0: 175 | return -number 176 | return number 177 | 178 | # Example usage: 179 | print(absolute_value(-10)) # Output: 10 180 | print(absolute_value(5)) # Output: 5 181 | 182 | ''' 183 | ### 184 | 185 | def string_length(string): 186 | return len(string) 187 | 188 | # Example usage: 189 | print(string_length("hello")) # Output: 5 190 | 191 | ''' 192 | # uses a loop to count the number of characters 193 | def string_length(string): 194 | length = 0 195 | for char in string: 196 | length += 1 197 | return length 198 | 199 | # Example usage: 200 | print(string_length("hello")) # Output: 5 201 | 202 | ''' -------------------------------------------------------------------------------- /Fall24/week02/turtle_example.py: -------------------------------------------------------------------------------- 1 | 2 | import turtle 3 | import time 4 | 5 | clicked = False 6 | def on_click(x, y): 7 | global clicked 8 | clicked = True 9 | 10 | turtle.onscreenclick(on_click) 11 | 12 | def waitonclick(): 13 | global clicked 14 | turtle.update() 15 | clicked = False 16 | while not clicked: 17 | turtle.update() 18 | time.sleep(.1) 19 | clicked = False 20 | turtle.clear() 21 | turtle.penup() 22 | turtle.goto(0,0) 23 | turtle.setheading(0) 24 | turtle.pendown() 25 | 26 | turtle.update() 27 | turtle.speed("fastest") 28 | 29 | # Draw your star shape in the following editable code block 30 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 31 | 32 | 33 | 34 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 35 | waitonclick() 36 | 37 | # Draw your Hexagon shape in the following editable code block 38 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 39 | 40 | 41 | 42 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 43 | waitonclick() 44 | 45 | # Draw your Spiral shape in the following editable code block 46 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 47 | 48 | 49 | 50 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 51 | waitonclick() 52 | 53 | # Draw your Olimpia shape in the following editable code block 54 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 55 | 56 | 57 | 58 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 59 | waitonclick() 60 | 61 | # Draw your Chain of Rings shape in the following editable code block 62 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 63 | 64 | 65 | 66 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 67 | 68 | turtle.done() 69 | 70 | -------------------------------------------------------------------------------- /Fall24/week03/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week03/.DS_Store -------------------------------------------------------------------------------- /Fall24/week03/Cmpe 150 Lab 3_ File I_O.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week03/Cmpe 150 Lab 3_ File I_O.pdf -------------------------------------------------------------------------------- /Fall24/week03/IO.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def generate_diamond(size): 4 | result = "" 5 | 6 | for line in range(size): 7 | width = 2*line -1 8 | initial_blanks = int(((2*size-1) - (width))/2) 9 | result += " " * initial_blanks + "#" * (width) + "\n" 10 | 11 | for line in range( size): 12 | width = 2 * (size - line) - 1 13 | initial_blanks = int(((2 * size - 1) - (width)) / 2) 14 | result += " " * initial_blanks + "#" * (width) + "\n" 15 | 16 | return result 17 | 18 | answer_file_name = "" 19 | 20 | # Receive two file paths from the user, where the former is for reading data and the latter is for writing. 21 | # The output file name must be assigned to answer_file_name variable as it is used for output checking. 22 | 23 | # The input file contains an integer number 24 | # The output file must contain the shape generated by the given generate_diamond method. 25 | 26 | # DO NOT write any prompt messages inside the input functions. 27 | # Do not write any prints 28 | # Do not forget to close your file handles. 29 | #---------------------------------------------------------------- 30 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 31 | 32 | 33 | 34 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 35 | #---------------------------------------------------------------- 36 | answer = open(answer_file_name) 37 | print(answer.read()) 38 | answer.close() 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Fall24/week03/IO_solution.py: -------------------------------------------------------------------------------- 1 | 2 | def generate_diamond(size): 3 | result = "" 4 | 5 | for line in range(size): 6 | width = 2*line -1 7 | initial_blanks = int(((2*size-1) - (width))/2) 8 | result += " " * initial_blanks + "#" * (width) + "\n" 9 | 10 | for line in range( size): 11 | width = 2 * (size - line) - 1 12 | initial_blanks = int(((2 * size - 1) - (width)) / 2) 13 | result += " " * initial_blanks + "#" * (width) + "\n" 14 | 15 | return result 16 | 17 | answer_file_name = "" 18 | 19 | # Receive two file paths from the user, where the former is for reading data and the latter is for writing. 20 | # The output file name must be assigned to answer_file_name variable as it is used for output checking. 21 | 22 | # The input file contains an integer number 23 | # The output file must contain the shape generated by the given generate_diamond method. 24 | 25 | # DO NOT write any prompt messages inside the input functions. 26 | # Do not write any prints 27 | # Do not forget to close your file handles. 28 | #---------------------------------------------------------------- 29 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 30 | 31 | input_file = open() 32 | answer_file_name = input() 33 | 34 | output_file = open(answer_file_name,"w") 35 | size = int(input_file.readline()) 36 | diamond = generate_diamond(size) 37 | 38 | output_file.write(diamond) 39 | 40 | input_file.close() 41 | output_file.close() 42 | 43 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 44 | #---------------------------------------------------------------- 45 | answer = open(answer_file_name) 46 | print(answer.read()) 47 | answer.close() 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Fall24/week03/additional/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week03/additional/.DS_Store -------------------------------------------------------------------------------- /Fall24/week03/additional/drawingFlower.md: -------------------------------------------------------------------------------- 1 | # Drawing a Flower with Turtle Graphics and File I/O 2 | Create a program that uses the turtle graphics library to draw a flower with six petals. In addition to drawing, the program should demonstrate file input/output (I/O) operations by recording the coordinates of the turtle's position during the drawing process. 3 | 4 | ### Requirements: 5 | 6 | #### Turtle Graphics 7 | 8 | * Utilize the turtle module to draw a flower with six petals. 9 | 10 | * Each petal should be created using arcs, and the turtle should rotate appropriately between petals to form a complete flower shape. 11 | 12 | #### File I/O Operations 13 | 14 | * Create a new text file named flower_coordinates.txt. 15 | 16 | * Write to this file the starting and ending coordinates (x, y) of the turtle for each petal drawn. 17 | 18 | * After all petals are drawn, add a message to the file stating that the flower drawing is complete. 19 | 20 | #### Code Structure 21 | 22 | * Implement a function to draw a single petal and record its coordinates in the file. 23 | 24 | * Ensure that file handles are properly managed and closed after writing and appending data to prevent resource leaks. 25 | 26 | #### Additional Details 27 | 28 | * Use turtle.hideturtle() to hide the turtle cursor after the drawing is complete. 29 | 30 | * The program should be executed in an environment where the turtle graphics window can be displayed. 31 | 32 | ### Hints: 33 | 34 | * You can use t.circle(radius, angle) to draw arcs for the petals. 35 | 36 | * To get the current position of the turtle, use t.xcor() and t.ycor(). 37 | 38 | * Use the with open(...) statement for file handling to ensure proper closure of the file. 39 | 40 | ### Expected Output: 41 | 42 | * A window displaying a flower with six petals drawn by the turtle. 43 | 44 | * A text file (flower_coordinates.txt) containing the coordinates of the turtle's position at the start and end of each petal, as well as a completion message. 45 | -------------------------------------------------------------------------------- /Fall24/week03/additional/drawing_flower_solution.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | 3 | 4 | # Function to write the turtle's position to a file 5 | def write_position_to_file(file, message): 6 | file.write(f"{message}: ({t.xcor()}, {t.ycor()})\n") 7 | 8 | 9 | # Set up turtle 10 | t = turtle.Turtle() 11 | 12 | # Open a file to write the coordinates of the turtle's position 13 | with open("flower_coordinates.txt", "w") as f: 14 | f.write("Turtle Drawing a Flower - Petal Coordinates:\n") 15 | 16 | 17 | # Function to draw one petal and write its position 18 | def draw_petal(): 19 | write_position_to_file(f, "Start of petal") # Write starting point of each petal 20 | t.circle(100, 60) 21 | t.left(120) 22 | t.circle(100, 60) 23 | t.left(60) # Position for the next petal 24 | write_position_to_file(f, "End of petal") # Write ending point of each petal 25 | 26 | 27 | # Draw the flower (6 petals) and write the positions to the file 28 | draw_petal() # First petal 29 | draw_petal() # Second petal 30 | draw_petal() # Third petal 31 | draw_petal() # Fourth petal 32 | draw_petal() # Fifth petal 33 | draw_petal() # Sixth petal 34 | 35 | # Open the file again to append additional information 36 | with open("flower_coordinates.txt", "a") as f: 37 | f.write("\nFlower drawing complete.\n") 38 | 39 | # Hide the turtle and finish 40 | t.hideturtle() 41 | turtle.done() 42 | -------------------------------------------------------------------------------- /Fall24/week03/drawingWithInput.md: -------------------------------------------------------------------------------- 1 | 2 | Experiment with the write() method by creating a file, writing to the file, and appending to the file. 3 | 4 | Do not forget to close the file handle as soon as you are done with working on it. 5 | 6 | Try drawing concentric circles. 7 | 8 | You can use turtle.circle(200, 270) to draw an arc of 270 degrees, with radius 200. 9 | 10 | You can also draw circles clockwise using a negative radius parameter such as turtle.circle(-150, 300). 11 | 12 | If you need to draw a hexagon, you can use turtle.circle(200, 360, 6). 13 | 14 | -------------------------------------------------------------------------------- /Fall24/week03/drawing_with_input_solution.py: -------------------------------------------------------------------------------- 1 | # Step 1: Create a file, write to it, and close it 2 | file_name = "circle_log.txt" 3 | with open(file_name, 'w') as f: 4 | f.write("Starting to draw concentric circles using turtle.\n") 5 | 6 | # Step 2: Append more data to the file 7 | with open(file_name, 'a') as f: 8 | f.write("Drawing concentric circles now.\n") 9 | 10 | # Step 3: Draw concentric circles using turtle 11 | import turtle 12 | 13 | # Set up the turtle environment 14 | screen = turtle.Screen() 15 | screen.bgcolor("white") 16 | 17 | pen = turtle.Turtle() 18 | pen.speed(5) # Set the speed of the turtle 19 | 20 | # Function to draw concentric circles 21 | def draw_concentric_circles(pen, start_radius, num_circles, gap): 22 | for i in range(num_circles): 23 | pen.circle(start_radius + i * gap) # Draw a circle 24 | pen.penup() # Lift the pen 25 | pen.sety(pen.ycor() - gap) # Move the turtle down for next circle 26 | pen.pendown() # Put the pen down 27 | 28 | ''' 29 | # Alternative concentric circles 30 | def draw_concentric_circles(pen, start_radius, num_circles, gap): 31 | for i in range(num_circles): 32 | # Move to the center and draw a circle 33 | pen.penup() # Lift the pen 34 | pen.goto(0, -start_radius - i * gap) # Move to the correct position 35 | pen.pendown() # Put the pen down 36 | pen.circle(start_radius + i * gap) # Draw a circle 37 | ''' 38 | 39 | # Draw 5 concentric circles with a starting radius of 50 and a gap of 30 between them 40 | draw_concentric_circles(pen, 50, 5, 30) 41 | 42 | # Step 4: Append information about the drawing process 43 | with open(file_name, 'a') as f: 44 | f.write("Drew 5 concentric circles with a starting radius of 50 and a gap of 30 between them.\n") 45 | 46 | # Close the turtle environment on click 47 | screen.exitonclick() 48 | -------------------------------------------------------------------------------- /Fall24/week03/drawing_with_input_solution_without_for.py: -------------------------------------------------------------------------------- 1 | # Step 1: Create a file, write to it, and close it 2 | file_name = "circle_log.txt" 3 | with open(file_name, 'w') as f: 4 | f.write("Starting to draw concentric circles using turtle.\n") 5 | 6 | # Step 2: Append more data to the file 7 | with open(file_name, 'a') as f: 8 | f.write("Drawing concentric circles now.\n") 9 | 10 | # Step 3: Draw concentric circles using turtle 11 | import turtle 12 | 13 | # Set up the turtle environment 14 | screen = turtle.Screen() 15 | screen.bgcolor("white") 16 | 17 | pen = turtle.Turtle() 18 | pen.speed(5) # Set the speed of the turtle 19 | 20 | # Draw the first circle (Radius: 50) 21 | pen.circle(50) # Draw circle with the initial radius of 50 22 | pen.penup() # Lift the pen 23 | pen.sety(pen.ycor() - 30) # Move down by gap (30) 24 | pen.pendown() # Put the pen down 25 | 26 | # Draw the second circle (Radius: 80) 27 | pen.circle(80) # Draw circle with radius increased by 30 (gap) 28 | pen.penup() # Lift the pen 29 | pen.sety(pen.ycor() - 30) # Move down by gap (30) 30 | pen.pendown() # Put the pen down 31 | 32 | # Draw the third circle (Radius: 110) 33 | pen.circle(110) # Draw circle with radius increased by 30 again 34 | pen.penup() # Lift the pen 35 | pen.sety(pen.ycor() - 30) # Move down by gap (30) 36 | pen.pendown() # Put the pen down 37 | 38 | # Draw the fourth circle (Radius: 140) 39 | pen.circle(140) # Draw circle with radius increased by 30 again 40 | pen.penup() # Lift the pen 41 | pen.sety(pen.ycor() - 30) # Move down by gap (30) 42 | pen.pendown() # Put the pen down 43 | 44 | # Draw the fifth circle (Radius: 170) 45 | pen.circle(170) # Draw circle with radius increased by 30 again 46 | pen.penup() # Lift the pen 47 | pen.sety(pen.ycor() - 30) # Move down by gap (30) 48 | pen.pendown() # Put the pen down 49 | 50 | # Step 4: Append information about the drawing process 51 | with open(file_name, 'a') as f: 52 | f.write("Drew 5 concentric circles with a starting radius of 50 and a gap of 30 between them.\n") 53 | 54 | # Close the turtle environment on click 55 | screen.exitonclick() 56 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q1.py: -------------------------------------------------------------------------------- 1 | 2 | # 1. Reading and Writing Simple Text: 3 | # Write a function that receives two file paths: one for reading and another for writing. 4 | # The function should read the contents of the first file and write the exact same content into the second file. 5 | 6 | def copy_content(input_file, output_file): 7 | with open(input_file, 'r') as read_file: 8 | contents = read_file.read() 9 | with open(output_file, 'w') as write_file: 10 | write_file.write(contents) 11 | return output_file 12 | 13 | 14 | file1 = input() 15 | file2 = input() 16 | print(copy_content(file1, file2)) 17 | 18 | 19 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q2.py: -------------------------------------------------------------------------------- 1 | 2 | # 2. Appending Text to a File: 3 | # Write a function that takes two arguments: a file path and a string of text. 4 | # The function should append the provided text to the end of the file without erasing the existing content. 5 | 6 | def append_text(file_path, text): 7 | with open(file_path, 'a') as file_handle: 8 | file_handle.write(text) 9 | 10 | 11 | txt = "\n\n# 2. Appending Text to a File: Write a function that takes two arguments: a file path and a string of text. " \ 12 | "The function should append the provided text to the end of the file without erasing the existing content." 13 | 14 | 15 | inp = input() 16 | append_text(inp, txt) 17 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q3.py: -------------------------------------------------------------------------------- 1 | 2 | # 3. Counting Words in a File: Write a function that takes a file path as input. 3 | # The function should open the file, read the content, and return the number of words in the file. 4 | 5 | def count_words(file_path): 6 | with open(file_path) as file_handle: 7 | content = file_handle.read() 8 | word_count = len(content.split()) 9 | return word_count 10 | 11 | 12 | print(count_words('new_file')) 13 | 14 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q4.py: -------------------------------------------------------------------------------- 1 | 2 | # 4. Counting Occurrences of a Word in a File: 3 | # Write a function that takes a file path and a word as input. 4 | # The function should return how many times the given word appears in the file. 5 | # Write a function to save the result to an output file. 6 | 7 | def frequency_of_word(input_file, word, output_file): 8 | with open(input_file, 'r') as read_file: 9 | content = read_file.read() 10 | 11 | count = content.count(word) 12 | 13 | with open(output_file, 'w') as write_file: 14 | write_file.write(f"The word {word} appears {count} times in this file.") 15 | 16 | return count 17 | 18 | 19 | frequency_of_word('new_file', 'for', 'frequency') 20 | 21 | 22 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q5.py: -------------------------------------------------------------------------------- 1 | 2 | # 5. Reading Specific Parts of a File: 3 | # Write a function that takes a file path and an integer n as input. 4 | # The function should read the first n characters from the file and return them as a string. 5 | 6 | def read_n_chars(file_path, character_count): 7 | with open(file_path, 'r') as file_handle: 8 | text = file_handle.read(character_count) 9 | return text 10 | 11 | 12 | print(read_n_chars('new_file', 23)) 13 | print(read_n_chars('new_file', 100)) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q6.py: -------------------------------------------------------------------------------- 1 | 2 | # 6. Reversing File Content: 3 | # Write a function that takes two file paths as input. 4 | # The function should read the first line of the first file, reverse the order of all characters, 5 | # and write the reversed content into the second file. 6 | 7 | def reverse_file(file_in, file_out): 8 | with open(file_in, 'r') as file_read: 9 | line = file_read.readline() 10 | 11 | reverse_line = ''.join(reversed(line)) 12 | 13 | with open(file_out, 'w') as file_written: 14 | file_written.write(reverse_line) 15 | 16 | 17 | reverse_file('new_file', 'reversed_file') -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q7.py: -------------------------------------------------------------------------------- 1 | 2 | # 7. Reading a Specific Line from a File: 3 | # Write a function that takes a file path and an integer line_number as input. 4 | # The function should return the content of the specified line from the file. 5 | # Assume that the first line is numbered 1. 6 | 7 | def specific_line(file_path, line_number): 8 | with open(file_path, 'r') as file_handle: 9 | lines = file_handle.readlines() 10 | line = lines[line_number - 1] 11 | return line 12 | 13 | 14 | print(specific_line('new_file', 3)) 15 | -------------------------------------------------------------------------------- /Fall24/week03/onlineSession/Q8.py: -------------------------------------------------------------------------------- 1 | 2 | # 8. Modifying Content in Place: 3 | # Write a function that takes a file path, a target word, and a replacement word as input. 4 | # The function should replace all occurrences of the target word with the replacement word in the file. 5 | # Ensure that the original file is modified and saved with the new content. 6 | 7 | def replacing_word(file_path, target_word, replacement_word): 8 | with open(file_path, 'r') as file_handle: 9 | contents = file_handle.read() 10 | 11 | new_content = contents.replace(target_word, replacement_word) 12 | 13 | with open(file_path, 'w') as file_handle: 14 | file_handle.write(new_content) 15 | 16 | 17 | replacing_word('new_file', 'for', 'four') 18 | -------------------------------------------------------------------------------- /Fall24/week04/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week04/.DS_Store -------------------------------------------------------------------------------- /Fall24/week04/Cmpe 150 Lab 4_ IfElse.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week04/Cmpe 150 Lab 4_ IfElse.pdf -------------------------------------------------------------------------------- /Fall24/week04/Cmpe 150 Lab 4_ Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week04/Cmpe 150 Lab 4_ Recursion.pdf -------------------------------------------------------------------------------- /Fall24/week04/additional/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week04/additional/.DS_Store -------------------------------------------------------------------------------- /Fall24/week04/additional/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week04/additional/README.md -------------------------------------------------------------------------------- /Fall24/week04/fibonacci.md: -------------------------------------------------------------------------------- 1 | Fibonacci numbers are defined as the sum of the two previous Fibonacci numbers: 2 | 3 | f(0) = 0, f(1) = 1, f(n) = f(n-1) + f(n-2) for 𝑛 ≥ 2 4 | 5 | The first 8 Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13 6 | 7 | Write a function that calculates the nth Fibonacci number using recursion. 8 | 9 | Report the outputs with n = 11, 15, 18, 21, 30 10 | 11 | 12 | -------------------------------------------------------------------------------- /Fall24/week04/fibonacci_solution.py: -------------------------------------------------------------------------------- 1 | def fibonacci(n): 2 | # Base cases 3 | if n == 0: 4 | return 0 5 | elif n == 1: 6 | return 1 7 | # Recursive case 8 | else: 9 | return fibonacci(n - 1) + fibonacci(n - 2) 10 | 11 | def report_fibonacci(numbers, index=0): 12 | # Base case for recursion 13 | if index >= len(numbers): 14 | return 15 | # Get the Fibonacci number for the current index 16 | n = numbers[index] 17 | print(f"Fibonacci({n}) = {fibonacci(n)}") 18 | # Recursive call for the next index 19 | report_fibonacci(numbers, index + 1) 20 | 21 | # List of values of n to compute Fibonacci numbers 22 | n_values = [11, 15, 18, 21, 30] 23 | 24 | # Reporting the outputs without using a for loop 25 | report_fibonacci(n_values) 26 | 27 | ''' 28 | # Alternative 29 | 30 | def fibonacci(n): 31 | if n == 0: # Base case 1 32 | return 0 33 | elif n == 1: # Base case 2 34 | return 1 35 | else: 36 | return fibonacci(n - 1) + fibonacci(n - 2) # Recursive call 37 | 38 | print(fibonacci(3)) 39 | 40 | ''' -------------------------------------------------------------------------------- /Fall24/week04/ifelse.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | file_name = input() 4 | 5 | # Received a, b, and c as floating point numbers from the user, 6 | # DO NOT write any prompt messages inside the input functions. 7 | #---------------------------------------------------------------- 8 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 9 | 10 | 11 | 12 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 13 | #---------------------------------------------------------------- 14 | print("a: %.2f, b: %.2f, c: %.2f" % (a,b,c) ) 15 | 16 | # Define the required functions in the following section. 17 | #---------------------------------------------------------------- 18 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 19 | 20 | 21 | 22 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 23 | #---------------------------------------------------------------- 24 | print(calculate_1st_degree_root()) 25 | 26 | delta = calculate_delta() 27 | 28 | import math 29 | 30 | if delta > 0: 31 | 32 | # Calculate x1 to be -b + square root of delta / 2a 33 | # and x2 to be -b - square root of delta / 2a 34 | # print their respective values 35 | 36 | # Be careful about the indentation 37 | #---------------------------------------------------------------- 38 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 39 | 40 | 41 | 42 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 43 | #---------------------------------------------------------------- 44 | print("%.3f, %.3f" % (x1, x2)) 45 | 46 | elif delta == 0: 47 | #Calculate x as a single root. Be careful about the indentation 48 | #---------------------------------------------------------------- 49 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 50 | 51 | 52 | 53 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 54 | #---------------------------------------------------------------- 55 | print( "%.3f" % x) 56 | else: 57 | print("No real roots") 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Fall24/week04/ifelse_solution.py: -------------------------------------------------------------------------------- 1 | 2 | file_name = input() 3 | 4 | # Received a, b, and c as floating point numbers from the user file, 5 | # Assume that each value is in a single line 6 | # DO NOT write any prompt messages inside the input functions. 7 | #------------------------------------------------------------------------------------------------------------------------------- 8 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 9 | 10 | file = open(file_name) 11 | 12 | a = float(file.readline()) 13 | b = float(file.readline()) 14 | c = float(file.readline()) 15 | 16 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 17 | #------------------------------------------------------------------------------------------------------------------------------- 18 | print("a: %.2f, b: %.2f, c: %.2f" % (a,b,c) ) 19 | 20 | # Define the required functions in the following section. 21 | # HINT: There should be three functions: calculate_1st_degree_root, calculate_delta, calculate_2nd_degree_value 22 | #------------------------------------------------------------------------------------------------------------------------------- 23 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 24 | 25 | def calculate_1st_degree_root(): 26 | return -b/a 27 | 28 | def calculate_delta(): 29 | delta = b*b - 4*a*c 30 | return delta 31 | 32 | def calculate_2nd_degree_value(user_x_value): 33 | x = float(user_x_value) 34 | return a * x * x + b * x + c 35 | 36 | 37 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 38 | #------------------------------------------------------------------------------------------------------------------------------- 39 | print(calculate_1st_degree_root()) 40 | 41 | delta = calculate_delta() 42 | 43 | import math 44 | 45 | if delta > 0: 46 | 47 | # Calculate x1 to be -b + square root of delta / 2a 48 | # and x2 to be -b - square root of delta / 2a 49 | # you can use math.sqrt for square root operation 50 | # print their respective values 51 | 52 | # Be careful about the indentation 53 | #------------------------------------------------------------------------------------------------------------------------------- 54 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 55 | 56 | x1 = (-b + math.sqrt(delta)) / (2*a) 57 | x2 = (-b - math.sqrt(delta)) / (2*a) 58 | print("Delta is greater than 0 ") 59 | print(calculate_2nd_degree_value(x1)) 60 | print(calculate_2nd_degree_value(x2)) 61 | 62 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 63 | #------------------------------------------------------------------------------------------------------------------------------- 64 | print("%.3f, %.3f" % (x1, x2)) 65 | 66 | elif delta == 0: 67 | #Calculate x as a single root. Be careful about the indentation 68 | #------------------------------------------------------------------------------------------------------------------------------- 69 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 70 | x = -1*b / (2*a) 71 | print("Delta is 0 ") 72 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 73 | #------------------------------------------------------------------------------------------------------------------------------- 74 | print( "%.3f" % x) 75 | else: 76 | print("No real roots") 77 | 78 | 79 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q1.py: -------------------------------------------------------------------------------- 1 | 2 | # 1. Write a Python function that checks if a number is positive. 3 | # If the number is positive, return "Positive", otherwise return "Not Positive". 4 | 5 | def check_positive(num): 6 | if num > 0: 7 | return "Positive" 8 | else: 9 | return "Not Positive" 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q2.py: -------------------------------------------------------------------------------- 1 | 2 | # 2. Write a Python function that takes an integer and checks if it is positive, negative, or zero. 3 | # Return "Positive", "Negative", or "Zero" based on the input. 4 | 5 | def check_sign_alt(num): 6 | if num > 0: 7 | return "Positive" 8 | else: 9 | if num < 0: 10 | return "Negative" 11 | else: 12 | return "Zero" 13 | 14 | 15 | def check_sign(num): 16 | if num > 0: 17 | return "Positive" 18 | elif num < 0: 19 | return "Negative" 20 | else: 21 | return "Zero" 22 | 23 | 24 | print(check_sign_alt(0)) 25 | print(check_sign_alt(-1)) 26 | print(check_sign_alt(1)) 27 | 28 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q3.py: -------------------------------------------------------------------------------- 1 | 2 | # Write a Python function that takes two numbers as input. 3 | # If both numbers are greater than zero, return "Both Positive". 4 | # If only one number is greater than zero, return "One Positive". 5 | # If neither number is greater than zero, return "None Positive". 6 | 7 | def check_both_positive(num1, num2): 8 | if num1 > 0 and num2 > 0: # if num1 and num2 > 0 doesn't work 9 | return "Both Positive" 10 | elif num1 > 0 or num2 > 0: 11 | return "One Positive" 12 | else: 13 | return "None Positive" 14 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q4.py: -------------------------------------------------------------------------------- 1 | 2 | # Write a Python function that checks if a number is divisible by both 3 and 5. 3 | # If it is, return "Divisible by both". If it is only divisible by 3, return "Divisible by 3". 4 | # If it is only divisible by 5, return "Divisible by 5". 5 | # If it is divisible by neither, return "Not Divisible by 3 or 5". 6 | 7 | def check_divisibility(num): 8 | if num % 3 == 0 and num % 5 == 0: # this has to come first, else execution will enter 3 or 5 first and terminate 9 | return "Divisible by both" 10 | elif num % 3 == 0: 11 | return "Divisible by 3" 12 | elif num % 5 == 0: 13 | return "Divisible by 5" 14 | else: 15 | return "Not Divisible by 3 or 5" 16 | 17 | 18 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q5.py: -------------------------------------------------------------------------------- 1 | 2 | # Write a Python function that takes three integers as input and determines if they can form a valid triangle. 3 | # A triangle is valid if the sum of any two sides is greater than the third side. 4 | # If the sides form a valid triangle, return the type of triangle based on its sides: 5 | # "Equilateral" if all three sides are equal. 6 | # "Isosceles" if exactly two sides are equal. 7 | # "Scalene" if all sides are different. 8 | # If the sides do not form a valid triangle, return "Not a valid triangle". 9 | 10 | def triangle_type(a, b, c): 11 | # Check if the sides form a valid triangle 12 | if a + b > c and a + c > b and b + c > a: 13 | # Check for the type of triangle 14 | if a == b == c: 15 | return "Equilateral" 16 | elif a == b or b == c or a == c: 17 | return "Isosceles" 18 | else: 19 | return "Scalene" 20 | else: 21 | return "Not a valid triangle" 22 | 23 | 24 | print(triangle_type(3, 4, 5)) 25 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q6.py: -------------------------------------------------------------------------------- 1 | 2 | # Factorial Calculation: Write a recursive function that takes an integer n 3 | # and returns the factorial of n (i.e., n! = n * (n-1) * ... * 1). 4 | 5 | def factorial(n): 6 | if n == 0 or n == 1: # Base case 7 | return 1 8 | else: 9 | return n * factorial(n - 1) # Recursive call 10 | 11 | 12 | print(factorial(5)) 13 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q7.py: -------------------------------------------------------------------------------- 1 | 2 | # Fibonacci Sequence: Write a recursive function that takes an integer n and returns the n-th Fibonacci number. 3 | # The Fibonacci sequence is defined as F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1. 4 | 5 | # f(2) = 1, f(3) = 2, f(4) = 3, f(5) = 5, f(6) = 8 ... 6 | 7 | def fibonacci(n): 8 | if n == 0: # Base case 1 9 | return 0 10 | elif n == 1: # Base case 2 11 | return 1 12 | else: 13 | return fibonacci(n - 1) + fibonacci(n - 2) # Recursive call 14 | 15 | 16 | print(fibonacci(16)) 17 | -------------------------------------------------------------------------------- /Fall24/week04/onlineSession/Q8.py: -------------------------------------------------------------------------------- 1 | 2 | # Sum of Digits: Write a recursive function that takes a positive integer n 3 | # and returns the sum of its digits. 4 | # For example, if the input is 123, the output should be 1 + 2 + 3 = 6 5 | 6 | def sum_of_digits(n): 7 | if n == 0: # Base case 8 | return 0 9 | else: 10 | return n % 10 + sum_of_digits(n // 10) # Recursive call 11 | 12 | 13 | print(1357/10) 14 | print(1357//10) 15 | print(1357 % 10) 16 | 17 | print(sum_of_digits(1357)) 18 | -------------------------------------------------------------------------------- /Fall24/week05/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week05/.DS_Store -------------------------------------------------------------------------------- /Fall24/week05/Cmpe 150 Lab 5_ For Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week05/Cmpe 150 Lab 5_ For Loops.pdf -------------------------------------------------------------------------------- /Fall24/week05/ForLoopQuestions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | 3 | Write a function that takes a list of numbers and returns their sum. 4 | 5 |
6 | 7 | ## Question 2 8 | 9 | Write a function that takes a string and returns it reversed. 10 | 11 |
12 | 13 | ## Question 3 14 | 15 | Write a function that takes a list and returns the largest number. 16 | 17 |
18 | 19 | ## Question 4 20 | 21 | Write a function that concatenates two strings. 22 | 23 |
24 | 25 | ## Question 5 26 | 27 | Write a function that takes a list of numbers and returns two new lists: one containing only the even numbers and the other containing only the odd numbers. 28 | 29 |
30 | 31 | ## Question 6 32 | 33 | Define a function cumulative_sum that takes a list of numbers and returns a list where each element is the cumulative sum up to that index. 34 | 35 | Example: cumulative_sum([1, 2, 3, 4]) should return [1, 3, 6, 10]. 36 | 37 |
38 | 39 | ## Question 7 40 | 41 | Write a function print_number_pattern that takes an integer n and prints a number pattern where each row i contains numbers from 1 to i. For example, if n is 5, the pattern should look like this: 42 | 43 | 1 44 | 45 | 1 2 46 | 47 | 1 2 3 48 | 49 | 1 2 3 4 50 | 51 | 1 2 3 4 5 52 | 53 |
54 | 55 | ## Question 8: Digital Clock Simulation 56 | 57 | Write a program that simulates a digital clock counting seconds, starting from 00:00:00 (HH: MM) up to a user-defined time limit in seconds. Use nested for loops for hours, minutes, and seconds up to the specified limit. 58 | 59 | Input: 60 | An integer seconds_limit representing how long the clock should run. 61 | 62 | Output: 63 | Print each second in HH:MM format, simulating the passage of time. 64 | 65 | For seconds_limit = 5, the output should be: 66 | 67 | 00:00:00 68 | 69 | 00:00:01 70 | 71 | 00:00:02 72 | 73 | 00:00:03 74 | 75 | 00:00:04 76 | 77 | 00:00:05 78 | 79 |
80 | 81 | ## Question 9: Pascal's Triangle 82 | 83 | Write a program that prints Pascal's Triangle up to a given number of rows, n. Pascal's Triangle is a triangle of numbers where each row represents the coefficients of the binomial expansion. 84 | 85 | Each number in a row is the sum of the two numbers directly above it. Use nested for loops to generate each row based on the previous row. 86 | 87 | For n = 4: 88 | 89 | 1 90 | 91 | 1 1 92 | 93 | 1 2 1 94 | 95 | 1 3 3 1 96 | 97 |
98 | 99 | ## Question 10: Checkerboard Pattern 100 | 101 | Write a program that prints an n x n checkerboard pattern with alternating X and O characters. Use nested for loops and conditionals to alternate between X and O based on the row and column indices. 102 | 103 | Input: 104 | An integer n (size of the board). 105 | 106 | Output: 107 | A checkerboard pattern of size n, alternating between X and O in a grid. 108 | 109 | For n = 5, the output should be: 110 | 111 | X O X O X 112 | 113 | O X O X O 114 | 115 | X O X O X 116 | 117 | O X O X O 118 | 119 | X O X O X 120 | 121 | 122 | -------------------------------------------------------------------------------- /Fall24/week05/additional/ForLoopAdditionalQuestions.md: -------------------------------------------------------------------------------- 1 | ## Question 1: Number Spiral Matrix 2 | 3 | Write a program that generates a square matrix of numbers in a spiral pattern. The matrix should be filled with consecutive integers starting from 1, spiraling inwards in a clockwise direction from the top-left corner. 4 | 5 | For n = 4: 6 | 7 | 1 2 3 4 8 | 9 | 12 13 14 5 10 | 11 | 11 16 15 6 12 | 13 | 10 9 8 7 14 | 15 | Hints: 16 | 17 | Use a 2D list to keep track of the grid. 18 | Use four directions (right, down, left, up) in a repeating sequence, changing direction when you hit the edge of the grid or an already-filled cell. 19 | Update the current position based on the direction. 20 | 21 |
22 | 23 | ## Question 2: Conway's Game of Life 24 | 25 | Simulate the next generation of Conway's Game of Life, a cellular automaton with the following rules: 26 | 27 | Any live cell with 2 or 3 live neighbors survives. 28 | Any dead cell with exactly 3 live neighbors becomes a live cell. 29 | All other cells die or remain dead. 30 | 31 | Write a program to print the board state after one generation. Use nested for loops to iterate over the grid and calculate the number of neighbors for each cell. 32 | 33 | Input: 34 | An integer n (size of the grid). 35 | A n x n grid of 0s and 1s, where 1 represents a live cell and 0 a dead cell. 36 | 37 | Output: 38 | Print the grid state after applying the rules of the game for one generation. 39 | 40 | For n = 4 and initial grid: 41 | 42 | 0 1 0 0 43 | 44 | 0 0 1 0 45 | 46 | 1 1 1 0 47 | 48 | 0 0 0 0 49 | 50 | The output after one generation should be: 51 | 52 | 0 0 0 0 53 | 54 | 1 0 1 0 55 | 56 | 0 1 1 0 57 | 58 | 0 1 0 0 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Fall24/week05/additional/additional_solutions.py: -------------------------------------------------------------------------------- 1 | # Number Spiral Matrix 2 | def generate_spiral_matrix(n): 3 | # Create an n x n matrix initialized with zeros 4 | matrix = [[0] * n for _ in range(n)] 5 | 6 | # Directions: right, down, left, up 7 | directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] 8 | direction_index = 0 # Start by moving right 9 | x, y = 0, 0 # Starting position 10 | 11 | for num in range(1, n * n + 1): 12 | matrix[x][y] = num 13 | # Calculate the next position 14 | next_x = x + directions[direction_index][0] 15 | next_y = y + directions[direction_index][1] 16 | 17 | # Check if the next position is out of bounds or already filled 18 | if (0 <= next_x < n and 0 <= next_y < n and matrix[next_x][next_y] == 0): 19 | x, y = next_x, next_y 20 | else: 21 | # Change direction 22 | direction_index = (direction_index + 1) % 4 23 | x += directions[direction_index][0] 24 | y += directions[direction_index][1] 25 | 26 | # Print the matrix in the specified format 27 | for row in matrix: 28 | print(' '.join(str(num) for num in row)) 29 | 30 | # Example 31 | generate_spiral_matrix(4) 32 | 33 | 34 | 35 | # Conway's Game of Life 36 | def next_generation(grid): 37 | n = len(grid) 38 | new_grid = [[0] * n for _ in range(n)] 39 | 40 | for i in range(n): 41 | for j in range(n): 42 | # Count live neighbors 43 | live_neighbors = 0 44 | for x in range(max(0, i - 1), min(n, i + 2)): 45 | for y in range(max(0, j - 1), min(n, j + 2)): 46 | if (x, y) != (i, j): 47 | live_neighbors += grid[x][y] 48 | 49 | # Apply the rules of the Game of Life 50 | if grid[i][j] == 1: 51 | new_grid[i][j] = 1 if live_neighbors in (2, 3) else 0 52 | else: 53 | new_grid[i][j] = 1 if live_neighbors == 3 else 0 54 | 55 | return new_grid 56 | 57 | 58 | def print_grid(grid): 59 | for row in grid: 60 | print(' '.join(map(str, row))) 61 | 62 | # Example 63 | n = 4 64 | initial_grid = [ 65 | [0, 1, 0, 0], 66 | [0, 0, 1, 0], 67 | [1, 1, 1, 0], 68 | [0, 0, 0, 0] 69 | ] 70 | 71 | print("Initial Grid:") 72 | print_grid(initial_grid) 73 | new_grid = next_generation(initial_grid) 74 | print("Next Generation:") 75 | print_grid(new_grid) 76 | -------------------------------------------------------------------------------- /Fall24/week05/for_loop_solutions.py: -------------------------------------------------------------------------------- 1 | # Question 1 2 | def sum_of_list(numbers): 3 | total = 0 4 | for i in range(len(numbers)): 5 | total += numbers[i] 6 | return total 7 | 8 | print(sum_of_list([1,2,3,4])) 9 | 10 | #Question 2 11 | def reverse_str(str): 12 | reversed = "" 13 | 14 | for i in str: 15 | reversed = i + reversed 16 | return reversed 17 | 18 | print(reverse_str("hello")) 19 | 20 | # Question 3 21 | def max_in_list(numbers): 22 | largest = numbers[0] 23 | for i in numbers: 24 | if i > largest: 25 | largest = i 26 | return largest 27 | 28 | 29 | print(max_in_list([1,2,3,4,5])) 30 | 31 | # Question 4 32 | def string_concat(str1, str2): 33 | result = "" 34 | 35 | for char in str1: 36 | result += char 37 | 38 | for char2 in str2: 39 | result += char2 40 | 41 | return result 42 | 43 | print(string_concat("Cmpe ", "150")) 44 | 45 | # Question 5 46 | def split_even_odd(numbers): 47 | even = [] 48 | odd = [] 49 | for num in numbers: 50 | if num % 2 == 0: 51 | even.append(num) 52 | else: 53 | odd.append(num) 54 | return even, odd 55 | 56 | print(split_even_odd([1,2,3,4,5])) 57 | 58 | # Question 6 59 | def cumulative_sum(numbers): 60 | cum_sum = [] 61 | total = 0 62 | for num in numbers: 63 | total += num 64 | cum_sum.append(total) 65 | return cum_sum 66 | 67 | print(cumulative_sum([1,2,3,4])) 68 | 69 | # Question 7 70 | def print_number_pattern(n): 71 | for i in range(1, n+1): 72 | for j in range(1, i+1): 73 | print(j, end= " ") 74 | print() 75 | 76 | print_number_pattern(5) 77 | 78 | # Question 8 79 | def digital_clock(second_limit): 80 | for hour in range(60): 81 | for min in range(60): 82 | for sec in range(60): 83 | current_seconds = hour*3600 + min*60 + sec 84 | if current_seconds > second_limit: 85 | return 86 | print(f"{hour:02} hello :{min:02}:{sec:02}") 87 | 88 | digital_clock(45) 89 | 90 | # Question 9 91 | def print_pascals_triangle(n): 92 | triangle = [] 93 | 94 | for i in range(n): 95 | # The first and last elements of each row in Pascal's Triangle are always 1. 96 | row = [1] * (i + 1) # Create a row with i + 1 elements, all initialized to 1. 97 | if i > 1: 98 | for j in range(1, i): 99 | # Each number is the sum of the two above it 100 | # triangle[i - 1][j - 1]: This is the element just to the left above. 101 | # triangle[i - 1][j]: This is the element directly above. 102 | row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j] 103 | triangle.append(row) 104 | return triangle 105 | 106 | tri = print_pascals_triangle(6) 107 | n = len(print_pascals_triangle(6)) 108 | for i in range(n): 109 | print(" "* (n-i), end= " ", sep = " ") 110 | for j in range(0, i+1): 111 | print(tri[i][j], end= " ", sep = " ") 112 | print("") 113 | 114 | # Question 10 115 | def checkerboard(n): 116 | for i in range(n): #rows 117 | for j in range(n): #columns 118 | if (i+j) % 2 == 0: 119 | print("X", end= " ") 120 | else: 121 | print("O", end= " ") 122 | 123 | print() 124 | 125 | checkerboard(5) 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Fall24/week05/house.py: -------------------------------------------------------------------------------- 1 | # Complete the roof code here so it prints a triangular roof based on the given height. 2 | # For instance, if `wall_height = 3` and `roof_height = 3`, the output should look like: 3 | # 4 | 5 | # __________ 6 | # / /\ \ 7 | # / / \ \ 8 | #TTTTTTTTTTTTTTTT 9 | # | | 10 | # | | 11 | # ######### 12 | 13 | 14 | 15 | def print_roof(height): 16 | 17 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 18 | 19 | 20 | 21 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 22 | 23 | 24 | # Complete the print_house code so it prints walls under the roof. 25 | # Use `roof_height` to align the walls, and ensure the last row of walls 26 | # uses "#" symbols to create a base for the house. 27 | 28 | def print_house(wall_height, roof_height): 29 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 30 | 31 | 32 | 33 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 34 | #---------------------------------------------------------------- 35 | wall_height = int(input()) 36 | roof_height = int(input()) 37 | print_house(wall_height, roof_height) 38 | 39 | -------------------------------------------------------------------------------- /Fall24/week05/house_solution.py: -------------------------------------------------------------------------------- 1 | 2 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 3 | def print_roof(height): 4 | print(" " * int(height) + "_" * (4 * height - 2)) # Roof top line 5 | for _ in range(1, int(height)): 6 | # Adjust spaces for each row of the roof 7 | print(" " * (int(height) - _) + "/" + " " * int(2 * height - 2) + "/" + " " * (2 * (_ - 1)) + "\\" + " " * int(2 * height - 2) + "\\") 8 | print("T" * (3 * 2 * height - 2)) # Roof base line 9 | 10 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 11 | 12 | def print_house(wall_height, roof_height): 13 | # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE 14 | print_roof(roof_height) # Print the roof 15 | 16 | offset = int((3 * 2 * roof_height - 3 * wall_height) / 2 - 1) 17 | for _ in range(wall_height - 1): 18 | # Print each row of the walls, adjusted for offset 19 | print(" " * offset + "|" + " " * (3 * wall_height - 2) + "|") 20 | 21 | # Print the base row for the walls 22 | print(" " * offset + "#" * (3 * wall_height)) 23 | 24 | # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE 25 | #---------------------------------------------------------------- 26 | wall_height = int(input("Enter wall height: ")) 27 | roof_height = int(input("Enter roof height: ")) 28 | print_house(wall_height, roof_height) -------------------------------------------------------------------------------- /Fall24/week06/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week06/.DS_Store -------------------------------------------------------------------------------- /Fall24/week06/Cmpe 150 Lab 6_ Lists and Tuples.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week06/Cmpe 150 Lab 6_ Lists and Tuples.pdf -------------------------------------------------------------------------------- /Fall24/week06/lists_tuples_solutions.py: -------------------------------------------------------------------------------- 1 | # Question 1 2 | N = int(input("give me the length of the list: ")) 3 | my_list = [] 4 | for i in range(N): 5 | m = int(input("give me the element: ")) 6 | my_list.append(m) 7 | 8 | avg = sum(my_list)/N 9 | print(avg, end= " ") 10 | for element in my_list: 11 | if element > avg: 12 | print(element, end= " ") 13 | 14 | #Question 2 15 | 16 | def find_freq(list): 17 | freq_list = [0] * 101 # 0 and 100 (inclusive) 18 | for i in range(len(list)): 19 | freq_list[list[i]] += 1 20 | for i in range(len(freq_list)): 21 | if freq_list[i] != 0: 22 | print(i, ' --> ', freq_list[i], end="\n") 23 | 24 | 25 | find_freq([1,4,5,67,87,1,1]) 26 | 27 | 28 | 29 | # Question 3 30 | list = [] 31 | 32 | for _ in range(5): 33 | num = int(input("give me the element: ")) 34 | list.append(num) 35 | 36 | transformed_list = [x ** 5 for x in list] 37 | print(transformed_list) 38 | 39 | # Question 4 40 | def shift_k_number(list, k): 41 | shift_amount = k % len(list) # check whether the given number is out of list length 42 | return list[k:] + list[:k] 43 | 44 | print(shift_k_number([1,2,3,4,5], 1)) 45 | 46 | # Question 5 47 | def reverse(list): 48 | reversed_list = [] 49 | for el in reversed(list): 50 | print(el, end= ' ') 51 | reversed_list.append(el) 52 | 53 | return reversed_list 54 | 55 | print(reverse([1,3,-4,5, 2])) 56 | 57 | # Question 6 58 | def remove_x(list, x): 59 | list_without_x = [] 60 | for i in range(len(list)): 61 | if list[i] != x: 62 | list_without_x.append(list[i]) 63 | 64 | return list_without_x 65 | 66 | print(remove_x([1,1,1,5,6,6,7,8], 1)) 67 | print(remove_x([45] * 10, 45)) 68 | 69 | # Question 7 70 | def remove_dup(list): 71 | seen_numbers = [] 72 | for i in range(len(list)): 73 | if not list[i] in seen_numbers: 74 | seen_numbers.append(list[i]) 75 | 76 | return seen_numbers 77 | 78 | print(remove_dup([1,1,1,2,3,5,5,5])) 79 | 80 | # Question 8 81 | def odd_occurrence(list): 82 | odd_element = [] 83 | for i in range(len(list)): 84 | if list[i] in odd_element: 85 | odd_element.remove(list[i]) 86 | else: 87 | odd_element.append(list[i]) 88 | 89 | return odd_element 90 | 91 | print(odd_occurrence([1,1,3,4,2, 'apple', 'apple', 'banana'])) 92 | 93 | 94 | # Question 9 95 | def fraction(frac1, frac2): 96 | return (((frac1[0] * frac2[1]) + (frac1[1] * frac2[0])), (frac1[1] * frac2[1])) 97 | 98 | print(fraction((1,3), (4,5))) 99 | 100 | # Question 10a 101 | def dist(p1, p2): 102 | distance_in_x_axis = p1[0]-p2[0] 103 | distance_in_x_axis_squared = distance_in_x_axis ** 2 104 | 105 | distance_in_y_axis = p1[1] - p2[1] 106 | distance_in_y_axis_squared = distance_in_y_axis ** 2 107 | 108 | squared_distance = distance_in_x_axis_squared + distance_in_y_axis_squared 109 | distance = squared_distance ** 0.5 110 | return distance 111 | 112 | # An alternative way to do the same thing 113 | # return (((p1[0]-p2[0])**2) + ((p1[1]-p2[1])**2))**0.5 114 | 115 | print(dist((3, 0), (0, 4))) 116 | print(dist((5, 8), (10, 20))) 117 | print(dist((3, 6), (3, 6))) 118 | 119 | # Question 10b 120 | def closest(p1, p2): 121 | dist1 = dist(p1, (0, 0)) 122 | dist2 = dist(p2, (0, 0)) 123 | if dist1 < dist2: 124 | return p1 125 | else: 126 | return p2 127 | 128 | print(closest((3, 0), (0, 4))) 129 | print(closest((11, 7), (6, 8))) 130 | 131 | # Question 10c 132 | N = int(input()) 133 | points = [] 134 | farthest_index1, farthest_index2, max_dist = -1, -2, -6 135 | for i in range(N): 136 | line = input() 137 | elements = line.split() 138 | point = (int(elements[0]), int(elements[1])) 139 | points.append(point) 140 | for i in range(len(points)): 141 | for j in range(i+1, len(points)): 142 | distance = dist(points[i], points[j]) 143 | if distance > max_dist: 144 | max_dist = distance 145 | farthest_index1 = i 146 | farthest_index2 = j 147 | 148 | print('Distance:', max_dist) 149 | print('Point 1:', points[farthest_index1]) 150 | print('Point 2:', points[farthest_index2]) 151 | 152 | # Question 11 153 | def bubble_sort(list): 154 | for i in range(len(list)-1): 155 | for j in range(len(list)-1-i): 156 | if list[j] > list[j+1]: 157 | list[j], list[j+1] = list[j+1], list[j] 158 | return list 159 | 160 | print(bubble_sort([4, 2, 8, 6, 7, 3, 1, 5])) 161 | #print(sorted([4, 2, 8, 6, 7, 3, 1, 5])) 162 | 163 | print(bubble_sort([4, -2, 4, 6, -7, 3, 1, 5])) 164 | #print(sorted([4, -2, 4, 6, -7, 3, 1, 5])) 165 | 166 | 167 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week06/onlineSession/.DS_Store -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/forLoops/Q1.py: -------------------------------------------------------------------------------- 1 | 2 | # 1. Basic Counting with a For Loop 3 | # Write a function that takes two numbers, start and end, as inputs. 4 | # Use a for loop to print all numbers on a new line from start to end, inclusive. 5 | # For example, if you input 1 and 10, the function should print the numbers 1 to 10. 6 | 7 | def print_numbers(start, end): 8 | for i in range(start, end + 1): 9 | print(i) 10 | 11 | 12 | print_numbers(1, 10) 13 | 14 | 15 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/forLoops/Q2.py: -------------------------------------------------------------------------------- 1 | 2 | # 2. Summing Numbers in a Range 3 | # Write a function that takes two numbers, start and end, as inputs. 4 | # The function should use a for loop to calculate the sum of all numbers from start to end and then return this total. 5 | # For example, if you input 1 and 10, the function should return the sum of numbers from 1 to 10. 6 | 7 | def sum_numbers(start, end): 8 | total = 0 9 | for i in range(start, end + 1): 10 | total += i 11 | return total 12 | 13 | 14 | print(sum_numbers(1, 10)) 15 | 16 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/forLoops/Q3.py: -------------------------------------------------------------------------------- 1 | 2 | # 3. Counting Even Numbers in a Range 3 | # Write a function that takes two numbers, start and end, as inputs. 4 | # The function should use a for loop to find all even numbers between start and end (inclusive) 5 | # and print each even number. At the end, the function should return the total count of even numbers. 6 | # For example, if you input 1 and 20, it should print each even number from 1 to 20 7 | # and return the total number of even numbers in that range. 8 | 9 | 10 | def count_even_numbers(start, end): 11 | count = 0 12 | for i in range(start, end + 1): 13 | if i % 2 == 0: 14 | print(i) 15 | count += 1 16 | return count 17 | 18 | 19 | print("Amount of even numbers:", count_even_numbers(1, 20)) 20 | 21 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/listsTuples/Q1.py: -------------------------------------------------------------------------------- 1 | 2 | # 1. Counting Even Numbers in a Range 3 | # Write a function that takes two numbers, start and end, as inputs. 4 | # The function should use a for loop to find all even numbers between start and end (inclusive) 5 | # and store each even number in a list. 6 | # After the loop finishes, the function should return this list of even numbers 7 | # and the total count of even numbers in the range. 8 | # For example, if you input 1 and 20, the function should return a list of all even numbers from 1 to 20 9 | # and the count of those numbers. 10 | 11 | def count_even_numbers(start, end): 12 | evens = [] 13 | for i in range(start, end + 1): 14 | if i % 2 == 0: 15 | evens.append(i) 16 | return evens, len(evens) 17 | 18 | # def count_evens(start, end): 19 | # evens = [] 20 | # even_count = 0 21 | # for number in range(start, end + 1): 22 | # if number % 2 == 0: 23 | # evens.append(number) 24 | # even_count += 1 25 | # return evens, even_count 26 | 27 | 28 | evens_list, count_evens = count_even_numbers(1, 20) 29 | print("Even numbers:", evens_list) 30 | print("Total even numbers:", count_evens) 31 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/listsTuples/Q2.py: -------------------------------------------------------------------------------- 1 | 2 | # 2. Extracting and Reversing Part of a List 3 | # Write a function that takes a list of numbers and two integers, start and end, as inputs. 4 | # Use slicing to produce a sublist from the original list that starts at start index and ends at end index (inclusive). 5 | # Then, use a for loop to reverse the sublist. Finally, return the reversed sublist. 6 | # For example, if the input list is [2, 4, 6, 8, 10, 12, 14], with start as 2 and end as 5, 7 | # the function should first create the sublist [6, 8, 10, 12] 8 | # and then return the reversed version of this sublist, which is [12, 10, 8, 6]. 9 | 10 | def extract_and_reverse_sublist(input_list, start, end): 11 | # Extract the sublist using slicing 12 | sublist = input_list[start:end + 1] 13 | 14 | # Reverse the sublist using a for loop 15 | reversed_sublist = sublist[::-1] 16 | # for item in sublist: 17 | # reversed_sublist.insert(0, item) 18 | 19 | return reversed_sublist 20 | 21 | 22 | result = extract_and_reverse_sublist([2, 4, 6, 8, 10, 12, 14], 2, 5) 23 | print(result) # Output: [12, 10, 8, 6] 24 | -------------------------------------------------------------------------------- /Fall24/week06/onlineSession/listsTuples/Q3.py: -------------------------------------------------------------------------------- 1 | 2 | # 3. Sort a List in Ascending Order 3 | # Write a function that takes a list of numbers as input and returns a new list with the numbers arranged 4 | # from smallest to largest. Do not use any built-in sorting functions (such as sort() or sorted()). 5 | # Hint: Use two for loops: one to keep iterating over the list and another to compare each pair of adjacent elements. 6 | # If two adjacent elements are in the wrong order, swap them. Repeat this until all elements are in the correct order. 7 | # For example, if the input list is [5, 2, 9, 1, 5, 6], the function should return [1, 2, 5, 5, 6, 9]. 8 | 9 | def sort_list_ascending(input_list): 10 | # Create a copy of the input list to avoid modifying the original list 11 | sorted_list = input_list[:] 12 | 13 | # Outer loop to keep passing through the list 14 | for i in range(len(sorted_list)): 15 | # Inner loop to compare each pair of adjacent elements 16 | for j in range(len(sorted_list) - 1): 17 | # Swap if the elements are in the wrong order 18 | # if sorted_list[j] > sorted_list[j + 1]: 19 | # temp = sorted_list[j] # Store the value of sorted_list[j] in a temporary variable 20 | # sorted_list[j] = sorted_list[j + 1] # Move the value of sorted_list[j + 1] to sorted_list[j] 21 | # sorted_list[j + 1] = temp # Assign the value from the temporary variable to sorted_list[j + 1] 22 | 23 | if sorted_list[j] > sorted_list[j + 1]: 24 | # Swap if the elements are in the wrong order 25 | sorted_list[j], sorted_list[j + 1] = sorted_list[j + 1], sorted_list[j] 26 | 27 | return sorted_list 28 | 29 | 30 | # Example usage 31 | result = sort_list_ascending([5, 2, 9, 1, 5, 6]) 32 | print(result) # Output: [1, 2, 5, 5, 6, 9] 33 | -------------------------------------------------------------------------------- /Fall24/week07/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week07/.DS_Store -------------------------------------------------------------------------------- /Fall24/week07/Cmpe 150 Lab 7_ Dictionaries.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week07/Cmpe 150 Lab 7_ Dictionaries.pdf -------------------------------------------------------------------------------- /Fall24/week07/Dictionaries.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Word Count 2 | Write a function that takes a string as input and returns a dictionary with each unique word as a key and its frequency as the value. 3 | 4 | INPUT OUTPUT 5 | 6 | "hello world hello" --> {"hello": 2, "world": 1} 7 | 8 | "apple orange banana apple apple" --> {"apple": 3, "orange": 1, "banana": 1} 9 | 10 |
11 | 12 | ## Question 2 - Grade Book 13 | Write a function that takes a dictionary where keys are student names and values are lists of scores. The function should return a dictionary with student names as keys and their average score as the value. 14 | 15 | INPUT OUTPUT 16 | 17 | {"Alice": [85, 90, 88], "Bob": [78, 82, 80], "Eve": [95, 90, 92]} --> {"Alice": 87.67, "Bob": 80.0, "Eve": 92.33} 18 | 19 |
20 | 21 | ## Question 3 - Value Inverter 22 | Write a function that takes a dictionary and returns a new dictionary with keys and values swapped. 23 | 24 | INPUT OUTPUT 25 | 26 | {"a": 1, "b": 2, "c": 3} --> {1: "a", 2: "b", 3: "c"} 27 | 28 | {"cat": "meow", "dog": "bark"} --> {"meow": "cat", "bark": "dog"} 29 | 30 |
31 | 32 | ## Question 4 - Birthday Lookup 33 | Write a program that takes a dictionary with names as keys and birthdates as values (in "YYYY-MM-DD" format). Allow the user to enter a name and return that person's birthdate if it exists, or "Not found" otherwise. 34 | 35 | INPUT OUTPUT 36 | 37 | {"Alice": "1990-05-15", "Bob": "1989-12-20"} --> "Alice" "1990-05-15" 38 | 39 | {"Alice": "1990-05-15", "Bob": "1989-12-20"} --> "Eve" "Not found" 40 | 41 |
42 | 43 | ## Question 5 - Inventory Management 44 | Write a function that takes a dictionary representing an inventory (item names as keys and quantities as values) and a list of items to be added. If an item is already in the inventory, increase its quantity by 1; if not, add it with quantity 1. 45 | 46 | INPUT OUTPUT 47 | 48 | {"apple": 2, "banana": 3} ["apple", "orange", "apple"] --> {"apple": 4, "banana": 3, "orange": 1} 49 | 50 | {"pen": 10, "pencil": 5} ["pencil", "notebook", "pen"] --> {"pen": 11, "pencil": 6, "notebook": 1} 51 | 52 |
53 | 54 | ## Question 6 - Unique Values 55 | Write a function that takes a dictionary and returns a list of unique values. 56 | 57 | INPUT OUTPUT 58 | 59 | {"a": 1, "b": 2, "c": 1, "d": 3} --> [1, 2, 3] 60 | 61 | {"apple": "fruit", "carrot": "vegetable", "banana": "fruit"} --> ["fruit", "vegetable"] 62 | 63 |
64 | 65 | ## Question 7 - Merge Dictionaries 66 | Write a function that takes two dictionaries and merges them into one. If there are any duplicate keys, the values from the second dictionary should overwrite those from the first. 67 | 68 | INPUT OUTPUT 69 | 70 | {"a": 1, "b": 2} {"b": 3, "c": 4} --> {"a": 1, "b": 3, "c": 4} 71 | 72 | {"name": "Alice", "age": 25} {"age": 30, "city": "NY"} --> {"name": "Alice", "age": 30, "city": "NY"} 73 | 74 |
75 | 76 | ## Question 8 - Char Frequency Counter 77 | Write a function that takes a string and returns a dictionary containing the frequency of each character. 78 | 79 | INPUT OUTPUT 80 | 81 | "hello" --> {"h": 1, "e": 1, "l": 2, "o": 1} 82 | 83 | "abracadabra" --> {"a": 5, "b": 2, "r": 2, "c": 1, "d": 1} 84 | 85 |
86 | 87 | ## Question 9 - Find the Max Key 88 | Write a function that takes a dictionary with string keys and integer values and returns the key with the highest value. 89 | 90 | INPUT OUTPUT 91 | 92 | {"apple": 5, "banana": 8, "orange": 3} --> "banana" 93 | 94 | {"Alice": 67, "Bob": 85, "Eve": 75} --> "Bob" 95 | 96 |
97 | 98 | ## Question 10 - Frequency of Frequencies 99 | Write a function that takes a list of numbers and returns a dictionary where the keys are the numbers from the list and the values are the frequencies of those numbers. 100 | 101 | INPUT OUTPUT 102 | 103 | [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] --> {1: 1, 2: 2, 3: 3, 4: 4} 104 | 105 | [7, 5, 5, 7, 7, 7, 8] --> {7: 4, 5: 2, 8: 1} 106 | -------------------------------------------------------------------------------- /Fall24/week07/random_examples.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | # # 1. random() - Generate a random floating-point number between 0.0 and 1.0 4 | print("random():", random.random()) 5 | 6 | # 2. randint(a, b) - Generate a random integer between a and b (inclusive) 7 | print("randint(1, 10):", random.randint(-10, 10)) 8 | 9 | # 3. uniform(a, b) - Generate a random floating-point number between a and b 10 | print("uniform(1, 10):", random.uniform(10, 100)) 11 | 12 | # 4. choice(seq) - Pick a random element from a non-empty sequence 13 | colors = ['red', 'green', 'blue', 'yellow'] 14 | print("choice(colors):", random.choice(colors)) 15 | 16 | # 5. choices(population, k=n) - Pick n random elements with replacement (duplicates allowed) 17 | print("choices(colors, k=10):", random.choices(colors, k=10)) 18 | 19 | # 6. sample(population, k=n) - Pick n unique elements without replacement 20 | numbers = list(range(1, 11)) 21 | print("sample(numbers, k=3):", random.sample(numbers, k=5)) 22 | 23 | # 7. shuffle(x) - Shuffle the list in place 24 | random.shuffle(numbers) 25 | print("shuffle(numbers):", numbers) 26 | 27 | # 8. randrange(start, stop, step) - Pick a random number from range(start, stop, step) 28 | print("randrange(0, 100, 10):", random.randrange(0, 100, 3)) 29 | -------------------------------------------------------------------------------- /Fall24/week08/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week08/.DS_Store -------------------------------------------------------------------------------- /Fall24/week08/Cmpe 150 Lab 8_ While Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week08/Cmpe 150 Lab 8_ While Loops.pdf -------------------------------------------------------------------------------- /Fall24/week08/WhileLoops.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Factorial 2 | Write a function factorial that takes a positive integer n and calculates its factorial using a while loop. 3 | 4 |
5 | 6 | ## Question 2 - Sum until Negative 7 | Write a function sum_until_negative that keeps asking the user for numbers until they enter a negative number. Return the sum of all non-negative numbers entered. 8 | 9 | INPUT -> OUTPUT 10 | 11 | Enter a number: 5 12 | 13 | Enter a number: 3 14 | 15 | Enter a number: 0 16 | 17 | Enter a number: -1 -> Sum: 8 18 | 19 |
20 | 21 | ## Question 3 - Guess the Number 22 | Write a function guess_the_number that generates a random number between 1 and 100 and keeps asking the user to guess it until they get it right. After each guess, tell the user if their guess was too high, too low, or correct. 23 | 24 | INPUT -> OUTPUT 25 | 26 | Guess a number: 50 -> Too high. 27 | 28 | Guess a number: 25 -> Too low. 29 | 30 | Guess a number: 37 -> Correct! 31 | 32 |
33 | 34 | ## Question 4 - Password Check 35 | Write a function password_check that repeatedly asks the user to enter a password until they enter the correct one. The correct password is "python123". 36 | 37 | INPUT -> OUTPUT 38 | 39 | Enter password: hello -> Wrong password. 40 | 41 | Enter password: python123 -> Access granted. 42 | 43 |
44 | 45 | ## Question 5 - Remove Elements 46 | Given a list, use a while loop to remove elements from the end until the remaining list has only even numbers. 47 | 48 |
49 | 50 | ## Question 6 - Count Word Frequencies 51 | Implement a word frequency counter using a while loop to iterate through a list of words and populate a dictionary. 52 | 53 |
54 | 55 | ## Question 7 - Move until Boundary 56 | Use a while loop to move a turtle forward until it hits the edge of the screen. 57 | 58 |
59 | 60 | ## Question 8 - Number Filter 61 | Write a function number_filter that takes a list of integers and two bounds low and high. Use a while loop to remove all numbers outside the range [low, high] from the list. 62 | 63 | INPUT -> OUTPUT 64 | 65 | [1, 5, 8, 12, 20], low=5, high=15 -> [5, 8, 12] 66 | 67 |
68 | 69 | ## Question 9 - Find the First Repeated Word 70 | Write a function first_repeated_word that takes a list of words and uses a while loop to find the first word that repeats. 71 | 72 | INPUT -> OUTPUT 73 | 74 | ["apple", "banana", "orange", "apple", "grape"] -> First repeated word: apple 75 | 76 |
77 | 78 | ## Question 10 - Dynamic Menu 79 | Write a function dynamic_menu that displays a menu to the user and keeps asking for a choice until they select "Quit". The menu options can be: 80 | 81 | Calculate Factorial 82 | 83 | Guess the Number 84 | 85 | Quit 86 | 87 | INPUT -> OUTPUT 88 | 89 | Menu: 90 | 91 | 1. Calculate Factorial 92 | 2. Guess the Number 93 | 3. Quit 94 | Enter your choice: 1 95 | Enter a number: 5 --> Factorial: 120 96 | 97 | Menu: 98 | 1. Calculate Factorial 99 | 2. Guess the Number 100 | 3. Quit 101 | Enter your choice: 3 --> Goodbye! 102 | -------------------------------------------------------------------------------- /Fall24/week08/while_loop_solutions.py: -------------------------------------------------------------------------------- 1 | # Question 1 - Factorial 2 | 3 | def factorial(): 4 | while True: 5 | n = int(input("Enter a positive integer: ")) 6 | if n < 0: 7 | print("Please enter a positive number.") 8 | continue 9 | result = 1 10 | i = 1 11 | while i <= n: 12 | result *= i 13 | i += 1 14 | print(f"Factorial of {n}: {result}") 15 | 16 | another = input("Do you want to calculate another factorial? (yes/no): ").lower() 17 | if another != "yes": 18 | break 19 | 20 | # Question 2 - Sum until Negative 21 | 22 | def sum_until_negative(): 23 | total = 0 24 | count = 0 25 | while True: 26 | num = int(input("Enter a number: ")) 27 | if num < 0: 28 | break 29 | total += num 30 | count += 1 31 | print(f"Sum: {total}") 32 | print(f"Numbers Entered: {count}") 33 | 34 | 35 | # Question 3 - Guess the Number 36 | 37 | import random 38 | 39 | def guess_the_number(): 40 | target = random.randint(1, 100) 41 | attempts = 0 42 | while True: 43 | guess = int(input("Guess a number: ")) 44 | attempts += 1 45 | if guess < target: 46 | print("Too low.") 47 | elif guess > target: 48 | print("Too high.") 49 | else: 50 | print(f"Correct! You guessed it in {attempts} attempts.") 51 | break 52 | 53 | # Question 4 - Password Check 54 | 55 | def password_check(): 56 | correct_password = "python123" 57 | attempts = 3 58 | while attempts > 0: 59 | password = input("Enter password: ") 60 | if password == correct_password: 61 | print("Access granted.") 62 | return 63 | else: 64 | attempts -= 1 65 | print(f"Wrong password. Attempts left: {attempts}") 66 | print("Access denied.") 67 | 68 | # Question 5 - Remove Elements 69 | 70 | def remove_elements(lst): 71 | i = 0 72 | while i < len(lst): 73 | if lst[i] % 2 != 0: # Check if the element is odd 74 | lst.pop(i) # Remove the odd number 75 | else: 76 | i += 1 # Move to the next index if the number is even 77 | print(f"Modified List: {lst}") 78 | print(f"List now has only even numbers.") 79 | 80 | # Call the function directly 81 | remove_elements([1, 2, 3, 4, 5, 6]) 82 | 83 | 84 | # Question 6 - Count Word Frequencies 85 | 86 | def count_word_frequencies(): 87 | word_frequencies = {} 88 | while True: 89 | word = input("Enter a word (type 'stop' to end): ").strip().lower() 90 | if word == "stop": 91 | break 92 | if word: 93 | word_frequencies[word] = word_frequencies.get(word, 0) + 1 94 | return word_frequencies 95 | 96 | # Example Usage 97 | frequencies = count_word_frequencies() 98 | print("Final Word Frequencies:", frequencies) 99 | 100 | # Question 7 - Move until Boundary 101 | 102 | import turtle 103 | import random 104 | 105 | def move_until_boundary(): 106 | screen = turtle.Screen() 107 | screen.setup(width=600, height=600) 108 | screen.setworldcoordinates(-300, -300, 300, 300) 109 | 110 | t = turtle.Turtle() 111 | while -300 < t.xcor() < 300 and -300 < t.ycor() < 300: 112 | t.forward(10) 113 | t.left(random.randint(-90, 90)) 114 | print("Turtle hit the boundary!") 115 | 116 | # Question 8 - Number Filter 117 | 118 | def number_filter(lst, low, high): 119 | i = 0 120 | while i < len(lst): 121 | if lst[i] < low or lst[i] > high: 122 | lst.pop(i) 123 | else: 124 | i += 1 125 | print(f"Filtered List: {lst}") 126 | 127 | 128 | # Question 9 - Find the First Repeated Word 129 | 130 | def first_repeated_word(words): 131 | seen = [] 132 | i = 0 133 | while i < len(words): 134 | if words[i] in seen: 135 | print(f"First repeated word: {words[i]}") 136 | return 137 | seen.append(words[i]) 138 | i += 1 139 | print("No repeated words.") 140 | 141 | first_repeated_word(['e', 'e', 'klm', 'klm', 'yu']) 142 | 143 | # Question 10 - Dynamic Menu 144 | 145 | def dynamic_menu(): 146 | while True: 147 | print("\nMenu:") 148 | print("1. Calculate Factorial") 149 | print("2. Guess the Number") 150 | print("3. Quit") 151 | choice = input("Enter your choice: ") 152 | 153 | if choice == "1": 154 | factorial() 155 | elif choice == "2": 156 | guess_the_number() 157 | elif choice == "3": 158 | print("Goodbye!") 159 | break 160 | else: 161 | print("Invalid choice. Try again.") 162 | -------------------------------------------------------------------------------- /Fall24/week09/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week09/.DS_Store -------------------------------------------------------------------------------- /Fall24/week09/Cmpe 150 Lab 9_ Strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week09/Cmpe 150 Lab 9_ Strings.pdf -------------------------------------------------------------------------------- /Fall24/week09/Strings.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Lowercase Conversion 2 | Write a function convert_to_lowercase that takes a string as input and returns the string in all lowercase letters using a string method. 3 | 4 | INPUT -> OUTPUT 5 | 6 | "Hello, WORLD!" -> "hello, world!" 7 | 8 |
9 | 10 | ## Question 2 - Count Specific Character 11 | Write a function count_character that takes a string and a character as input and returns the count of the character in the string. 12 | 13 | INPUT -> OUTPUT 14 | 15 | String: "banana", Character: 'a' -> 3 16 | 17 |
18 | 19 | ## Question 3 - Reverse String 20 | Write a function reverse_string that takes a string as input and returns the reversed version of the string. 21 | 22 | INPUT -> OUTPUT 23 | 24 | "Python" -> "nohtyP" 25 | 26 |
27 | 28 | ## Question 4 - Palindrome Check 29 | Write a function is_palindrome that checks if a given string is a palindrome (reads the same forwards and backwards, ignoring case and spaces). 30 | 31 | INPUT -> OUTPUT 32 | 33 | "Racecar" -> True 34 | 35 | "Hello" -> False 36 | 37 |
38 | 39 | ## Question 5 - Substring Finder 40 | Write a function find_substring that takes two strings: a main string and a substring. Return the starting index of the first occurrence of the substring in the main string, or -1 if it’s not found. 41 | 42 | INPUT -> OUTPUT 43 | 44 | Main String: "hello world", Substring: "world" -> 6 45 | 46 |
47 | 48 | ## Question 6 - Word Counter 49 | Write a function word_count that takes a string and returns the number of words in the string. Words are separated by spaces. 50 | 51 | INPUT -> OUTPUT 52 | 53 | "This is a sample sentence." -> 5 54 | 55 |
56 | 57 | ## Question 7 - Join Strings 58 | Write a function join_strings that takes a list of strings and a delimiter and returns a single string joined by the delimiter. 59 | 60 | INPUT -> OUTPUT 61 | 62 | ["apple", "banana", "cherry"], Delimiter: ", " -> "apple, banana, cherry" 63 | 64 |
65 | 66 | ## Question 8 - Replace Substring 67 | Write a function replace_substring that takes a string, a substring to replace, and a new substring, and returns the string with replacements made. 68 | 69 | INPUT -> OUTPUT 70 | 71 | String: "I like cats.", Old Substring: "cats", New Substring: "dogs" -> "I like dogs." 72 | 73 |
74 | 75 | ## Question 9 - Remove Whitespace 76 | Write a function strip_whitespace that removes leading and trailing whitespace from a given string. 77 | 78 | INPUT -> OUTPUT 79 | 80 | " hello " -> "hello" 81 | 82 |
83 | 84 | ## Question 10 - Dynamic String Menu 85 | Write a function string_menu that provides the user with the following options for a given string: 86 | 87 | Convert to Uppercase 88 | 89 | Count a Specific Character 90 | 91 | Reverse the String 92 | 93 | Quit 94 | 95 | It keeps showing the menu until the user selects "Quit". 96 | 97 | 98 | -------------------------------------------------------------------------------- /Fall24/week09/string_solutions.py: -------------------------------------------------------------------------------- 1 | # Question 1 - Lowercase Conversion 2 | def convert_to_lowercase(string): 3 | return string.lower() 4 | 5 | # Question 2 - Count Specific Character 6 | def count_character(string, char): 7 | return string.count(char) 8 | 9 | # Question 3 - Reverse String 10 | def reverse_string(string): 11 | return string[::-1] 12 | 13 | # Question 4 - Palindrome Check 14 | def is_palindrome(string): 15 | string = string.replace(" ", "").lower() 16 | return string == string[::-1] 17 | 18 | # Question 5 - Substring Finder 19 | def find_substring(main_string, substring): 20 | return main_string.find(substring) 21 | 22 | # Question 6 - Word Counter 23 | def word_count(string): 24 | return len(string.split()) 25 | 26 | # Question 7 - Join Strings 27 | def join_strings(strings, delimiter): 28 | return delimiter.join(strings) 29 | 30 | # Question 8 - Replace Substring 31 | def replace_substring(string, old, new): 32 | return string.replace(old, new) 33 | 34 | # Question 9 - Remove Whitespace 35 | def strip_whitespace(string): 36 | return string.strip() 37 | 38 | # Question 10 - Dynamic String Menu 39 | def string_menu(): 40 | while True: 41 | print("1. Convert to Uppercase") 42 | print("2. Count a Specific Character") 43 | print("3. Reverse the String") 44 | print("4. Quit") 45 | choice = input("Enter your choice: ") 46 | if choice == "1": 47 | string = input("Enter a string: ") 48 | print(string.upper()) 49 | elif choice == "2": 50 | string = input("Enter a string: ") 51 | char = input("Enter a character: ") 52 | print(count_character(string, char)) 53 | elif choice == "3": 54 | string = input("Enter a string: ") 55 | print(reverse_string(string)) 56 | elif choice == "4": 57 | print("Goodbye!") 58 | break 59 | else: 60 | print("Invalid choice.") 61 | 62 | -------------------------------------------------------------------------------- /Fall24/week10/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week10/.DS_Store -------------------------------------------------------------------------------- /Fall24/week10/Cmpe 150 Lab 10_ Sets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Fall24/week10/Cmpe 150 Lab 10_ Sets.pdf -------------------------------------------------------------------------------- /Fall24/week10/Sets.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Set Operations 2 | Write a function that takes two sets then prints union, intersection and difference operations between them. 3 | 4 | INPUT -> OUTPUT 5 | 6 | A = {1, 2, 3, 4, 5, 6} 7 | 8 | B = {1, 1, 2, 7, 11} -> A ∪ B = {1, 2, 3, 4, 5, 6, 7, 11}, A ∩ B = {1, 2}, A / B = {3, 4, 5, 6}, B / A = {11, 7} 9 | 10 |
11 | 12 | ## Question 2 - Check Subset 13 | Write a function is_subset that takes two sets as input and checks if the first set is a subset of the second. 14 | 15 | INPUT -> OUTPUT 16 | 17 | Set1: {1, 2}, Set2: {1, 2, 3} -> True 18 | 19 | Set1: {1, 4}, Set2: {1, 2, 3} -> False 20 | 21 |
22 | 23 | ## Question 3 - Remove Duplicates from List 24 | Write a function remove_duplicates that takes a list as input and uses a set to remove duplicates, returning the list without duplicates. 25 | 26 | INPUT -> OUTPUT 27 | 28 | [1, 2, 2, 3, 4, 4] -> [1, 2, 3, 4] 29 | 30 |
31 | 32 | ## Question 4 - Common Elements in Two Lists 33 | Write a function common_elements that takes two lists as input and returns a set of their common elements. 34 | 35 | INPUT -> OUTPUT 36 | 37 | List1: [1, 2, 3], List2: [2, 3, 4] -> {2, 3} 38 | 39 | 40 |
41 | 42 | ## Question 5 - Find Unique Values Across Dictionaries 43 | Write a function unique_values_across_dicts that takes two dictionaries and returns a set of all unique values across both. 44 | 45 | INPUT -> OUTPUT 46 | 47 | Dict1: {"a": 1, "b": 2}, Dict2: {"c": 3, "d": 2} -> {1, 2, 3} 48 | 49 |
50 | 51 | ## Question 6 - Merge Inventories 52 | Write a function merge_inventories that takes two dictionaries representing inventories (item names as keys and quantities as values) and merges them. If an item exists in both, add their quantities and return a single dictionary. 53 | 54 | INPUT -> OUTPUT 55 | 56 | Inventory1: {"apple": 2, "banana": 3}, Inventory2: {"apple": 1, "orange": 4} -> {"apple": 3, "banana": 3, "orange": 4} 57 | 58 |
59 | 60 | ## Question 7 - Filter by Threshold 61 | Write a function filter_by_threshold that takes a dictionary where keys are names and values are scores, and a threshold value. Return a set of names whose scores exceed the threshold. 62 | 63 | INPUT -> OUTPUT 64 | 65 | Scores: {"Alice": 85, "Bob": 78, "Eve": 92}, Threshold: 80 -> {"Alice", "Eve"} 66 | 67 |
68 | 69 | ## Question 8 - Common Words in Sentences 70 | Write a function common_words that takes two strings (representing sentences) and returns a set of words common to both sentences. 71 | 72 | INPUT -> OUTPUT 73 | 74 | "I like apples and oranges", "She likes oranges and grapes" -> {"oranges", "and"} 75 | 76 |
77 | 78 | ## Question 9 - Power Set Generator 79 | Write a function generate_power_set that takes a set and returns a list of all subsets (the power set). 80 | 81 | INPUT -> OUTPUT 82 | 83 | {1, 2} -> [set(), {1}, {2}, {1, 2}] 84 | 85 | {"a"} -> [set(), {"a"}] 86 | 87 |
88 | 89 | ## Question 10 - Find Anagrams Using Sets 90 | Write a function find_anagrams that takes two strings and determines if they are anagrams (ignoring case and spaces) using sets. 91 | 92 | 93 | INPUT -> OUTPUT 94 | 95 | "listen", "silent" -> True 96 | 97 | "hello", "world" -> False 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Fall24/week12/AnimatingShapes.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Moving Point Animation 2 | Write a function animate_point that animates a point moving along the x-axis in a 2D plot. The x-coordinates should range from 0 to 10, and the y-coordinate should remain constant at 5 throughout the animation. Ensure the point moves smoothly across the screen. 3 | 4 | 5 |
6 | 7 | ## Question 2 - Oscillating Sine Wave 8 | Write a function oscillating_wave that animates a sine wave oscillating vertically. The x-coordinates should range from 0 to 2π, and the wave should oscillate up and down over time. 9 | 10 | 11 |
12 | 13 | ## Question 3 - Bouncing Ball in a Box 14 | Write a function bouncing_ball that simulates a ball bouncing inside a 2D box of size 10×10. The ball should reflect off the walls (left, right, top, and bottom) when it hits them and continue bouncing inside the box. 15 | 16 | 17 |
18 | 19 | ## Question 4 - Circular Orbit Simulation 20 | Write a function circular_orbit that simulates two points orbiting a central point in circular paths. One point should have a radius of 1 and the other a radius of 2. Both points should orbit the center simultaneously, each moving at different speeds. 21 | 22 | 23 |
24 | 25 | ## Question 5 - Complex Ball Animation 26 | Write a function ball_following_wave that simulates a ball following a sine wave while also bouncing vertically. The ball should move horizontally along the sine wave and bounce vertically. Provide two versions of the solution. 27 | 28 |
29 | 30 | ## Question 6 - Animation of Multiple Moving Points 31 | Write a function animate_multiple_points that animates multiple points moving along the x-axis. Each point should have its own speed, and the points should be distinguished by different colors. The points should move in parallel but at different rates. 32 | 33 | 34 |
35 | 36 | ## Question 7 - Bouncing Ball with Gravity 37 | Write a function bouncing_ball_gravity that simulates a ball bouncing inside a 10×10 box with gravity applied. The ball should start at a random position within the box (not on the edges) and should accelerate downward due to gravity. It should bounce off the floor with energy loss each time it hits the floor. The ball's speed should increase as it falls, and it should slow down when moving upward. The ball should maintain realistic physics, with gravity causing the ball to accelerate downward and decelerate when moving upward. The ball should also bounce off the walls (left, right, top) and never go outside the box. 38 | 39 | 40 |
41 | 42 | ## Question 8 - Pendulum Simulation 43 | Write a function pendulum_simulation that simulates a simple pendulum. The pendulum should swing back and forth, and its motion should be based on simple harmonic motion principles. The pendulum should eventually stop after a few oscillations due to damping (energy loss). 44 | 45 |
46 | 47 | ## Question 9 - Color Changing Sine Wave 48 | Write a function color_changing_sine_wave that animates a sine wave whose color changes dynamically as the wave oscillates. The wave's color should transition smoothly from one color to another over time. 49 | 50 | 51 |
52 | 53 | ## Question 10 - Expanding Circle 54 | Write a function expanding_circle that animates a circle whose radius increases over time. The circle should start small and expand while remaining centered on the screen. The expansion should stop once the circle hits the border of the box, and the animation should end. 55 | 56 | -------------------------------------------------------------------------------- /PyCharm Installation Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/PyCharm Installation Guide.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CmpE150 - Fall 2024 2 | 3 | Bogazici University CmpE 150 Introduction to Computing (Python programming language) Notes 4 | 5 | **E-mails:** 6 | 7 | * [cmpe150.mail@gmail.com](mailto:cmpe150.mail@gmail.com) 8 | 9 | **Additional Materials** 10 | 11 | * [Installation Guide](PyCharm%20Installation%20Guide.pdf) 12 | * http://www.pythontutor.com/visualize.html 13 | 14 | 15 | 16 | ## Exercises 17 | 18 | ### [Week1](Fall24/week01) 19 | 20 | * Introduction to Computing and Python 21 | * Basic Mathematical Expressions 22 | 23 | 24 | ### [Week2](Fall24/week02) 25 | 26 | * Functions 27 | * Turtle Graphics 28 | 29 | 30 | ### [Week3](Fall24/week03) 31 | 32 | * Text IO and File Operations 33 | * Drawing with Input 34 | 35 | 36 | ### [Week4](Fall24/week04) 37 | 38 | * Logic Operations (If-Elif-Else) 39 | * Recursive Functions 40 | 41 | 42 | ### [Week5](Fall24/week05) 43 | 44 | * Repeating Instructions for Loops in Detail 45 | * Printing Console Shapes with for Loops 46 | 47 | 48 | ### [Week6](Fall24/week06) 49 | 50 | * Random Numbers 51 | * Tuples and Lists 52 | 53 | ### [Week7](Fall24/week07) 54 | 55 | * Dictionaries 56 | 57 | 58 | ### [Week8](Fall24/week08) 59 | 60 | * Conditional Loop 61 | 62 | 63 | ### [Week9](Fall24/week09) 64 | 65 | * Strings 66 | 67 | 68 | ### [Week10](Fall24/week10) 69 | 70 | * Sets 71 | 72 | ### [Week11](Fall24/week11) 73 | 74 | * Lists and Tuples in Detail 75 | 76 | ### [Week12](Fall24/week12) 77 | 78 | * Animating Shapes 79 | 80 | -------------------------------------------------------------------------------- /Spring21/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/.DS_Store -------------------------------------------------------------------------------- /Spring21/figures/1616341138563.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/1616341138563.png -------------------------------------------------------------------------------- /Spring21/figures/1616342184949.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/1616342184949.png -------------------------------------------------------------------------------- /Spring21/figures/1616342517499.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/1616342517499.png -------------------------------------------------------------------------------- /Spring21/figures/ChangeTheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/ChangeTheme.png -------------------------------------------------------------------------------- /Spring21/figures/HTML_Browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/HTML_Browser.png -------------------------------------------------------------------------------- /Spring21/figures/HTML_Explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/HTML_Explorer.png -------------------------------------------------------------------------------- /Spring21/figures/Maintxt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/Maintxt.png -------------------------------------------------------------------------------- /Spring21/figures/PythonInstaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/PythonInstaller.png -------------------------------------------------------------------------------- /Spring21/figures/Teaching.Codes New Version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/Teaching.Codes New Version.png -------------------------------------------------------------------------------- /Spring21/figures/Teaching.Codes Uninstall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/Teaching.Codes Uninstall.png -------------------------------------------------------------------------------- /Spring21/figures/Teaching.Codes Version 1212JB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/Teaching.Codes Version 1212JB.png -------------------------------------------------------------------------------- /Spring21/figures/commit_and_push_failed1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/commit_and_push_failed1.png -------------------------------------------------------------------------------- /Spring21/figures/commit_and_push_failed2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/commit_and_push_failed2.png -------------------------------------------------------------------------------- /Spring21/figures/connection.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/connection.PNG -------------------------------------------------------------------------------- /Spring21/figures/could not open.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/could not open.PNG -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618485979513.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618485979513.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618486104949.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618486104949.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618486398394.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618486398394.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618486497781.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618486497781.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618486752521.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618486752521.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618486890025.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618486890025.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487070207.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487070207.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487098652.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487098652.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487165943.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487165943.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487273664.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487273664.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487440503.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487440503.png -------------------------------------------------------------------------------- /Spring21/figures/project-guide/1618487934948.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/project-guide/1618487934948.png -------------------------------------------------------------------------------- /Spring21/figures/python-customize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/python-customize.png -------------------------------------------------------------------------------- /Spring21/figures/python-final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/python-final.png -------------------------------------------------------------------------------- /Spring21/figures/python-optional.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/python-optional.png -------------------------------------------------------------------------------- /Spring21/figures/team-fixed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/figures/team-fixed.png -------------------------------------------------------------------------------- /Spring21/week01/README.md: -------------------------------------------------------------------------------- 1 | ## Welcome to CMPE150 Lab Session and programming! 2 | 3 | 4 | 5 | 6 | 7 | ### Assistants: 8 | 9 | ![1616505237530](../figures/team-fixed.png) 10 | 11 | ## Announcements 12 | 13 | - We will use **PyCharm** and **Teaching Codes** plug-in in projects and exams. Student accounts will be created for this plug-in. 14 | 15 | - The username and password will be sent to **the e-mail in BUIS** **after add drop period**. We will make an announcement when the credentials are sent. 16 | 17 | - If your email address that you use in BUIS (registration.boun.edu.tr) is anything other than 18 | 19 | - **@gmail** 20 | - **@boun.edu.tr** 21 | 22 | Please change it to @gmail.com, or @boun.edu.tr. In order to do that, 23 | 24 | - Go to https://registration.boun.edu.tr, and Login. 25 | - Enter General Settings, and then E-Mail Management. 26 | - You should change your current Contact E-mail Address to @boun.edu.tr or @gmail.com. 27 | 28 | - Please check announcements on Moodle **regularly**! 29 | 30 | - Lab hours are dedicated to **practical programming exercises not for covering lecture materials**. I **strongly** suggest you to attend the lectures. 31 | 32 | - Follow the Installation Guide and TeachingCodes Guide to complete installation and get familiar with the environment. 33 | 34 | - The installation must be completed **until April 9, 2021**. After that date, questions regarding installation **WILL NOT BE ANSWERED.** 35 | 36 | - What counts as **cheating**: 37 | - **Information exchange between students:** Giving and Receiving information to/from your colleagues both count as cheating. 38 | - **Using codes from any source other than the materials of our course:** You can consult internet or books to learn and improve your programming skills. But you shouldn't use any material that is not your own work in the projects and exams. 39 | 40 | - Check **FAQ** and **Technical Support** to get help. 41 | 42 | ![1616502949955](figures/moodle.png) 43 | -------------------------------------------------------------------------------- /Spring21/week01/figures/moodle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/week01/figures/moodle.png -------------------------------------------------------------------------------- /Spring21/week02/README.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | ## Question 1 4 | 5 | **a)** Create two integer variables, and print them 6 | 7 | **b)** Take two integers from the user, and print them 8 | 9 | **c)** Take two integers from the user (a, b), and then print their sum, difference, product, power and remainder. 10 | 11 | | Input | Output | 12 | | -------- | ---------------- | 13 | | 13 5 | 18 8 65 371293 3 | 14 | 15 | ## Question 2 16 | 17 | **a)** Create an integer, a float, and a string variable. Print their types, using the type() function. 18 | 19 | **b)** Take an integer, a float, and a string variable from the user. Print the variables. 20 | 21 | ## Question 3 22 | 23 | Write a program that takes 3 integers from the user and then prints the sum, mean and multiple of the numbers. 24 | 25 | | Input | Output | 26 | | -------- | ---------------- | 27 | | 13 27 14 | 54 18.00 4914| 28 | 29 |
30 | 31 | ## Question 4 32 | 33 | Using the formula below of compound interest, take the **principal amount (A)**, **interest rate (i)** (per month) and **duration (n)** (months) and print the final amount. 34 | 35 | 36 | 37 | 38 | | Input | Output | 39 | | --------- | ------- | 40 | | 1000 12 5 | 1762.34 | 41 | | 500 12 5 | 881.17 | 42 | 43 |
44 | 45 | ## Question 5 46 | 47 | Write a program which takes the values in **Ohm** of two parallel resistances and the generator's voltage in **Volt** respectively and print the currents that passes by each resistance. 48 | 49 | 50 | 51 | 52 | | Input | Output | 53 | | ------ | ------ | 54 | | 2 8 40 | 20 5 | 55 | | 5 5 10 | 2 2 | 56 | 57 |
58 | 59 | ## Question 6 60 | 61 | Write a program that calculates the amount of seconds in a given period of years, months, days, hours and minutes respectively. 62 | 63 | * 1 year = 365 days 64 | * 1 month = 30 days 65 | 66 | | Input | Output | 67 | | --------- | --------- | 68 | | 5 2 4 3 0 | 163220400 | 69 | | 1 1 1 1 1 | 34218060 | 70 | 71 |
72 | -------------------------------------------------------------------------------- /Spring21/week02/Solutions.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | ## Q1.a 4 | 5 | ```python 6 | number1 = 13 7 | number2 = 5 8 | 9 | # Printing numbers in separate lines 10 | print(number1) 11 | print(number2) 12 | 13 | # Printing numbers in a single line 14 | print(number1, number2) 15 | ``` 16 | 17 | ## Q1.b 18 | 19 | ```python 20 | number1 = int(input()) 21 | number2 = int(input()) 22 | 23 | print(number1) 24 | print(number2) 25 | ``` 26 | 27 | ## Q1.c 28 | 29 | ```python 30 | a = int(input()) 31 | b = int(input()) 32 | 33 | print(a + b, a - b, a * b, a ** b, a % b) 34 | ``` 35 | 36 | ## Q2.a 37 | 38 | ```python 39 | number = 5 40 | my_float = 9.8 41 | my_str = "Helloo" 42 | 43 | print(type(number)) 44 | print(type(my_float)) 45 | print(type(my_str)) 46 | ``` 47 | 48 |
49 | 50 | ## Q2.b 51 | 52 | ```python 53 | number = int(input("Enter an integer: ")) 54 | my_float = float(input("Enter a float ")) 55 | my_str = input("Please enter third number: ") 56 | 57 | print(number, my_float, my_str) 58 | # Same print with + operator (concatenation of strings)) 59 | print(str(number) + " " + str(my_float) + " " + my_str) 60 | ``` 61 | 62 |
63 | 64 | 65 | 66 | ## Q3 67 | ```python 68 | number1 = int(input("First number: ")) 69 | number2 = int(input("Second number: ")) 70 | number3 = int(input("Third number: ")) 71 | 72 | sum = number1 + number2 + number3 73 | 74 | print(sum) 75 | print(sum / 3) 76 | print(number1 * number2 * number3) 77 | ``` 78 | 79 |
80 | 81 | ## Q4 82 | ```python 83 | A = int(input("Enter principal amount: ")) 84 | i = int(input("Enter interest rate: ")) 85 | n = int(input("Enter duration: ")) 86 | 87 | S = A * (1 + i/100) ** n 88 | 89 | print("{:.2f}".format(S)) 90 | ``` 91 | 92 |
93 | 94 | ## Q5 95 | ```python 96 | r1 = int(input("First resistance: ")) 97 | r2 = int(input("Second resistance: ")) 98 | 99 | v = int(input("Voltage: ")) 100 | 101 | print(int(v / r1), int(v / r2)) 102 | 103 | ``` 104 | 105 |
106 | 107 | ## Q6 108 | ```python 109 | y = int(input("Year: ")) 110 | m = int(input("Month: ")) 111 | d = int(input("Days: ")) 112 | h = int(input("Hours: ")) 113 | min = int(input("Minutes: ")) 114 | 115 | y = y * 365 * 24 * 60 * 60 116 | m = m * 30 * 24 * 60 * 60 117 | d = d * 24 * 60 * 60 118 | h = h * 60 * 60 119 | min = min * 60 120 | 121 | sum = y + m + d + h + min 122 | 123 | print(sum) 124 | ``` 125 | 126 | Alternative: 127 | 128 | ```python 129 | y = int(input("Year: ")) 130 | m = int(input("Month: ")) 131 | d = int(input("Days: ")) 132 | h = int(input("Hours: ")) 133 | min = int(input("Minutes: ")) 134 | 135 | sum = (((y * 365 + m * 30 + d) * 24 + h) * 60 + min) * 60 136 | 137 | print(sum) 138 | ``` 139 | 140 |
141 | -------------------------------------------------------------------------------- /Spring21/week03/Solutions.md: -------------------------------------------------------------------------------- 1 | # Variables / Expressions / Statements 2 | 3 | You may clean strings in input and print functions. 4 | 5 | ## Q1 6 | ```python 7 | from math import pi 8 | 9 | r = int(input("Plese enter a radius: ")) 10 | 11 | print("The perimeter of the circle with given radius is: " + str(2*pi*r)) 12 | print("The surface of the circle with given radius is: " + str(pi*r**2)) 13 | ``` 14 | 15 |
16 | 17 | ## Q2 18 | ```python 19 | import math 20 | 21 | r = int(input("Plese enter a radius: ")) 22 | 23 | print("The volume of the sphere with the given radius is: " + str(4.0/3*math.pi*math.pow(r,3))) 24 | ``` 25 | 26 |
27 | 28 | ## Q3 29 | ```python 30 | n = int(input("Plese enter a number: ")) 31 | 32 | print("The sum till the given number is: " + str((n*(n+1))/2)) 33 | 34 | ``` 35 | 36 |
37 | 38 | ## Q4 39 | ```python 40 | a = int(input("Plese enter the first number: ")) 41 | b = int(input("Plese enter the second number: ")) 42 | 43 | # Version 0 (Easy Swap): 44 | original_a = a 45 | original_b = b 46 | a = original_b 47 | b = original_a 48 | 49 | # Version 1 (Classic Swap): 50 | temp = a 51 | a = b 52 | b = temp 53 | 54 | # Version 2 (Without using extra variable): 55 | # a = a + b 56 | # b = a - b 57 | # a = a - b 58 | 59 | # Version 3 (Python Variation): 60 | # a, b = b, a 61 | 62 | print("Here they are inversed: " + str(a) + " " + str(b)) 63 | ``` 64 | 65 |
66 | 67 | ## Q5 68 | ```python 69 | ll = input("Plese enter a lowercase letter: ") 70 | 71 | ul = chr(ord(ll) + ord("A") - ord("a")) 72 | 73 | print("Here is the upparcase version: " + ul) 74 | 75 | # Built-in function 76 | # print(ll.upper()) 77 | ``` 78 | 79 |
80 | 81 | 82 | ## Q6 83 | ```python 84 | a = int(input("Please enter the first number: ")) 85 | b = int(input("Please enter the second number: ")) 86 | c = int(input("Please enter the third number: ")) 87 | 88 | print(a * (a % 2) + b * (b % 2) + c * (c % 2)) 89 | ``` 90 | 91 | **Alternative solution (using if)** 92 | 93 | ```python 94 | a = int(input("Please enter the first number: ")) 95 | b = int(input("Please enter the second number: ")) 96 | c = int(input("Please enter the third number: ")) 97 | 98 | sum = 0 99 | 100 | if a % 2 == 1: 101 | sum = sum + a 102 | # Equivalent expression: sum += a 103 | 104 | if b % 2 == 1: 105 | sum = sum + b 106 | # Equivalent expression: sum += b 107 | 108 | if c % 2 == 1: 109 | sum = sum + c 110 | # Equivalent expression: sum += c 111 | 112 | print(sum) 113 | ``` 114 | 115 |
116 | 117 | ## Q7 118 | ```python 119 | amount = int(input("Please enter the amount of money requested by the customer: ")) 120 | 121 | print("Number of 5tl banknotes: %d" % (amount//5)) 122 | print("Number of 1tl coins: %d" % (amount%5)) 123 | ``` 124 | 125 |
126 | 127 | ## Q8 128 | 129 | ```python 130 | print(int('6') + int('4')) 10 131 | print('1' + '4') 14 132 | print(int(3.9)) 3 133 | print(str(5.3) + '2.7') 5.32.7 134 | print(int('5') * str(0.6)) 0.60.60.60.60.6 135 | print(float('3' + '8.6')) 38.6 136 | print(3.5 + 6.7) 10.2 137 | print(2 ** 3 ** 2 / 32) 16.0 138 | print(str(4.4) + str(7.3)) 4.47.3 139 | print(int(6.5) + float('6.5')) 12.5 140 | print(int(4.5 + 3.2)) 7 141 | print(int(3.2) + int(float(str(3.2)))) 6 142 | ``` 143 | 144 |
145 | 146 | ## Q9 147 | ```python 148 | dividend = int(input()) 149 | divisor = int(input()) 150 | 151 | quotient = dividend // divisor 152 | remainder = dividend % divisor 153 | # remainder = dividend - (quotient * divisor) 154 | 155 | print("quotient =", str(quotient), "remainder =", str(remainder)) 156 | ``` 157 | 158 |
159 | 160 | ## Q10 161 | ```python 162 | a = float(input()) 163 | b = float(input()) 164 | c = float(input()) 165 | 166 | floor_a = a // 1 167 | floor_b = b // 1 168 | floor_c = c // 1 169 | 170 | fraction_a = a - floor_a 171 | fraction_b = b - floor_b 172 | fraction_c = c - floor_c 173 | 174 | # print(str(fraction_a), str(fraction_b), str(fraction_c)) 175 | print("%.2f %.2f %.2f" % (fraction_a, fraction_b, fraction_c)) 176 | 177 | ``` 178 | 179 |
180 | -------------------------------------------------------------------------------- /Spring21/week11/data/paragraph.txt: -------------------------------------------------------------------------------- 1 | Eating raw fish didn't sound like a good idea. "It's a delicacy in Japan," didn't seem to make it any more appetizing. Raw fish is raw fish, delicacy or not -------------------------------------------------------------------------------- /Spring21/week12/External Libraries.md: -------------------------------------------------------------------------------- 1 | # External Libraries 2 | 3 | ## Outline 4 | 5 | * How to Install External Libraries 6 | * Widely used Python libraries: Numpy and Pandas 7 | * **Demo:** Exploring ‘Game Of Thrones’ Battles 8 | 9 | ## How to Install External Libraries 10 | 11 | ![img](https://pypi.org/static/images/logo-large.72ad8bf1.svg) 12 | 13 | * The Python Package Index (PyPI) is a repository of software for the Python programming language. 14 | 15 | **~ 310K packages** 16 | 17 | * To install these packages, a package manager is required. PIP is the default package installer for Python. The packages can be downloaded by running the following command on the command line: 18 | 19 | ```bash 20 | pip install 21 | ``` 22 | 23 | * However, the projects could have the same dependency, but depend on incompatible versions of the shared package. For example, you can have ProjectA and ProjectB depending on packageX where ProjectA requires the first version of packageX and ProjectB requires the second version of packageX which are not compatible. If you use the same "environment" for both projects, Python cannot differentiate between these versions. Thus, we need separate environments for projects. 24 | 25 | * We can create a new virtual environment while creating a new project in PyCharm: 26 | 27 | ![1623750783722](figures/1623750783722.png) 28 | 29 | * When we open the terminal after the project is created, we can see that the environment is activated (the name of the virtual environment in brackets). 30 | 31 | ![1623751368006](figures/1623751368006.png) 32 | 33 | * We need the following libraries for this session: 34 | 35 | * Numpy (NumericalPython) 36 | * Pandas (Data Manipulation) 37 | * Scikit-Learn (Machine Learning) 38 | * Matplotlib (Visualization) 39 | * Seaborn (Extension of Matplotlib) 40 | * Jupyter Notebook (Web based application for documents) 41 | 42 | * To install the required packages, open the terminal and run these lines: 43 | 44 | ```bash 45 | pip install numpy 46 | ``` 47 | 48 | ```bash 49 | pip install pandas 50 | ``` 51 | 52 | ```bash 53 | pip install scikit-learn 54 | ``` 55 | 56 | ```bash 57 | pip install matplotlib 58 | ``` 59 | 60 | ```bash 61 | pip install seaborn 62 | ``` 63 | 64 | ```bash 65 | pip install notebook 66 | ``` 67 | 68 | * If the installation is completed successfully, you can open Jupyter Notebook by typing `jupyter-notebook` on the command line. 69 | 70 | ![1623752067689](figures/1623752067689.png) 71 | 72 | 73 | ## Widely used Python libraries: Numpy and Pandas: available [here](Widely%20used%20Python%20libraries%20Numpy%20and%20Pandas.ipynb) as a jupyter notebook 74 | ## Exploring ‘Game Of Thrones’ Battles: available [here](Exploring%20'Game%20of%20Thrones'%20Battles.ipynb) as a jupyter notebook 75 | 76 | 77 | -------------------------------------------------------------------------------- /Spring21/week12/Solutions.md: -------------------------------------------------------------------------------- 1 | # Dictionaries 2 | 3 | ## Question 1 4 | 5 | ```python 6 | def name_to_age_ratio(a): 7 | result = [] 8 | for name, age in a.items(): 9 | total_characters = sum([len(word) for word in name.split()]) 10 | result.append(totalCharacters / age) 11 | return result 12 | ``` 13 | 14 | ### Alternative 15 | 16 | ```python 17 | def name_to_age_ratio(info): 18 | results = [] 19 | for name in info: 20 | results.append(sum([for ch in name if not ch.isspace()]) / info[name]) 21 | return results 22 | ``` 23 | 24 | ## Question 2 25 | 26 | ```python 27 | mylist = str(input()).split() 28 | mydict = {} 29 | 30 | for i in mylist: 31 | mydict[i] = 1 if mydict.get(i) is None else mydict[i] + 1 32 | for i in sorted(mydict, key = mydict.get, reverse = True): 33 | print(i, end = " ") 34 | ``` 35 | 36 | ### Alternative 37 | 38 | ```python 39 | words = str(input()).split() 40 | counts = {} 41 | for word in words: 42 | # counts[word] = counts.get(word, 0) + 1 43 | if word not in counts: 44 | counts[word] = 1 45 | else: 46 | counts[word] += 1 47 | counts_sorted = sorted(counts, key=counts.get, reverse=True) # returns words 48 | print(' '.join(counts_sorted)) 49 | ``` 50 | 51 | ## Question 3 52 | 53 | ```python 54 | def tickets(people): 55 | change = {25: 0, 50: 0, 100: 0} 56 | for money in people: 57 | if money == 25: 58 | change[25] += 1 59 | elif money == 50: 60 | change[25] -= 1 61 | change[50] += 1 62 | elif money == 100 and change[50] > 0: 63 | change[25] -= 1 64 | change[50] -= 1 65 | elif money==100 and change[50] == 0: 66 | change[25] -= 3 67 | 68 | if change[25] < 0 or change[50] < 0: 69 | return 'NO' 70 | return 'YES' 71 | 72 | print(tickets([25, 25, 50])) # => YES 73 | print(tickets([25, 100])) # => NO. Vasya will not have enough money to give change to 100 dollars 74 | print(tickets([25, 25, 50, 50, 100])) # => NO. Vasya will not have the right bills to give 75 dollars of change (you can't make two bills of 25 from one of 50) 75 | ``` 76 | 77 | # Sets 78 | 79 | ## Question 1 80 | 81 | ```python 82 | A = {1, 2, 3, 4, 5, 6} 83 | B = {1, 1, 2, 7, 11} 84 | 85 | def set_operations(set1, set2): 86 | print("A ∪ B = {}".format(set1.union(set2))) 87 | print("A ∩ B = {}".format(set1.intersection(set2))) 88 | print("A / B = {}".format(set1.difference(set2))) 89 | print("B / A = {}".format(set2.difference(set1))) 90 | 91 | set_operations(A, B) 92 | ``` 93 | 94 | ## Question 2 95 | 96 | ```python 97 | required = {"CmpE150","CmpE160","CmpE220","CmpE250","CmpE260"} 98 | def is_eligible(current): 99 | if len(required.intersection(current)) == len(required): 100 | return "Eligible" 101 | else: 102 | return "Not Eligible" 103 | print(is_eligible({"Cmpe150"})) 104 | ``` 105 | 106 | ## Question 3 107 | 108 | ```python 109 | def overall_traits(traits1, traits2): 110 | intersection = traits1.intersection(traits2) 111 | return sum(intersections) 112 | ``` 113 | 114 | ## Question 4 115 | 116 | ```python 117 | def is_distinct(string): 118 | return len(set(string)) == len(string) 119 | 120 | print(is_distinct('violate')) 121 | ``` 122 | 123 | -------------------------------------------------------------------------------- /Spring21/week12/figures/1623750783722.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/week12/figures/1623750783722.png -------------------------------------------------------------------------------- /Spring21/week12/figures/1623751368006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/week12/figures/1623751368006.png -------------------------------------------------------------------------------- /Spring21/week12/figures/1623752067689.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring21/week12/figures/1623752067689.png -------------------------------------------------------------------------------- /Spring22/ReadME: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Spring22/python2022spring22/week10/ps7 chapter list week10.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week10/ps7 chapter list week10.pptx -------------------------------------------------------------------------------- /Spring22/python2022spring22/week10/solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 2 | ```python 3 | list=["pasta",14, False, "True", 3.5,"makarna",(3,8),12] 4 | 5 | for item in list: 6 | if type(item)==str or type(item)==int: 7 | print (item, end=" ") 8 | ``` 9 | 10 | ## Question 2 11 | ```python 12 | the_list=["horse","chicken","pig","lamb","cow","ox","rooster"] 13 | 14 | if len(the_list)>= 5 and len(the_list)%2!=0: 15 | a=len(the_list) 16 | the_list=the_list[0:int((a-3)/2)]+the_list[-int((a-3)/2):a] 17 | print(the_list) 18 | else: 19 | print(the_list) 20 | ``` 21 | 22 | ## Question 3 23 | ```python 24 | def to_the_left(list,N): 25 | return list[N:] + list[:N] 26 | 27 | print(to_the_left(["i","r","r","e","p","l","a","c","a","b","l","e"], 8)) 28 | ``` 29 | ## Question 4 30 | ``` python 31 | def remove_odd_ones(list): 32 | return [value for value in list if value%2!= 1] 33 | 34 | print(remove_odd_ones([0,12,4,21,53,346,234])) 35 | ``` 36 | ## Question 5 37 | ```python 38 | def adding_additions(list): 39 | new_list=[] 40 | for i in range(0,len(list)-1): 41 | addition=list[i]+list[i+1] 42 | new_list.append(list[i]) 43 | new_list.append(addition) 44 | new_list.append(list[len(list)-1]) 45 | 46 | return new_list 47 | 48 | print(adding_additions([1,3,5,7,8])) 49 | ``` 50 | ## Question 6 51 | ```python 52 | def create_duplicates(list): 53 | result = [] 54 | for item in list: 55 | for i in range(item): 56 | result.append(item) 57 | 58 | return result 59 | 60 | 61 | print(create_duplicates([3,2,6,9,3,1])) 62 | ``` 63 | ## Question 7 64 | ```python 65 | def popper(list,N): 66 | list.pop(N-1) 67 | return list 68 | 69 | def remover(list,N): 70 | Nth_item= list[N-1] 71 | for item in list: 72 | if item==Nth_item: 73 | list.remove(item) 74 | 75 | return list 76 | 77 | print(remover(["apples","oranges", "JFK", "potato","tomato"],3)) 78 | ``` 79 | ## Question 8 80 | ```python 81 | N=str(input()) 82 | list_of_strings=[N] 83 | 84 | while N != ".": 85 | N=str(input()) 86 | list_of_strings.append(N) 87 | 88 | def reverse_strings(string): 89 | return " ".join([letter[::-1] for letter in string.split()]) 90 | 91 | result=[] 92 | 93 | for string in list_of_strings: 94 | string=reverse_strings(string) 95 | result.append(string) 96 | 97 | result.reverse() 98 | 99 | def join_strings_as_one(strings): 100 | return " ".join(string if string!="." else "" for string in strings) 101 | 102 | print (join_strings_as_one(result)) 103 | ``` 104 | ## Question 9 105 | ```python 106 | list_of_integers= [1,5,54,312,52,9] 107 | list_of_strings= ["Slytherin","Gryffindor", "Ravenclaw","Hufflepuff"] 108 | 109 | list_of_integers.sort() 110 | list_of_strings.sort() 111 | 112 | print(list_of_integers) 113 | print(list_of_strings) 114 | ``` 115 | ## Question 10 116 | ```python 117 | def counter(list): 118 | the_most_recurring=0 119 | counter=0 120 | 121 | for item in list: 122 | a=list.count(item) 123 | if a>counter: 124 | the_most_recurring=item 125 | counter=a 126 | 127 | return the_most_recurring 128 | 129 | print(counter([3,2,1,2,2,2,3,1,1,3,2,5,1])) 130 | ``` 131 | -------------------------------------------------------------------------------- /Spring22/python2022spring22/week12/README.md: -------------------------------------------------------------------------------- 1 | # Week 12 - Dictionary and Sets 2 | 3 | ## Question 1- Disctinctness 4 | 5 | A distinct string is a string whose all characters occurs only once. Write a function that takes a string as an argument and checks whether given string is distinct or not. 6 | 7 | 8 | | Input | Output | 9 | |-----------| ------ | 10 | | slay | True | 11 | | obliviate | False | 12 | | mahmut | False | 13 | 14 | ## Question 2 - Seperating the Types 15 | 16 | Write a program that takes lists of different types, then seperates the inputs according to their types. The program should print the inputs with their types just like in the example. 17 | 18 | | Input | Output | 19 | | ------------------------------------------------------------ | ---------- | 20 | | ["music",13,True, "black", (26,1),"16", "False","pencil"] | ==> ['music', 'black', '16', 'False', 'pencil']
==> [13]
==> [True]
==> [(26, 1)] | 21 | 22 | ## Question 3 - imdB 23 | 24 | Write a program that reads lines from the input. Each line will be composed of 4 words, name of the movie, genre of the movie, year of release and the director respectively. If a line is equal to "exit", stop reading. Store the games in a dictionary. Their values should also correspond to dictionaries composed of their genre, release_data and director 25 | 26 | | Input | Output | 27 | | ------------------------------------------------------------ | ---------- | 28 | | Black Swan, Thriller, 2010, Darren Aronofsky

Dunkirk, Action, 2017, Christopher Nolan

The Rocky Horror Picture Show, Musical, 1975, Jim Sherman

The Matrix, Sci-Fi, 1999, Wachowski Sisters

exit | {'Black Swan': {'genre': ' Thriller', 'release_date': ' 2010', 'director': ' Darren Aronofsky'}, 'Dunkirk': {'genre': ' Action', 'release_date': ' 2017', 'director': ' Christopher Nolan'}, 'The Rocky Horror Picture Show': {'genre': ' Musical', 'release_date': ' 1975', 'director': ' Jim Sherman'}, 'The Matrix': {'genre': ' Sci-Fi', 'release_date': ' 1999', 'director': ' Wachowski Sisters'}} | 29 | 30 | ## Question 4 - String Who Should Not Be Written 31 | 32 | Anagram is a word formed by rearranging the letters of a different word (heart, earth). Write a program that takes a tuple of two strings and prints out "Anagram" if the tuple has an anagram. 33 | 34 | | Input | Output | 35 | |----------------------------------------------| ---------- | 36 | | ("peach","cheap") | Anagram | 37 | | ("TOM MARVOLO RIDDLE","I AM LORD VOLDEMORT") | Anagram | 38 | 39 | ## Question 5 - Cooking Oil Lines 40 | 41 | The cooking oil prices have just been raised! There are a lot of people at the supermarket check-out line. Each of them has a single 200,100,50 Turkish liras. A liter of cooking oil costs 50 Turkish liras. 42 | 43 | Yiğit is currently working as a cashier. He wants to sell cooking oil to every single person before the prices are raised again next week but he cannot accept credit cards at the moment or has any cash. 44 | 45 | Can Yiğit sell cooking oil (only a liter to each) to every person and give change to all of them strictly in the order of the line? 46 | 47 | Return YES, if Yiğit can sell cooking oil to every person and give change with the bills he has at that moment. Otherwise return NO. 48 | 49 | | Input | Output | Explanation | 50 | | --------------------- | ------ | ------------------------------------------------------------ | 51 | | [50, 50, 100] | YES | | 52 | | [50, 200] | NO | Yiğit will not have enough money to give change to 200 Turkish liras. | 53 | | [50, 50, 100, 100, 200] | NO | Yiğit will not have the right bills to give 150 Turkish liras of change (you can't make two bills of 50 from one of 100) | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Spring22/python2022spring22/week12/Solutions.md: -------------------------------------------------------------------------------- 1 | ## Question 1 - Distinctness 2 | ```python 3 | def is_distinct(string): 4 | print(set(string)) 5 | return len(set(string)) == len(string) 6 | 7 | print(is_distinct('slay')) 8 | ``` 9 | 10 | ## Question 2 - Seperating the Types 11 | ```python 12 | the_list= ["music",13,True, "black", (26,1),"16", "False","pencil"] 13 | the_dictionary= {} 14 | 15 | for item in the_list: 16 | if type(item) not in the_dictionary: 17 | the_dictionary[type(item)]=[item] 18 | else: 19 | the_dictionary[type(item)].append(item) 20 | 21 | for item_type, item_list in the_dictionary.items(): 22 | print(item_type, '->',item_list) 23 | 24 | ``` 25 | 26 | ## Question 3 - imdB 27 | ```python 28 | lines = [] 29 | line = str(input()) 30 | while line != "exit": 31 | lines.append(line) 32 | line = str(input()) 33 | 34 | my_dict = {} 35 | for line in lines: 36 | line = line.split(",") 37 | info = {'genre' : line[1], 'release_date': line[2], 'director':line[3]} 38 | my_dict[line[0]] = info 39 | print(my_dict) 40 | ``` 41 | 42 | ## Question 4 - String Who Should Not Be Written 43 | ```python 44 | the_tuple=("TOM MARVOLO RIDDLE","I AM LORD VOLDEMORT") 45 | 46 | def freq(word): 47 | freq_dict = {} 48 | for char in word: 49 | if char != (" ") : 50 | freq_dict[char] = freq_dict.get(char, 0) + 1 51 | return freq_dict 52 | 53 | if (freq(the_tuple[0])) == (freq(the_tuple[1])): 54 | print ("Anagram") 55 | else: 56 | print("Not an anagram") 57 | ``` 58 | 59 | ## Question 5 - Cooking Oil Lines 60 | ``` python 61 | def cashier(people): 62 | change = {50: 0, 100: 0, 200: 0} 63 | for money in people: 64 | if money == 50: 65 | change[50] += 1 66 | elif money == 100: 67 | change[50] -= 1 68 | change[100] += 1 69 | elif money == 200 and change[100] > 0: 70 | change[50] -= 1 71 | change[100] -= 1 72 | elif money==200 and change[100] == 0: 73 | change[50] -= 3 74 | 75 | if change[100] < 0 or change[50] < 0: 76 | return 'NO' 77 | return 'YES' 78 | 79 | print(cashier([50, 50, 100])) 80 | print(cashier([50, 200])) 81 | print(cashier([50, 50, 100, 100, 200])) 82 | ``` 83 | -------------------------------------------------------------------------------- /Spring22/python2022spring22/week12/ps8 chapter dict week12.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week12/ps8 chapter dict week12.pptx -------------------------------------------------------------------------------- /Spring22/python2022spring22/week4/lab3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week4/lab3.pdf -------------------------------------------------------------------------------- /Spring22/python2022spring22/week6/chapter4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week6/chapter4.pdf -------------------------------------------------------------------------------- /Spring22/python2022spring22/week7/cmpe150-chp4-p2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week7/cmpe150-chp4-p2.pptx -------------------------------------------------------------------------------- /Spring22/python2022spring22/week9/Solutions.md: -------------------------------------------------------------------------------- 1 | # Strings 2 | 3 | ## Question 1 - Voweeels 4 | 5 | ```python 6 | def vowel(s): 7 | max_length, length = 0, 0 8 | for c in s: 9 | if c in 'oeaiu': 10 | length += 1 11 | else: 12 | length = 0 13 | max_length = max(length, max_length) 14 | return max_length 15 | 16 | print(vowel("happy beaar")) 17 | print(vowel("how you doin?")) 18 | print(vowel("aiaiai")) 19 | print(vowel("try")) 20 | ``` 21 | 22 | 23 | ## Question 2 - Palindrome 24 | 25 | ```python 26 | def is_palindrome(str): 27 | return str == str[::-1] 28 | ``` 29 | 30 | ## Question 3 - Abbreviate 31 | 32 | ```python 33 | def abbreviation(st): 34 | if (len(st) <= 14): 35 | return st 36 | else: 37 | return st[0:2] + str(len(st) - 4) + st[-2:] 38 | ``` 39 | 40 | ## Question 4 - Lower/Upper Counts 41 | 42 | ```python 43 | str = "HeLLo WoRLD" 44 | lower_count, upper_count = 0, 0 45 | for c in str: 46 | lower_count += c.islower() 47 | upper_count += c.isupper() 48 | 49 | print(upper_count, lower_count) 50 | ``` 51 | 52 | ## Question 5 - Requirements 53 | 54 | ```python 55 | def is_valid(password): 56 | length = len(password) 57 | if length < 6 or length > 20: 58 | return False 59 | lower, upper, digit = 0, 0, 0 60 | for c in password: 61 | lower += c.islower() 62 | upper += c.isupper() 63 | digit += c.isdigit() 64 | return lower >= 1 and upper >= 1 and digit >= 1 65 | 66 | print(is_valid("Covid19")) 67 | ``` 68 | 69 | ## Question 6 - Length 70 | 71 | ```python 72 | sentence = input() 73 | words = sentence.split() 74 | lengths = [len(w) for w in words] 75 | shortest_index = lengths.index(min(lengths)) 76 | longest_index = lengths.index(max(lengths)) 77 | print(words[shortest_index], words[longest_index]) 78 | ``` 79 | 80 | ## Question 7 - Word Cases 81 | 82 | ```python 83 | def modify(str): 84 | words = str.split() 85 | new_str = '' 86 | for ix, word in enumerate(words): 87 | if ix % 2 == 0: 88 | new_str += word.upper() + ' ' 89 | else: 90 | new_str += word.lower() + ' ' 91 | return new_str 92 | 93 | def modify2(str): 94 | return ' '.join([word.upper() if ix % 2 == 0 else word.lower() for ix, word in enumerate(str.split())]) 95 | 96 | print(modify('stop making sponge bob memes')) 97 | print(modify2('stop making sponge bob memes')) 98 | 99 | ``` 100 | 101 | 102 | ## Question 8 - Second Most Common 103 | ```python 104 | string = str(input()) 105 | modified = string.replace(" ", "").lower() 106 | Max = 0 107 | secondMax = 0 108 | second = '' 109 | first = '' 110 | for i in modified: 111 | occur = modified.count(i) 112 | if(occur > Max): 113 | second = first 114 | first = i 115 | secondMax = Max 116 | Max = occur 117 | elif(occur < Max and occur > secondMax): 118 | second = i 119 | secondMax = occur 120 | print(first, second) 121 | ``` 122 | 123 | ## Question 9 - Not poor 124 | ```python 125 | def not_poor(str1): 126 | snot = str1.find('not') 127 | spoor = str1.find('poor') 128 | if spoor > snot and snot > 0 and spoor > 0: 129 | str1 = str1.replace(str1[snot:(spoor+4)], 'good') 130 | return str1 131 | print(not_poor('The lyrics is not that poor!')) 132 | print(not_poor('The lyrics is poor!')) 133 | ``` 134 | 135 | ## Question 10 - Find and replace 136 | 137 | ```python 138 | 139 | def find_and_replace(string, a, b): 140 | ix = 0 141 | while string.find(a, ix) != -1: 142 | ix = string.find(a, ix) 143 | string = string[:ix] + b + string[ix+len(a):] 144 | ix = ix + len(b) 145 | return string 146 | 147 | 148 | print(find_and_replace("This is another test", "is", "is not")) 149 | print(find_and_replace("I mean, it went badly last time but surely it will go much better this time.", "it", "filling zeppelins with hydrogen")) 150 | print(find_and_replace("Test test TeSt te st TEst teSt crest TEA", "st TE", "test")) 151 | ``` 152 | 153 | -------------------------------------------------------------------------------- /Spring22/python2022spring22/week9/string.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/Spring22/python2022spring22/week9/string.pptx -------------------------------------------------------------------------------- /figures/1616341138563.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/1616341138563.png -------------------------------------------------------------------------------- /figures/1616342184949.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/1616342184949.png -------------------------------------------------------------------------------- /figures/1616342517499.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/1616342517499.png -------------------------------------------------------------------------------- /figures/ChangeTheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/ChangeTheme.png -------------------------------------------------------------------------------- /figures/HTML_Browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/HTML_Browser.png -------------------------------------------------------------------------------- /figures/HTML_Explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/HTML_Explorer.png -------------------------------------------------------------------------------- /figures/Maintxt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/Maintxt.png -------------------------------------------------------------------------------- /figures/TC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/TC.png -------------------------------------------------------------------------------- /figures/Teaching.Codes New Version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/Teaching.Codes New Version.png -------------------------------------------------------------------------------- /figures/Teaching.Codes Uninstall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/Teaching.Codes Uninstall.png -------------------------------------------------------------------------------- /figures/Teaching.Codes Version 1212JB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/Teaching.Codes Version 1212JB.png -------------------------------------------------------------------------------- /figures/commit_and_push_failed1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/commit_and_push_failed1.png -------------------------------------------------------------------------------- /figures/commit_and_push_failed2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/commit_and_push_failed2.png -------------------------------------------------------------------------------- /figures/connection.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/connection.PNG -------------------------------------------------------------------------------- /figures/correspondence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/correspondence.png -------------------------------------------------------------------------------- /figures/could not open.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/could not open.PNG -------------------------------------------------------------------------------- /figures/project-guide/1618485979513.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618485979513.png -------------------------------------------------------------------------------- /figures/project-guide/1618486104949.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618486104949.png -------------------------------------------------------------------------------- /figures/project-guide/1618486398394.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618486398394.png -------------------------------------------------------------------------------- /figures/project-guide/1618486497781.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618486497781.png -------------------------------------------------------------------------------- /figures/project-guide/1618486752521.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618486752521.png -------------------------------------------------------------------------------- /figures/project-guide/1618486890025.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618486890025.png -------------------------------------------------------------------------------- /figures/project-guide/1618487070207.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487070207.png -------------------------------------------------------------------------------- /figures/project-guide/1618487098652.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487098652.png -------------------------------------------------------------------------------- /figures/project-guide/1618487165943.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487165943.png -------------------------------------------------------------------------------- /figures/project-guide/1618487273664.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487273664.png -------------------------------------------------------------------------------- /figures/project-guide/1618487440503.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487440503.png -------------------------------------------------------------------------------- /figures/project-guide/1618487934948.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/project-guide/1618487934948.png -------------------------------------------------------------------------------- /figures/python-customize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/python-customize.png -------------------------------------------------------------------------------- /figures/python-final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/python-final.png -------------------------------------------------------------------------------- /figures/python-optional.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bouncmpe150/python-notes/f731d6c1d4ef524fcf7eca73fd989da9a31638ff/figures/python-optional.png --------------------------------------------------------------------------------