while loops get to the while statementtry to see if temp is not equal to - and run into problem because temp doesn' yet exist to take care of thiswe just declare temp equal to there is nothing special about the value here we could set it to anything except - (setting it to - would cause the condition on the while loop to be false right from the start and the loop would never run note that is natural to think of the while loop as continuing looping until the user enters - howeverwhen we construct the conditioninstead of thinking about when to stop loopingwe instead need to think in terms of what has to be true in order to keep going while loop is lot like an if statement the difference is that the indented statements in an if block will only be executed oncewhereas the indented statements in while loop are repeatedly executed example one problem with the previous program is that when the user enters in - to quitthe program still converts the value - and doesn' give any message to indicate that the program has ended nicer way to do the program is shown below temp while temp!=- temp eval(input'enter temperature (- to quit)')if temp!=- print'in fahrenheit that is ' / *temp+ elseprint'bye'example when first met if statements in section we wrote program that played simple random number guessing game the problem with that program is that the player only gets one guess we canin sensereplace the if statement in that program with while loop to create program that allows the user to keep guessing until they get it right from random import randint secret_num randint( , guess while guess !secret_numguess eval(input'guess the secret number')print'you finally got it'the condition guess!=secret_num says that as long as the current guess is not correctwe will keep looping in this casethe loop consists of one statementthe input statementand so the program will keep asking the user for guess until their guess is correct we require the line guess= prior to the while loop so that the first time the program reaches the loopthere is something in guess for the program to use in the comparison the exact value of guess doesn' really matter at this point we just want something that is guaranteed to be different than secret_num when the user finally guesses the right answerthe loop ends and program control moves to the print statement after the loopwhich prints congratulatory message to the player