From e8b016e8374e8242804d304c046dcc13233fef7c Mon Sep 17 00:00:00 2001 From: nakshatra2003 <99409336+nakshatra2003@users.noreply.github.com> Date: Thu, 10 Feb 2022 19:43:42 +0530 Subject: [PATCH 1/2] Created using Colaboratory --- PythonMOL.ipynb | 431 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 431 insertions(+) create mode 100644 PythonMOL.ipynb diff --git a/PythonMOL.ipynb b/PythonMOL.ipynb new file mode 100644 index 0000000..d690098 --- /dev/null +++ b/PythonMOL.ipynb @@ -0,0 +1,431 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "PythonMOL.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyN+diYwhI2xvZOMH07IUfV/", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "source": [ + "!pip install numpy" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wxS3dPX9tCMi", + "outputId": "1d389864-0e13-4ce5-e242-d597e7d67c8c" + }, + "execution_count": 48, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (1.19.5)\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import numpy as np" + ], + "metadata": { + "id": "KDIyjXsNtRvF" + }, + "execution_count": 49, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def power(a,b):\n", + " return a**b" + ], + "metadata": { + "id": "lQSD13LX8V1j" + }, + "execution_count": 112, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def split_str(s):\n", + " return s.split()" + ], + "metadata": { + "id": "UUyJ5m0v8YC8" + }, + "execution_count": 113, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def format(planet,diameter):\n", + " planet=\"Earth\" \n", + " diameter=12742\n", + "\n", + "# print(\"The diameter of {} is {} kilometers.\".format(planet,diameter))\n", + " return ('The diameter of {} is {} kilometers.'.format(planet,diameter))" + ], + "metadata": { + "id": "cthtkBp0iAHh" + }, + "execution_count": 11, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def indexing(lst):\n", + " \n", + "# ** Given this nested list, use indexing to grab the word \"hello\" **\n", + "\n", + " lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7]\n", + " return lst[3][1][2][0]" + ], + "metadata": { + "id": "O1qvEbFbCL8f" + }, + "execution_count": 114, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def dictionary(d):\n", + " \n", + "# ** Given this nested dictionary grab the word \"hello\". Be prepared, this will be annoying/tricky **\n", + " d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}\n", + "\n", + "\n", + " return d['k1'][3]['tricky'][3]['target'][3]" + ], + "metadata": { + "id": "Mrf5tcyLD-T7" + }, + "execution_count": 115, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def subjective():\n", + " \n", + "# ** What is the main difference between a tuple and a list? **\n", + "# Tuple is ________\n", + "\n", + " return \"immutable\"" + ], + "metadata": { + "id": "rnMcAzjkE16j" + }, + "execution_count": 116, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def domainGet(email):\n", + " \n", + " # ** Create a function that grabs the email website domain from a string in the form:nakshatra **\n", + "# \n", + "# user@domain.com\n", + "# \n", + "# **So for example, passing \"user@domain.com\" would return: domain.com**\n", + " s=email.split('@')[1]\n", + " return s" + ], + "metadata": { + "id": "zxmM0g9tFFYP" + }, + "execution_count": 14, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def findDog(st):\n", + " \n", + "# ** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. **\n", + " s=set(st.split())\n", + "# print(s)\n", + " for item in s:\n", + "# print(item)\n", + " if(item==\"dog\"):\n", + " return True" + ], + "metadata": { + "id": "vFQ_0r7KmM_R" + }, + "execution_count": 39, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def countDog(st):\n", + " i=0\n", + "# ** Create a function that counts the number of times the word \"dog\" occurs in a string. Again ignore edge cases. **\n", + " p=st.split()\n", + " for item in p:\n", + " if(item==\"dog\"):\n", + " i=i+1\n", + " return i" + ], + "metadata": { + "id": "-O-kWNvOqqH5" + }, + "execution_count": 46, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def lambdafunc(seq):\n", + " \n", + " # ** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:**\n", + "# \n", + "# seq = ['soup','dog','salad','cat','great']\n", + "# \n", + "# **should be filtered down to:**\n", + "# \n", + "# ['soup','salad']\n", + "\n", + " return list(filter(lambda item: item[0]==\"s\",seq))" + ], + "metadata": { + "id": "gCnvuTwD1yEe" + }, + "execution_count": 50, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "\n", + "def caught_speeding(speed, is_birthday):\n", + " \n", + " \n", + "# **You are driving a little too fast, and a police officer stops you. Write a function\n", + "# to return one of 3 possible results: \"No ticket\", \"Small ticket\", or \"Big Ticket\". \n", + "# If your speed is 60 or less, the result is \"No Ticket\". If speed is between 61 \n", + "# and 80 inclusive, the result is \"Small Ticket\". If speed is 81 or more, the result is \"Big Ticket\". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all \n", + "# cases. **\n", + " if(speed<61 or (speed<66 and is_birthday)):\n", + " return \"No Ticket\"\n", + " elif((speed>60 and speed<81) or (speed<86 and is_birthday)):\n", + " return \"Small Ticket\"\n", + " else:\n", + " return \"Big Ticket\"" + ], + "metadata": { + "id": "ogN4h8N-3L4j" + }, + "execution_count": 53, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def create_arr_of_fives():\n", + " \n", + " #### Create an array of 10 fives\n", + " #### Convert your output into list \n", + " #### e.g return list(arr)\n", + " arr = np.ones(10)\n", + " for i in range(10):\n", + " arr[i]= 5*arr[i]\n", + " return list(arr)" + ], + "metadata": { + "id": "4H6N77Av-Kfj" + }, + "execution_count": 68, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def even_num():\n", + " \n", + " ### Create an array of all the even integers from 10 to 50\n", + " ### Convert your output into list \n", + " ### e.g return list(arr) \n", + " arr=np.arange(10,51,2)\n", + "\n", + " return (list(arr))" + ], + "metadata": { + "id": "h6xOs4phYmfy" + }, + "execution_count": 78, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def create_matrix():\n", + " \n", + " ### Create a 3x3 matrix with values ranging from 0 to 8\n", + " ### Convert your output into list \n", + " ### e.g return (arr).tolist()\n", + " arr=(np.arange(0,9)).reshape(3,3)\n", + "\n", + " return (arr).tolist()" + ], + "metadata": { + "id": "LyPQ1xK0baau" + }, + "execution_count": 84, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def linear_space():\n", + " \n", + " ### Create an array of 20 linearly spaced points between 0 and 1\n", + " ### Convert your output into list \n", + " ### e.g return list(arr) \n", + " arr = np.linspace(0,1,20)\n", + " return list(arr)" + ], + "metadata": { + "id": "HJcMJDMbc85Q" + }, + "execution_count": 90, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def decimal_mat():\n", + " \n", + " ### Create an array of size 10*10 consisting of numbers from 0.01 to 1\n", + " ### Convert your output into list \n", + " ### e.g return (arr).tolist()\n", + " arr = np.linspace(0.01,1,100)\n", + " arr = arr.reshape(10,10)\n", + " return (arr).tolist()" + ], + "metadata": { + "id": "HzUd8b19hdaB" + }, + "execution_count": 97, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def slices_1():\n", + " \n", + " # This is a given array\n", + " arr = np.arange(1,26).reshape(5,5)\n", + " # array([[ 1, 2, 3, 4, 5],\n", + " # [ 6, 7, 8, 9, 10],\n", + " # [11, 12, 13, 14, 15],\n", + " # [16, 17, 18, 19, 20],\n", + " # [21, 22, 23, 24, 25]])\n", + "\n", + " # Write a code to slice this given array\n", + " ### Convert your output into list \n", + " ### e.g return (arr).tolist()\n", + " # array([[12, 13, 14, 15],\n", + " # [17, 18, 19, 20],\n", + " # [22, 23, 24, 25]])\n", + "\n", + " return (arr[2:,1:]).tolist()\n", + " " + ], + "metadata": { + "id": "Zor0qrPNi08H" + }, + "execution_count": 106, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def slices_2():\n", + " \n", + " # This is a given array\n", + " arr = np.arange(1,26).reshape(5,5)\n", + " # array([[ 1, 2, 3, 4, 5],\n", + " # [ 6, 7, 8, 9, 10],\n", + " # [11, 12, 13, 14, 15],\n", + " # [16, 17, 18, 19, 20],\n", + " # [21, 22, 23, 24, 25]])\n", + "\n", + " # Write a code to slice this given array\n", + " ### Convert your output into list \n", + " ### e.g return (arr).tolist()\n", + " # array([[ 2],\n", + " # [ 7],\n", + " # [12]])\n", + "\n", + " return (arr[:3,1]).tolist()" + ], + "metadata": { + "id": "a9jKIKc1zsCI" + }, + "execution_count": 104, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "def slices_3():\n", + " \n", + " # This is a given array\n", + " arr = np.arange(1,26).reshape(5,5)\n", + " # array([[ 1, 2, 3, 4, 5],\n", + " # [ 6, 7, 8, 9, 10],\n", + " # [11, 12, 13, 14, 15],\n", + " # [16, 17, 18, 19, 20],\n", + " # [21, 22, 23, 24, 25]])\n", + "\n", + " # Write a code to slice this given array\n", + " ### Convert your output into list \n", + " ### e.g return (arr).tolist()\n", + " # array([[16, 17, 18, 19, 20],\n", + " # [21, 22, 23, 24, 25]])\n", + " \n", + " return (arr[3:,:]).tolist()" + ], + "metadata": { + "id": "P_HCqCYN1vQ9" + }, + "execution_count": 110, + "outputs": [] + } + ] +} \ No newline at end of file From e8ec1b88eb6d0170e3a962f355af8ab708a57883 Mon Sep 17 00:00:00 2001 From: nakshatra2003 <99409336+nakshatra2003@users.noreply.github.com> Date: Thu, 10 Feb 2022 20:21:13 +0530 Subject: [PATCH 2/2] Created using Colaboratory