L = [365,'everyday',3.14,True]
print(L[-1])
print(L[-3])
#切片符號:相當於集合 [),半開半閉區間
print(L[0:3])
#不指定結束位,表示到最後一位結束
print(L[:3])
#不指定起始位,表示從頭開始
print(L[1:])
#不指定起始和結束位,切片等於原始序列
print(L[:])
#點球遊戲
#電腦爲守門員,守住三個方向,左中右;人爲發球員,想左中右三個方向發球,
#如果電腦方向=人發球方向,電腦+1否則人+1
from random import choice
#python3 使用input接收所有格式的輸入
dircetion = input('Choose one side to shoot(L/M/R):')
print('your choose is ' + dircetion)
seq = ['L','M','R']
#choice函數隨機取序列中的一個值
com = choice(seq)
print('computer\'s choice is ' + com)
computer = 0
person = 0
if dircetion == com:
#python數字自相加
computer+=1
#python中輸出數字使用%s %f佔位
print('wow!computer get a goal,now is %d ' %(computer))
else:
person+=1
print('wow!person get a goal,now is %d ' %(person))
python3--list的使用2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.