Foundation, selection, cycle
================================
Foundation, selection, cycle
# python
>>> quit ()
# Python[tab]
# Python2
# python2.6
>>> 3+3
>>> 3 + 3
# VI hello.py
#!/usr/bin/python Print (' Hello ') Print (' World ') |
>>> k=9
>>> K
>>> k=9.9-3
>>> K
>>> for I in Range (1,10):
... [Tab]print (i)
... [Tab]
>>> i=20
>>> for K in range (1,i):
... [Tab]print (k)
...
# VI random.py
Import Random Today=random.randint (1,7) Print (today) |
>>> for I in range (1,3):
[Tab]today=random.randint (1,7)
[Tab]print (Today)
[Tab]
--------------
Eg:1
# VI example1.py
Import Random I=random.randint (1,100) J=random.randint (1,100) If i>80: []print (' Good,your maths. ') Elif i>60: []print (' Normal,your maths. ') Else []print (' Bad,your maths. ')If j>80: []print (' Good,your Chinese ') Elif j>60: []print (' Normal,your Chinese. ') Else []print (' Bad,your Chinese. ') |
Eg:2
Import Random I=1 While True: []i=i+1 []t1=random.randint (1,100) []t2=random.randint (1,100) []total=t1+t2 []if Total = = 200: [][]break Print (' Double 100 ') Print (i) |
This article from "Little Cui's experimental notes" blog, declined to reprint!
The first experience of Python