1.while is more versatile than for: always on if conditions are met
2. Guess the number Game version 1.0
ImportNumPy as NP" "guess the integer 1.0 version: 1. Number of records 2. Give range 3.while statements, including continue, break, Tyr, except" "Answer=np.random.randint (1,101) I=0 whileTrue:Try: Guess=int (Input ('please guess a positive integer of 1-100:')) I+=1ifguess==Answer:Print('It's great! \ n your guess {0} is correct! \ n You used {1} times to guess the answer! I'll give you some praise! '. Format (guess,i)) Break elifguess<Answer:Print('your answer is too small! Please continue ...') Print('{0} times guessed value: {1}'. Format (i, guess))Continue elifGuess>Answer:Print('your answer is too big! Please continue ...') Print('{0} times guessed value: {1}'. Format (i, guess))Continue except: Print('wrong input format! Please check again after typing! ')
Python notes (one)------while loop (break and Continue)