Category Archives: Python

Using Dictionary Python

”’ Created on Aug 11, 2017 @author: asharda ”’ legs={“human”:2,”cats”:4} for leg in legs: num=legs[leg] print(‘A %s has %d legs’ %(leg,num))

Posted in Python | Leave a comment

Probability Python

from random import choice destinations=[“Agra”,”Mumbai”,”New York”,”San Francisco”] print(choice(destinations))

Posted in Python, Uncategorized | Leave a comment

Basic Operations using Numpy

import numpy as np a=np.array([1,2,3]) print(a.shape) print(a.dtype) b=np.zeros((2,2)) print(b) c=np.ones((1,1)) print(c) d=np.eye(2) print(d) e=np.random.random((3,3,3)) print(e)

Posted in Python, Uncategorized | Leave a comment

Print Numbers between 5 and 50 in intervals of 2

import numpy as np print np.arange(5,50,2)

Posted in Python, Uncategorized | Leave a comment

In in Python

”’ Created on Jul 9, 2017 @author: asharda ”’ miles=11 milestone=[1,2,3,4,5,6,7,8,9,10] if miles in milestone: print(“Miles is there in milestone”) else: print(“Miles is not there in milestone”)

Posted in Python, Uncategorized | Leave a comment

Celsius to Fahrenheit Python

”’ Created on Jul 7, 2017 @author: asharda ”’ import numpy as np cvalues=[22,18,23,30] C=np.array(cvalues) F=C*1.8+32 print F

Posted in Python, Uncategorized | Leave a comment

Binary Search Python

”’ Created on Jul 2, 2017 @author: asharda ”’ arr=[1,2,4,8,12] def bSearch(arr,target): low=0 high=len(arr)-1 while(low<=high): mid=low+high/2 if(target==arr[mid]): return True elif(target>arr[mid]): low=low+1 elif(target<arr[mid]): high=high-1 return False b=bSearch(arr, 3) if(b==True): print(“Number Found”) else: print(“Number not Found”)

Posted in Python, Uncategorized | Leave a comment