Friday, 26 February 2016

Computing lesson 18/2 LOOP


25 February



Firstly, I have learnt how to set up raspberry pi as a desktop and it is Linux and also learnt the commands of raspberry pi.

Next, I have learnt about loop. There is function of factorial and function sum_up_to_n. There are two ways to type the range.    For both, we first have to define factorial n by typing “def fac(n):” or define sum_up_to_n by typing “def sum_up_to_n (n):”. A colon must be added at the end.  We will have to type result = 1 for factorial or result = 0 for sum_up_to_n since factorial cannot have 0 being multiplied as answers will always be 0.   One way is to type “for I in range (1, n+1):”  while the other is “ while ( i <= n ):”     The last step will be to type “return result” and then print the n number that we want to insert in. 




No comments:

Post a Comment