The loops: For and while masteries 19, 20

whileforloops

With this program the conditional loop while and the loop with range of values are executed; te program basicaly asks for a number to make the factorial of it with the For, yet it does not allows you to type a float using the While

While

After the conditionals If, the conditional loop came in, they do everything inside them WHILE the condition is met

while

So

let f be a point, like the point of the float numbers

while (f in x):
       print («You see?»)
       x = input («Give me an integer»)

With these lines of code, you are making a restriction of value for X, that it can not store values with the point on it.

for () in range ()

for

This function is a combintation between the For loop, and the ranges. The for loop is basicaly say for a variable from the start value to the end one each n steps, it breaks when there are no more values. This is a little tricky one; first, you have to start with the for followed by a non-defined variable, then, that variable will ocuppy every number from x number including it to y number excluding it each z «steps» like this for e in range (x,y,z). {If you don’t put a z, it is 1}

We know a factorial number is that number multiplied by that number – 1 and so on, so we can recreate that with this for function

for e in range (1,x ):
fact = fact*(x-e)

which means that fact is going to take the value of fact times the number, represented with X minus the times the loop has run, represented with

e is going to take every value from X to 1 excluding 1 each 1 step, so if X is 5, e is going to be 5, 4, 3, 2, and 1dependig on which round it is.

And that is it!!

StraightOuttaSomewhere

Deja un comentario