这篇文章主要介绍了python官方网站下载教程,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。
大家好,本文将围绕python中3//2的值为1.5展开说明,python中3<<2怎么算是一个很多人都想弄明白的事情,想搞清楚python2中3/2的结果需要先了解以下几个事情。
importrandomdefdrawBoard(board):# This function prints out the board that it was passed.# "board" is a list of 29 strings representing the board (ignore index 0)print('|---+---+---+---+---+---+---|')print('| | | | | | | |')print('| '+board[1]+' | '+board[2]+' | '+board[3]+' | '+board[4]+' | '+board[5]+' | '+board[6]+' | '+board[7]+' | ')print('| | | | | | | |')print('|---+---+---+---+---+---+---|')print('| | | | | | | |')print('| '+board[8]+' | '+board[9]+' | '+board[10]+' | '+board[11]+' | '+board[12]+' | '+board[13]+' | '+board[14]+' | ')print('| | | | | | | |')print('|---+---+---+---+---+---+---|')print('| | | | | | | |')print('| '+board[15]+' | '+board[16]+' | '+board[17]+' | '+board[18]+' | '+board[19]+' | '+board[20]+' | '+board[21]+' | ')print('| | | | | | | |')print('|---+---+---+---+---+---+---|')print('| | | | | | | |')print('| '+board[22]+' | '+board[23]+' | '+board[24]+' | '+board[25]+' | '+board[26]+' | '+board[27]+' | '+board[28]+' | ')print('| | | | | | | |')print('|---+---+---+---+---+---+---|')defwhoGoesFirst():ifrandom.randint(0,1)==0:# coin flip 50/50 who starts combatfirstToSpawn=enemy
lastToSpawn=playerelse:firstToSpawn=player
lastToSpawn=enemy# following chunk works out the spawn points of the first to enter#and the last to enter, respectively. It then places them on the#board in their respective spawn points, represented by their symbolwhilefirstToSpawnnotintheBoardandlastToSpawnnotintheBoard:boardSpawn='1 2 3 4 5 6 7 14 21 28 27 26 25 24 23 22 15 8'.split()boardSpawnResult=random.choice(boardSpawn)theBoard[int(boardSpawnResult)]=firstToSpawnprint(firstToSpawn+' has entered the room.')else:iffirstToSpawnintheBoardandlastToSpawnnotintheBoard:boardHalf=len(boardSpawn)/2boardHalf=int(boardHalf)lastToSpawnPosition=int(boardSpawnResult)+boardHalfiflastToSpawnPosition>len(boardSpawn):lastToSpawnPosition=lastToSpawnPosition-len(boardSpawn)lastToSpawnPosition=boardSpawn[lastToSpawnPosition]theBoard[int(lastToSpawnPosition)]=lastToSpawnprint(lastToSpawn+' has entered the room.')iffirstToSpawn==player:playerLocale=int(boardSpawnResult)globalplayerLocaleelse:playerLocale=int(lastToSpawnPosition)globalplayerLocaleprint(drawBoard(theBoard))defshoot():shotChance=int(playerStats[1])-int(gangerStats[3])didItHit=random.randint(int(shotChance),100)ifdidItHit<65:print(playerName+' Missed the shot!')elifdidItHit>=65:didItCrit=random.randint(int(playerStats[5],85))ifdidItCrit>=85:shotDamage=25+weaponsGlockprint('Critical hit! '+shotDamage)else:shotDamage=weaponsGlockprint(playerName+' Hit the enemy for '+shotDamage)gangerStats[0]-shotDamageifgangerStats[0]<1:print(playerName+' killed the Ganger!')#declaring globals and starting the programwhileTrue:theBoard=[' ']*29player=' 'enemy='!'print('What\'s your name, Droog?')playerName=input()player=playerName[0].upper()playerLocale=' 'playerStats='100 50 2 10 5 2'.split()gangerStats='65 20 1 5 3 5'.split()weaponsGlock=30whoGoesFirst()shoot()whileint(gangerStats[0])>0:command=input('Type shoot to attack again:').lowerifcommand=='shoot':shoot()else:ifint(gangerStats[0])<=0:command=input('Type "searchbody" to loot dead enemies:').lower