顯示具有 程式設計 標籤的文章。 顯示所有文章
顯示具有 程式設計 標籤的文章。 顯示所有文章

2010年1月10日 星期日

猜數字遊戲(一)

# -*- coding: utf-8 -*-

# Python version: 2.5.4


import random


ans = random.randint(0, 3)

count= 0

num = 0


2010年1月9日 星期六

九九乘法表

# -*- coding: utf-8 -*-
# Python version: 2.5.4

"""九九乘法表"""


範例一、
# -*- coding: utf-8 -*-
# Python version: 2.5.4


for i in range(1, 10):

    for j in range(1, 10):
        print i ,'*', j ,'=' ,i*j

python 寫 剪刀、石頭、布

# -*- coding: utf-8 -*-
# PYTHON version: 2.5.4

import random

hand = ['剪刀', '石頭', '布']

pwin = 0
cwin = 0

c = random.choice(hand)
pc = input('請選擇-0(剪刀),1(石頭),2(布):')
p = hand[pc]

while pwin < 3 and cwin < 3:
   print '目前成績: 電腦贏了', cwin, '次'
   print ' 玩家贏了', pwin, '次\n\n'

   c = random.choice(hand)
   pc = input('請選擇-0(剪刀),1(石頭),2(布):')
   p = hand[pc]
   if c == '剪刀' and p == '布' or c == '石頭' and p == '剪刀' or c == '布' and p == '石頭':
      print '電腦出:', c, '玩家出:', p
      print 'computer win!'
      cwin += 1

   elif c == '剪刀' and p == '石頭' or c == '石頭' and p == '布' or c == '布' and p == '剪刀':
      print '電腦出:', c, '玩家出:', p
      print 'player win!'
      pwin += 1

   elif c == '剪刀' and p == '剪刀' or c == '石頭' and p == '石頭' or c == '布' and p == '布':
      print '電腦出:', c, '玩家出:', p
      print '平手!!'

if pwin > cwin:
   print '恭禧!玩家勝出!'
else:
   print '你輸了!!'