Vladimir420
Established
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.
Dahil natigil yung code natin kagabi, Sa previous topic natin, Lalagyan natin sya ng loop para pwede ka mag restart pag nag kamali ka.
Sana may mga matutunan kayo sa kakemehan ko.
Next topic: Basic file reading/writing.
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)
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.
Next topic: Basic file reading/writing.