首页 > 代码库 > python的初体验

python的初体验

基础、选择、循环

 

================================

基础、选择、循环

# 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)

 

 

本文出自 “小崔的实验笔记” 博客,谢绝转载!

python的初体验