Python language: Data structuresand functionsThe FOSSEE GroupDepartment of Aerospace EngineeringIIT Bombay1 May, 2010Day 2, Session 2FOSSEE Team (IIT Bombay) Basic Python 1 / 40Outline1 Control flowBasic LoopingExercises2 Data structuresListsTuplesDictionariesSets3 FunctionsFOSSEE Team (IIT Bombay) Basic Python 2 / 40Control flowOutline1 Control flowBasic LoopingExercises2 Data structuresListsTuplesDictionariesSets3 FunctionsFOSSEE Team (IIT Bombay) Basic Python 3 / 40Control flow Basic LoopingOutline1 Control flowBasic LoopingExercises2 Data structuresListsTuplesDictionariesSets3 FunctionsFOSSEE Team (IIT Bombay) Basic Python 4 / 40Control flow Basic LoopingwhileExample: Fibonacci seriesSum of previous two elements defines the nextIn []: a, b = 0, 1In []: while b < 10:...: print b, a, b = b, a + b...:1 1 2 3 5 8FOSSEE Team (IIT Bombay) Basic Python 5 / 40Control flow Basic Loopingrange()range([start,] stop[, step])range() returns a list of integersThestart and thestep arguments are optionalstop is not included in the listDocumentation conventionAnything within[] is optionalNothing to do with Python.FOSSEE Team (IIT Bombay) Basic Python 6 / 40Control flow Basic Loopingfor . . .range()Example: print squares of first5 numbersIn []: for i in range(5):....: print i, i i*....:0 01 12 43 94 16FOSSEE Team (IIT Bombay) Basic Python 7 / 40Control flow Basic Loopingfor . . .range()Example: print squares of odd ...
Write a program that displays all three digit numbers that are equal to the sum of the cubes of their digits. That is, print numbersabcthat have the property abc=a3+b3+c3 For example, 153=13+53+33
These are calledtsmrAngros.ermbnu
Start with an arbitrary (positive) integer. If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1. Repeat the procedure with the new number. It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
3 4
1 2
1/n1
Write a program that accepts the starting value and prints out the Collatz sequence.10 m