While loop, Python Programming

Assignment Help:

 

You should use for whenever you can, because  it creates  the structure of your  loops clear. Sometimes, however, you require to do an operation various times, but you don't want to know in advance how many  times it requires  to be done.  In such conditions, you can use a while instruction statement, of the form:

 

while :

...

 

In  order  to  evaluate a while statement, the  interpreter  evaluates , placing a Boolean  value.  If the value  is 0, it skips  all the statements and  calculation moves  on to the next  statement in the code.  If the value  is 1 or true, then  the instructions are performed, and  the

 

is calculated again.  If it is False, execution of the loop is ended, and if it is

 

True, it goes around again.

It will generally be the case that you initialize a variable before the while statement, modify that variable in the course of executing the loop, and check some property of that variable in the Boolean expression. Consider that you need to write  a procedure that  takes an argument n and  returns the largest  power of 2 that is shorter  than  n. You may do it like this:

 

def pow2Smaller(n):

p = 1

while p*2 < n:

p = p*2

return p

 


Related Discussions:- While loop

Three layer neural network to classify the two sets of 3-D d, 1. Use a thre...

1. Use a three layer neural network to classify the two sets of 3-D data set. You should generate 100 samples for each data set based on the following criteria: Data set 1: generat

Conditionals- booleans, Booleans   Before we talk about  conditional...

Booleans   Before we talk about  conditionals, we require  to clarify the Boolean  data  type.  It has two values False and True. Typical statement that have Boolean values

assignment 10, #question.Program 10 Assignment (Banking Objects – Savings/...

#question.Program 10 Assignment (Banking Objects – Savings/Checking Accounts) Create a program named 10.py that performs the following: Create a class named ChkAcct, and a class n

Random Geometric Graphs, Displaying random geometric graphs in an uniform s...

Displaying random geometric graphs in an uniform square, unit disk, dense rim unit disk, and uniform sphere

Lists, Python has  a built-in list data  structure that  is easy  to use  a...

Python has  a built-in list data  structure that  is easy  to use  and  incredibly convenient.  So, for that point, you can say >>> y = [1, 2, 3] >>> y[0] 1 >>> y[2]

Variables, Variables We cannot  go very far without variables. A variabl...

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

Euler method, python program of motion of a particle in viscus medium

python program of motion of a particle in viscus medium

Procedures as First-class objects, Procedures as First-class objects I...

Procedures as First-class objects In Python, unlike  many  other  languages, methods are behave in much  the same way as num­ bers:  they  can be stored as values  of variable

Python programs, Python Programs You must submit the source code and s...

Python Programs You must submit the source code and samples of output for each program.Please do not provide python file (eg. Filename.py). Copy all source code to one word fi

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd