import sys
print ('Welcome to the Number Guess Game!')
upper = 10
lower = 1
if type(sys.argv) != list or len(sys.argv) > 2 :
print('Usage: guessNum [number between ' + lower + 'to' + upper + ']') )
exit()
#target = input('Please enter the target number:')
target = int ( sys.argv[1])
if target > upper or target < lower:
print('Error: out of range')
exit()
guess = 0
while target != guess :
guess=int(input('Please enter a number between' + str(lower) + 'and' +
str(upper) + ': '))
if target > upper or target < lower:
print('Error: out of range')
exit()
if guess < target:
lower = guess + 1
else:
upper = guess - 1
print('Bingo!')
--
記念第一支python程式,因為作系系統實驗而開始接觸的python……
看起來還不錯(我不喜歡白底的syntax highlighter…),但是因為我還不大熟pygments的關係(也不大熟CSS和blogger Orz),目前只能手動去改標籤,應該可以花個幾個寫個程式讓他變成我想要的就是了……
話說本來想要把blog的本文寬度調成正好顯示79個字元,不過看來很難(而且也不好看)就算了XD~
沒有留言:
張貼留言