pythonÓï·¨½éÉÜ
1.1. Óï·¨
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
... print 'negative'
... elif x==0:
... print 'zero'
... else:
... print 'positive'
...
negative
ÕâÀïÓм¸¸ö֪ʶµãÐèÒªÌáÐÑ£º
1¡£ºÍshellÖÐifÓï¾äµÄÇø±ð
ÎÒÃÇÀ´»Ø¹ËÒ»ÏÂshellÖеÄifÓï¾ä¡£
shellÖÐifÓï¾äµÄ½á¹¹ÊÇ£º
if ±í´ïʽ
then ÃüÁî±í
[else]
fi
¾Ù¸ö¼òµ¥µÄÀý×Ó£ºifsingle
#!/bin/bash
#filename:ifsingle
echo "please enter the first string:"
read word1
echo "please enter the second string:"
read word2
echo "_______________"
if test $word1 = $word2 ÕâÀï×¢Òâ$word1ºÍ$word2Ö®¼äµÄµÈºÅÇ°ºó±ØÐëÓпոñ£¬²»È»¾Í±ä³ÉÁ˸³ÖµÓï¾ä£¬³ÌÐòµÄ¹¦ÄܾÍÌåÏÖ²»³öÀ´ÁË¡£
then
echo " the first string is equal to the second string"
fi
echo "the program has finished"
²¢ÇÒifÓï¾ä¿ÉÒÔÎÞÏÞ²ãµÄǶÌ×ÔÚÆäËûifÓï¾äÖС£
pythonÖеÄÊÇÒ»¸öif£¬elif,elseÓï¾äʵÏÖ¶à·ÅжÏ
ÎÒÃÇͬÑù¾ÙÒ»¸öÏàËƵÄÀý×Ó£º
ʹÓÃvi±à¼Æ÷½øÐб༣º
#!/bin/bash
#filename:ifelif
echo "please enter the first argu:"
read str1 z×¢ÒâÕâÀïÇв»ÒªÊ¹ÓÃ$1£¬ÒòΪ$1ÊÇÖ¸³ýÁ˳ÌÐòÃûµÄµÚÒ»¸ö²ÎÊý
echo "please enter the second argu:"
read str2
echo "please enter the third argu:"
read str3
if test $str1 = $str2 -a $str2 = $str3 test ÓÃ[ ]ÊÇtestµÄÓï·¨£¬ÐèÒªÓÃ-a±íʾÂß¼Ó룬µ±È»test Ò²¿ÉÒÔ²»ÊµÓÃ[]
then
echo "the three argu are same"
elif test $str1 = $str2
then
echo "the first argu is equal to the second argu"
elif test $str2 = $str3
then
echo "the second argu is equal to the third argu"
elif test $str1 = $str3
then
echo "the third argu is equal to the first argu"
else
echo " they are different"
fi
2
Ïà¹ØÎĵµ£º
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......
¶ÔËÑË÷ÒýÇæ¡¢ÎļþË÷Òý¡¢Îĵµ×ª»»¡¢Êý¾Ý¼ìË÷¡¢Õ¾µã±¸·Ý»òǨÒƵÈÓ¦ÓóÌÐòÀ´Ëµ£¬¾³£Óõ½¶ÔÍøÒ³(¼´HTMLÎļþ)µÄ½âÎö´¦Àí¡£ÊÂʵÉÏ£¬Í¨¹ýPythonÓïÑÔÌṩµÄ¸÷ÖÖÄ£¿é£¬ÎÒÃÇÎÞÐè½èÖúWeb·þÎñÆ÷
»ò
ÕßWebä¯ÀÀÆ÷¾ÍÄܹ»½âÎöºÍ´¦ÀíHTMLÎĵµ¡£±¾ÎĽ«Ïêϸ½éÉÜÈçºÎÀûÓÃPythonץȡºÍ½âÎöÍøÒ³¡£Ê×ÏÈ£¬ÎÒÃǽéÉÜÒ»¸ö¿ÉÒÔ°ïÖú¼ò»¯´ò¿ªÎ»ÓÚ±¾µØºÍ ......
while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......
ÔÚÒ»¸öÏîÄ¿ÖÐÐèÒª»ñÈ¡Ëæ»úÊý£¬ËÖªµÀÓöµ½µãÎÊÌ⣺Ëæ»úÊý²»Ëæ»ú¡£ËùÒÔÎÒдÁ˸ö¼òµ¥ÔÐÍ¡£¿´Ïµ½µ×ÊÇɶÎÊÌâ¡£
import os,random,sys,time
while True:
father = os.fork()
if father:
time.sleep(2)
rd = 7
else:
#random.seed()
rd = random.choice([2,3,4,5])
......
ÓÃgcc±àÒëÁËÒ»¸öC++µ÷ÓÃpythonµÄ³ÌÐò£¬Õâ¸ö³ÌÐòÔÚVSÏÂÊǺÃÓõģ¬¶øÇÒûÓÐʹÓÃvsµÄÈκοâ
¿ÉÊǵ½ÁËgccϾÍÊÇÎÞ·¨Ê¹ÓÃ
ºóÀ´ÉÏÍø²éÁËÒ»ÏÂ×ÊÁϲÅÖªµÀ£¬ÊÇÒòΪclÓëgccµÄÔËÐÐʱ¿â²»Í¬¡£
´ò¿ªcmd´°¿Ú£¬ÊäÈëpython¾Í¿ÉÒÔ¿´µ½
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32
Type " ......