Tutorial Python untuk bukan pengatur cara/Mengira sehingga 10: Perbezaan antara semakan
Kandungan dihapus Kandungan ditambah
Baris 74:
== Contoh ==
'''Fibonacci.py'''
<source lang="python">
a = 0
▲ #This program calulates the fibonnacci sequence
while count < max_count:
old_a = a
▲ #we need to keep track of a since we change it
b = old_a + old_b▼
▲ #Notice that the , at the end of a print statement keeps it
▲ # from switching to a new line
</source>
Output:
Baris 98 ⟶ 97:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
'''Password.py'''
<source lang="python">
</source>
Cubaan menjalankan:
▲ # Waits until a password has been entered. Use control-C to break out with out
Password: '''auo'''▼
▲ # the password
Password: '''y22'''▼
▲ #Note that this must not be the password so that the
Password: '''password'''▼
▲ # while loop runs at least once.
Password: '''open sesame'''▼
▲ password = "foobar"
Password: '''unicorn'''▼
▲ #note that != means not equal
Welcome in▼
▲ while password != "unicorn":
▲ password = raw_input("Password:")
▲ print "Welcome in"
== Latihan ==
▲ Password:auo
▲ Password:y22
▲ Password:password
▲ Password:open sesame
▲ Password:unicorn
▲ Welcome in
|