What's new

Closed [1] python basics: while

Status
Not open for further replies.

Vladimir420

Addict
Established
Joined
Dec 10, 2018
Posts
86
Reaction
33
Points
103
Dahil may pasok pako at isiningit ko lang to, Bibillisan natin.
While = Repeat the conclusion while statement is True;
Loop until false.

Anong ibig sabihn nyan? Ibig sabihin, paulit ulit nyang ie-execute ang conclusion mo habang true pa. Example.
Code:
i = 0
#define i as integer 0
while i == 0:
    #i == 0 is a statement that means i is equal to 0.
    #while true. Kasi nga 0 talaga si 0 nung dinefine natin, Uulitin nyatong script na to.
    print('i ==', i)
Dahil natigil yung code natin kagabi, Sa previous topic natin, Lalagyan natin sya ng loop para pwede ka mag restart pag nag kamali ka.

Code:
import random
#import natin yung module na random for access ng random functions
import time
#for time modules.

rand_this = [1, 2, 3, 4, 5, 6]
#integers in a list

t = input('Number of tries: ')
#number of trials based on uset input.
counter = 0

while counter != int(t):
    #!= is not equal which is true/false based on user input.

    guess = input('Guess a number from 1-6 \n')
#tatanungin kung anong hula mo.
#ang \n ay new line

    result = random.choice(rand_this)
#pipili ang script ng choice dun sa list natin sa taas. RANDOMLY

    if int(guess) == result:
        print('You win!', guess, 'is', result)
    else:
        print('Sorry.', guess, 'is not', result)
    counter += 1
    #instead of counter = counter + 1
#if and else statement. Yung nasa baba ay ang conclusions ang 'if' ay condition. Uri sya ng function.
#ang int() naman ay conversation from string. To integer.

#ang nasalabas ng while ay mag eexecute lamang kapag tapos na ang loop or false na.
print('Thankyou for playing.')
time.sleep(5)
#sleep for 5seconds.
Sana may mga matutunan kayo sa kakemehan ko.

Next topic: Basic file reading/writing.
 
Mejo may nakuha ako. Mejo mahirap kasi ung looping para sakin pati array. Pero talagang marami lang destruction sa isip ko. Well new line lang alam ko.:) pero pag aaralan ko ung post mo ts. Thanks sa effort.
 
Last edited by a moderator:
Mejo may nakuha ako. Mejo mahirap kasi ung looping para sakin pati array. Pero talagang marami lang destruction sa isip ko. Well new line lang alam ko.:) pero pag aaralan ko ung post mo ts. Thanks sa effort.
Pa follow ako boss interested ka pala sa programming
 
Last edited by a moderator:
Pa follow ako boss interested ka pala sa programming
interested talga ako tatlong beses ko tinake ung programming 1 at dalawang beses ko tinake ung prog 2 pati database management 2 2 take rin ako. wahahah kaya naging interested ako sa programming kaya ngayun running for graduate na ako. proud to be 5 years in I.T. whahaha
 
interested talga ako tatlong beses ko tinake ung programming 1 at dalawang beses ko tinake ung prog 2 pati database management 2 2 take rin ako. wahahah kaya naging interested ako sa programming kaya ngayun running for graduate na ako. proud to be 5 years in I.T. whahaha
G11 here. baka kulang ka sa reference dati paps
 
it's nice to see na may nagtuturo ng py dito. super dali lang ng programming language na to. highly ρáíd pa at top sya sa mga most desired programming language for web and desktop app. nice sharing kay OP.
 
Status
Not open for further replies.

Similar threads

Back
Top