Created
January 8, 2012 16:16
-
-
Save mojaie/1578863 to your computer and use it in GitHub Desktop.
hitandblow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
import random | |
print '###Hit and Blow###' | |
ls = range(10) | |
random.shuffle(ls) | |
answer = ls[:4] | |
while 1: | |
try: | |
nums = raw_input('0-9の整数を4つ入力してください(空白区切り):') | |
numarr = [int(e) for e in nums.split(' ') if len(e) == 1] | |
if len(numarr) != 4: | |
raise | |
except: | |
print 'エラー:入力が不正です。' | |
continue | |
hit = 0 | |
blow = 0 | |
for i in range(4): | |
if answer[i] == numarr[i]: | |
hit += 1 | |
continue | |
for j in range (4): | |
if answer[i] == numarr[j]: | |
blow += 1 | |
print str(hit) + ' hit ' + str(blow) + ' blow' | |
if hit == 4: | |
print 'Congratulations!' | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment