0% found this document useful (0 votes)
2 views

Python-13 march 25(While loop)

The document explains the concept of loops in programming, specifically focusing on the while loop and for loop in Python. It provides a syntax example for a while loop and outlines a guessing game algorithm where the user has three attempts to guess a secret number. The pseudo code for the guessing game is also included, demonstrating the logic for user input and win/lose conditions.

Uploaded by

free fire legend
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python-13 march 25(While loop)

The document explains the concept of loops in programming, specifically focusing on the while loop and for loop in Python. It provides a syntax example for a while loop and outlines a guessing game algorithm where the user has three attempts to guess a secret number. The pseudo code for the guessing game is also included, demonstrating the logic for user input and win/lose conditions.

Uploaded by

free fire legend
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Loop

Life is full of routines. In programming we also do


lots of repetitive tasks. In order to handle repetitive task
programming languages use loops. Python programming
language also provides the following types of two loops:

1.while loop
2.for loop
While loop
Syntax Python
WHILE condition
print (“------”)
Count=count+1
initialValue = 1

while intialValue<=10

Example: 06 print(initialValue)

Print 1 to 10 in python code . initialValue= initialValue+1


Guessing Game

Algorithm:
1. System must have a secret number.
2. System will give chance to user for 3 times for
guessing the secret number.
3.System must count guess from 1
4. System will allow user to give input when it will
be in between (3)guess limit.
5. If user’s guess & secret number is same, system
will show you a massage “you win” or after 3
chances it will show you “you lose… ”
Guessing Game
Pseudo Code:
DECLARE guessNum= INTEGER
SecretNumber =5 secret_num= 3
guessLimit=3 guess_limit =3
guessCount=1 guess_count = 1
OUTPUT “Enter your guessNumber:”
while guess_count <=guess_limit:
guess_num=int(input("guess:
WHILE guessCount<=guessLimit "))
INPUT guessNum guess_count=guess_count+1
guessCount= guessCount+1 if guess_num==secret_num:
print("you win")
IF guessNum==SecretNumber else:
print("you lose... :( )")
THEN
OUTPUT “you win”
ELSE
OUTPUT “you lose ”
ENDIF
ENDWHILE
THANK YOU

You might also like