{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"> # **Welcome!**\n\n> **I have created 22 simple python program that may be useful for you, if there that I have a mistake in my code, please give me a feedback, so I can fix it asap, thanks in advance!**","metadata":{}},{"cell_type":"markdown","source":"> # **1. BMI Converter**","metadata":{}},{"cell_type":"code","source":"weight = int(input('Weight: ')) # Kg\nheight = float(input('Height: ')) # Cm\n\nbmi = (weight / height) ** 2\n\nif bmi < 18.5:\n    print(\"Underweight\")\nelif bmi >= 18.5 and bmi <= 25:\n    print(\"Normal\")\nelif bmi >= 25 and bmi <= 30:\n    print(\"Overweight\")\nelse:\n    print(\"Obesity\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-04T17:22:13.295080Z","iopub.execute_input":"2021-12-04T17:22:13.295468Z","iopub.status.idle":"2021-12-04T17:22:21.906017Z","shell.execute_reply.started":"2021-12-04T17:22:13.295382Z","shell.execute_reply":"2021-12-04T17:22:21.904967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **2. Data Entry**","metadata":{}},{"cell_type":"code","source":"many_data = int(input('How Many Data? '))\n\nscore_with_name = {}\n\nfor i in range(many_data):\n    input_name = input('Name: ')\n    input_score = int(input('Score: '))\n\n    score_with_name[input_score] = score_with_name.get(input_score, []) + [input_name]\n\nscore_sorted = sorted(list(score_with_name.keys()))\n\nlow_score, high_score = score_sorted[0], score_sorted[-1]\n\nprint(f'\\nThe name with the high score: {score_with_name[high_score]}, the score is {high_score}\\n')\n\nprint(f'The name with the low score: {score_with_name[low_score]}, the score is {low_score}\\n')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:22:36.484025Z","iopub.execute_input":"2021-12-04T17:22:36.484355Z","iopub.status.idle":"2021-12-04T17:22:53.653877Z","shell.execute_reply.started":"2021-12-04T17:22:36.484324Z","shell.execute_reply":"2021-12-04T17:22:53.653113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **3. Convert Number into Text**","metadata":{}},{"cell_type":"code","source":"phone = input(\"Phone : \")\n\nnum = {\n    \"0\": \"Zero\",\n    \"1\": \"One\",\n    \"2\": \"Two\",\n    \"3\": \"Three\",\n    \"4\": \"Four\",\n    \"5\": \"Five\",\n    \"6\": \"Six\",\n    \"7\": \"Seven\",\n    \"8\": \"Eight\",\n    \"9\": \"Nine\"\n}\n\noutput = \"\"\n\nfor ch in phone:\n\toutput += num.get(ch) + \" \"\n\nprint(output)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:22:53.655068Z","iopub.execute_input":"2021-12-04T17:22:53.655497Z","iopub.status.idle":"2021-12-04T17:23:00.458744Z","shell.execute_reply.started":"2021-12-04T17:22:53.655467Z","shell.execute_reply":"2021-12-04T17:23:00.457750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **4. Stack**","metadata":{}},{"cell_type":"code","source":"# Stack Wrapper Class\n\nclass Stack(): # LIFO = last in first out\n    def __init__(self): \n        self.stack = list()\n\n    def push(self, item): # Push an item onto the stack\n        self.stack.append(item)\n\n    def pop(self): # Pop an item off of the stack\n        if len(self.stack) > 0:\n            return self.stack.pop()\n        else:\n            return None\n\n    def peek(self): # get an item on top of stack, without removing it\n        if len(self.stack) > 0:\n            return self.stack[len(self.stack)-1]\n        else:\n            return None\n\n    def __str__(self): # magic funct that for changing the bool to str\n        return str(self.stack)\n\nmystack = Stack()\nmystack.push(4)\nmystack.push(5)\nmystack.push(6)\nmystack.pop()\nprint(mystack)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:23:00.460316Z","iopub.execute_input":"2021-12-04T17:23:00.460593Z","iopub.status.idle":"2021-12-04T17:23:00.468209Z","shell.execute_reply.started":"2021-12-04T17:23:00.460565Z","shell.execute_reply":"2021-12-04T17:23:00.467448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **5. Perimeter and Square Area**","metadata":{}},{"cell_type":"code","source":"def perimeter_square_area(width, length):\n    around = 2 * (width + length)\n    large = (width * length)\n    return around, large\n\ncircumference_result, broad_result = perimeter_square_area(10, 20)\nprint(f'Circumference result: {circumference_result}, Broad Result: {broad_result}')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:23:00.469558Z","iopub.execute_input":"2021-12-04T17:23:00.470050Z","iopub.status.idle":"2021-12-04T17:23:00.484400Z","shell.execute_reply.started":"2021-12-04T17:23:00.470018Z","shell.execute_reply":"2021-12-04T17:23:00.483564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **6. Weight Converter**","metadata":{}},{"cell_type":"code","source":"weight = int(input(\"Weight : \"))\nunit = input(\"(L)bs or (K)g : \")\n\nif unit.upper() == \"L\":\n    converted = weight * 0.45\n    print(f\"You are {converted}\")\nelse:\n    converted = weight / 0.45\n    print(f\"You are {converted}\")","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:23:00.485657Z","iopub.execute_input":"2021-12-04T17:23:00.486237Z","iopub.status.idle":"2021-12-04T17:23:13.531351Z","shell.execute_reply.started":"2021-12-04T17:23:00.486194Z","shell.execute_reply":"2021-12-04T17:23:13.530371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **7. Dice Roll**","metadata":{}},{"cell_type":"code","source":"import random\n\nclass Dice:\n    def roll(self):\n        first = random.randint(1, 6)\n        second = random.randint(1, 6)\n        return first, second\n\ndice = Dice()\nprint(dice.roll())","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:23:13.532402Z","iopub.execute_input":"2021-12-04T17:23:13.532662Z","iopub.status.idle":"2021-12-04T17:23:13.538972Z","shell.execute_reply.started":"2021-12-04T17:23:13.532636Z","shell.execute_reply":"2021-12-04T17:23:13.537956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **8. Madlibs**","metadata":{}},{"cell_type":"code","source":"color = input(\"Enter a color : \") \nplural_noun = input(\"Enter a plural noun : \") \nverb = input(\"Enter a verb : \") \nadjective = input(\"Enter a adjective : \") \n\nprint(\"-\" * 10) \n\nprint(\"roses are \" + color) \nprint(plural_noun + \" are blue\") \nprint(\"when the chicken goes \" + verb) \nprint(\"your grandma is \" + adjective) ","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:23:13.540466Z","iopub.execute_input":"2021-12-04T17:23:13.541084Z","iopub.status.idle":"2021-12-04T17:24:22.172400Z","shell.execute_reply.started":"2021-12-04T17:23:13.541039Z","shell.execute_reply":"2021-12-04T17:24:22.171354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **9. Calculator**","metadata":{}},{"cell_type":"code","source":"def number():\n    print(\"\")\n    num1 = float(input(\"Enter first number : \"))\n    op = input(\"Enter operator : \")\n    num2 = float(input(\"Enter second number : \"))\n\n    if op == \"+\":\n        print(\"\")\n        print(num1 + num2)\n    elif op == \"-\":\n        print(\"\")\n        print(num1 - num2)\n    elif op == \"/\":\n        print(\"\")\n        print(num1 / num2)\n    elif op == \"*\":\n        print(\"\")\n        print(num1 * num2)\n    else:\n        print(\"\")\n        print(\"Invalid operator\")\n\n\nif __name__ == '__main__':\n    number()","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:22.173694Z","iopub.execute_input":"2021-12-04T17:24:22.174079Z","iopub.status.idle":"2021-12-04T17:24:30.019032Z","shell.execute_reply.started":"2021-12-04T17:24:22.174048Z","shell.execute_reply":"2021-12-04T17:24:30.017888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **10. Guessing Games**","metadata":{}},{"cell_type":"code","source":"secret_word = \"you\"\nguess = \"\"\nguess_count = 0\nguess_limit = 3\nout_of_guess = False\n\nwhile guess != secret_word and not(out_of_guess):\n    if guess_count < guess_limit:\n        guess = input(\"Enter guess : \").lower()\n        guess_count += 1\n    else:\n        out_of_guess = True\n\nif out_of_guess:\n    print(\"Out of guesses, YOU LOSE!\")\nelse:\n    print(\"YOU WIN!\")","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:30.021221Z","iopub.execute_input":"2021-12-04T17:24:30.021510Z","iopub.status.idle":"2021-12-04T17:24:38.613152Z","shell.execute_reply.started":"2021-12-04T17:24:30.021481Z","shell.execute_reply":"2021-12-04T17:24:38.612415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **11. Finding the Large Number**","metadata":{}},{"cell_type":"code","source":"larger_so_far = -1\nprint('Before', larger_so_far)\n\nfor value_large in [9, 41, 13, 3, 74, 15]:\n    if value_large > larger_so_far:\n        larger_so_far = value_large\n    print(larger_so_far, value_large)\n\nprint('Larger so far ', larger_so_far)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:38.614454Z","iopub.execute_input":"2021-12-04T17:24:38.614849Z","iopub.status.idle":"2021-12-04T17:24:38.622620Z","shell.execute_reply.started":"2021-12-04T17:24:38.614803Z","shell.execute_reply":"2021-12-04T17:24:38.621717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **12. Finding the Smallest Number**","metadata":{}},{"cell_type":"code","source":"smallest = None\nprint('Before', smallest)\n\nfor value_small in [9, 41, 13, 3, 74, 15]:\n    if smallest is None:\n        smallest = value_small\n    elif value_small < smallest:\n        smallest = value_small\n    print(smallest, value_small)\n    \nprint('After', smallest)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:38.623984Z","iopub.execute_input":"2021-12-04T17:24:38.624461Z","iopub.status.idle":"2021-12-04T17:24:38.637806Z","shell.execute_reply.started":"2021-12-04T17:24:38.624432Z","shell.execute_reply":"2021-12-04T17:24:38.637078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **13. Counting a Number**","metadata":{}},{"cell_type":"code","source":"total = count = average = 0\n\nwhile True:\n    num_input = input('Enter a number: ')\n    if num_input == 'done':\n        print(f'Total: {total}, Count: {count}, Average: {average}')\n        break\n    try:\n        count += int(num_input)\n        total += 1\n        average = total/count\n    except ValueError:\n        print('Invalid input')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:38.638936Z","iopub.execute_input":"2021-12-04T17:24:38.639357Z","iopub.status.idle":"2021-12-04T17:24:48.225866Z","shell.execute_reply.started":"2021-12-04T17:24:38.639315Z","shell.execute_reply":"2021-12-04T17:24:48.225121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **14. Looping Through Strings**","metadata":{}},{"cell_type":"code","source":"fruit, index = 'banana', 0\n\nwhile index < len(fruit):\n    letter = fruit[index]\n    print(f'index: {index}, letter: {letter}\\n')\n    index += 1\n\n# Prettier way\nfor letter in fruit:\n    print(f'prettier: {letter}\\n')\n\n# Loop and counting\nword, count = 'banana', 0\n\nfor letter in word:\n    if letter == 'a':\n        count += 1\nprint(f'loops: {count}\\n')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:48.226750Z","iopub.execute_input":"2021-12-04T17:24:48.227193Z","iopub.status.idle":"2021-12-04T17:24:48.234577Z","shell.execute_reply.started":"2021-12-04T17:24:48.227162Z","shell.execute_reply":"2021-12-04T17:24:48.233746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **15. Change the String into Float**","metadata":{}},{"cell_type":"code","source":"str = 'X-DSPAM-Confidence: 0.8475'\npos = str.find(' ')\nvalue = float(str[pos:])\nprint(value)\nprint(type(value))","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:48.235604Z","iopub.execute_input":"2021-12-04T17:24:48.235911Z","iopub.status.idle":"2021-12-04T17:24:48.251466Z","shell.execute_reply.started":"2021-12-04T17:24:48.235880Z","shell.execute_reply":"2021-12-04T17:24:48.250773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **16. Determine the Number is a Factor or Not**","metadata":{}},{"cell_type":"code","source":"n = int(input('Input Number: '))\n\nfor i in range(1, n+1):\n    if (n % i == 0):\n        print(i, 'is factor from ',n)\n    else:\n        print(i, 'is not a factor from ',n)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:48.252886Z","iopub.execute_input":"2021-12-04T17:24:48.253528Z","iopub.status.idle":"2021-12-04T17:24:51.909579Z","shell.execute_reply.started":"2021-12-04T17:24:48.253485Z","shell.execute_reply":"2021-12-04T17:24:51.908610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **17. Determine Odd or Even Numbers**","metadata":{}},{"cell_type":"code","source":"n = int(input('Input Number: '))\n\nfor i in range(0, n+1):\n    if (i % 2):\n        print(i, \"is an even number of \", n)\n    else:\n        print(i, \"is an odd number of\", n)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:51.910915Z","iopub.execute_input":"2021-12-04T17:24:51.911195Z","iopub.status.idle":"2021-12-04T17:24:54.809455Z","shell.execute_reply.started":"2021-12-04T17:24:51.911168Z","shell.execute_reply":"2021-12-04T17:24:54.808840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **18. Functions and Procedures**","metadata":{}},{"cell_type":"markdown","source":"> ### **1. Step Function**","metadata":{}},{"cell_type":"code","source":"def step(x):\n    tmp = 0\n    if x >= 0:\n        tmp = 1\n    return tmp\n\nstep(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:54.810329Z","iopub.execute_input":"2021-12-04T17:24:54.810691Z","iopub.status.idle":"2021-12-04T17:24:54.817538Z","shell.execute_reply.started":"2021-12-04T17:24:54.810664Z","shell.execute_reply":"2021-12-04T17:24:54.816895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### **2. RelU Function**","metadata":{}},{"cell_type":"code","source":"def relu(x):\n    tmp = 0\n    if x > 0:\n        tmp = x\n    return tmp\n\nrelu(10)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:54.818601Z","iopub.execute_input":"2021-12-04T17:24:54.819051Z","iopub.status.idle":"2021-12-04T17:24:54.834286Z","shell.execute_reply.started":"2021-12-04T17:24:54.819021Z","shell.execute_reply":"2021-12-04T17:24:54.833264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### **3. Procedure**","metadata":{}},{"cell_type":"code","source":"def plus(x, y):\n    print(x + y)\n    \nplus(10, 20)","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:54.835401Z","iopub.execute_input":"2021-12-04T17:24:54.835843Z","iopub.status.idle":"2021-12-04T17:24:54.842995Z","shell.execute_reply.started":"2021-12-04T17:24:54.835790Z","shell.execute_reply":"2021-12-04T17:24:54.842181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **19. Binary Search**","metadata":{}},{"cell_type":"code","source":"def binary_search(list, item):\n    low = 0\n    high = len(list)-1\n    \n    while low <= high:\n        mid = (low + high) // 2\n        guess = list[mid]\n        if guess == item:\n            return mid\n        if guess > item:\n            high = mid - 1\n        else:\n            low = mid + 1\n    return None\n\nmylist = [1, 3, 5, 7, 9]\nprint(f'the number is in index: {binary_search(mylist, 7)}')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:54.843961Z","iopub.execute_input":"2021-12-04T17:24:54.844375Z","iopub.status.idle":"2021-12-04T17:24:54.854089Z","shell.execute_reply.started":"2021-12-04T17:24:54.844344Z","shell.execute_reply":"2021-12-04T17:24:54.853312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **20. Longest Word Search Program**","metadata":{}},{"cell_type":"code","source":"n = input('')\n\nlist_word = n.split(' ')\n\nlongest_word = list_word[0]\n\nfor word in list_word[0:]:\n    if len(word) > len(longest_word):\n        longest_word = word\n\nprint(f'longest word: {longest_word}')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:24:54.855108Z","iopub.execute_input":"2021-12-04T17:24:54.855518Z","iopub.status.idle":"2021-12-04T17:25:04.399220Z","shell.execute_reply.started":"2021-12-04T17:24:54.855490Z","shell.execute_reply":"2021-12-04T17:25:04.398427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> # **21. Sorted Word From The Last Names**","metadata":{}},{"cell_type":"code","source":"student = ['Guido Van Rossum', 'Steve Jobs', 'Elon Musk', 'Bill Gates']","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:25:04.400457Z","iopub.execute_input":"2021-12-04T17:25:04.400981Z","iopub.status.idle":"2021-12-04T17:25:04.404449Z","shell.execute_reply.started":"2021-12-04T17:25:04.400948Z","shell.execute_reply":"2021-12-04T17:25:04.403756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### **Step 1**","metadata":{}},{"cell_type":"code","source":"for i in range(len(student)-1):\n    for j in range(i+1, len(student)):\n        if student[i].split()[-1] > student[j].split()[-1]:\n            student[i], student[j] = student[j], student[i]\n            \nprint(f'sorted: {student}')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:25:04.405640Z","iopub.execute_input":"2021-12-04T17:25:04.406064Z","iopub.status.idle":"2021-12-04T17:25:04.421925Z","shell.execute_reply.started":"2021-12-04T17:25:04.406024Z","shell.execute_reply":"2021-12-04T17:25:04.420837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### **Step 2**","metadata":{}},{"cell_type":"code","source":"sorted_student = sorted(student, key=lambda x: x.split()[-1])\n\nprint(f'sorted: {student}')","metadata":{"execution":{"iopub.status.busy":"2021-12-04T17:25:04.423305Z","iopub.execute_input":"2021-12-04T17:25:04.423875Z","iopub.status.idle":"2021-12-04T17:25:04.435982Z","shell.execute_reply.started":"2021-12-04T17:25:04.423828Z","shell.execute_reply":"2021-12-04T17:25:04.434895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ## **That's it, I'll add more simple python program asap, don't forget to give me an upvote if you like it!**","metadata":{}}]}