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

Help, When investing money, an important concept to know is compound intere...

When investing money, an important concept to know is compound interest. The equation FV = PV (1+rate)periods . This relates the following four quantities. The present value (

Primitives, Primitives, Composition, Abstraction, and Patterns   We ...

Primitives, Composition, Abstraction, and Patterns   We will  start  by thinking about  how  the  PCAP  framework applies to computer programs, in general. We may do that by

Structured assignment, Structured assignment Once  we have  tuples and...

Structured assignment Once  we have  tuples and lists, we may use  a nice trick  in assignment expression, based  on the packing and unpacking of tuples. >>> a, b, c = 1, 2

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]

Basics of python-introduction, Basics of python-introduction Python is...

Basics of python-introduction Python is designed for easy interaction between a user and the system. It goes with  an inter­ active function  known as  a shell or listener.  T

Lcr circuit, program on damped lcr cicuit

program on damped lcr cicuit

Python programming, Suppose the cover price of a book is $24.95, but bookst...

Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the total whol

Turtle graphics module in python programming language, Your assignment for ...

Your assignment for the semester will involve the development of a system for drawing trees using the Python programming language and the turtle graphics module (turtle.py). Comple

Matrix, What are squared matrices?

What are squared matrices?

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