The value of 3//2 in python is 1.5. How to calculate 3<<2 in python?

Hello everyone, this article will focus on the explanation of the value of 3//2 in python as 1.5. How 3<<2 in python is a thing that many people want to understand. If you want to understand the result of 3/2 in python2, you need to understand it first. Here are a few things.

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

Supongo que te gusta

Origin blog.csdn.net/chatgpt002/article/details/132866888
Recomendado
Clasificación