Closed [1] python basics: while

Status
Not open for further replies.

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.
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.
 
Did you know?

Web hosting is a service that allows organizations and individuals to post a website or web page onto the Internet. A web host, or web hosting service provider, is a business that provides the technologies and services needed for a website or webpage to be viewed on the Internet. Websites are hosted, or stored, on special computers called servers.

When Internet users want to view your website, all they need to do is type your website address or domain into their browser. Their computer will then connect to your server, and your webpages will be delivered to them through the browser.

When it comes to web hosting companies based on the number of hosted websites, GoDaddy has established itself as a clear market dominator. According to HostAdvice, GoDaddy has covered over 19% of the market, leaving a not-so-significant market share to other hosting providers such as Google Cloud Platform, 1&1, Amazon Web Services, and Cloudflare.

According to Builtwith, GoDaddy has also managed to become a world dominator when it comes to providing VPS web hosting. GoDaddy’s market share in this segment counts for over 23%, whereas its closest competitors, such as DreamHost and Digital Ocean, cover 1.46% and 1.23% of the market share, respectively.
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
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.

About this Thread

  • 12
    Replies
  • 773
    Views
  • 8
    Participants
Last reply from:
Modelobugdotcom

Trending Content

Online now

Members online
513
Guests online
9,204
Total visitors
9,717

Forum statistics

Threads
2,032,235
Posts
27,568,687
Members
1,602,571
Latest member
MomoNoce91
Back
Top