# Some more list manipulation my_list = ['apple', 'banana', 'guava', 'pineapple'] print my_list print "second element is", my_list[2] print "The length of the list is", len(my_list) del my_list[2] print "The new list is", my_list position = my_list.index('pineapple') print "Position of pineapple is", position del my_list[position] print "List after removing pineapple", my_list print "The length of the list is", len(my_list) my_list.append('pomegranate') print my_list # while loops C = -50 dC = 2 C_max = 60 print "Celsius\tFahrenheit" while C <= 60 : F = 9.0/5.0 * C + 32 # print C,"\t",F C += dC print "____________________________________________________________" # Computing the exponential function from math import factorial # Want to compute my_exp(x) x = input("x = ") x = float(x) N = input("No of terms to be computed : ") k = 0 val_exp = 0 while k <= N : val_term = x**k / factorial(k) val_exp += val_term k += 1 print "exp(%g) = %10.5F (approximated to %d terms)" % (x, val_exp, N) # Boolean values def truefalse(expr) : if expr : print "True" else : print "False" print True, truefalse(True) print False, truefalse(False) print 4, truefalse(4) print 0, truefalse(0) print 3.0, truefalse(3.0) print "ab", truefalse("ab") print "", truefalse("") x = 10 y = 5 print "x < 10 and y > 3", truefalse(x < 10 and y > 3) print "x == 10 and y > 3", truefalse(x == 10 and y > 3) print "x != 11 and y > 3", truefalse(x == 10 and y > 3) print "not x == 11 and y > 3", truefalse(x == 11 and y > 3) print "not (x == 11 and y > 3)", truefalse(not (x == 11 and y > 3)) print "x == 10 or y == 10", truefalse(x == 10 or y == 10)