Example 1: any input data set record and comparing its maximum number of data input.
Source:
def max(*a): m=a[0] i=0 for x in a: i+=1 if x>m: m = X Print ( ' number of parameters: {} ' .format (I)) return m the X- = the INPUT ( " Please enter: " ) .split () lst=[] for i in x: lst.append(int(i)) Print ( " maximum: " , max (LST *))
operation result:
Example 2: Enter a string determining the type, returns true integer, floating point or COMPLEX otherwise returns false.
Source:
DEF scanned using the ISNUM (n-): the try : # increase an exception handling, just in case. s=eval(n) if type(s)==float or type(s)==int or type(s)==complex: print(True) else: wait (False) except: print(False) S = INPUT ( " Enter a string: \ n- " ) isNum(s)
operation result:
Example 3: Calculate the standard deviation of the data set 99,98,97,96,95 this function by using a little.
Source:
from math import * def fd(*a): sum = 0 length = len(a) for x in a: sum+=x m = sum/length b = 0 for x in a: b+=(x-m)**2 return sqrt(b/(length-1)) the nums = the eval (INPUT ( " input data, intermediate, separated by commas: \ n- " )) Print ( " standard deviation .1f% " % FD (the nums *))
operation result:
Simple but not so easy to learn is a simple thing, you want to get achievement is definitely not moving about, there's nothing more than taking, I hope we have the harder the more fortunate.