리스트도 곱셈 연산이 가능하다! 특정 아이템의 인덱스를 찾자
import random
sampleList = random.sample(range(1,11),10)
selectIndex = int(input('숫자 7의 위치 입력'))
searchIndec = sampleList.index(7)
if selectIndex == searchIndec:
print('정답')
else:
print('오답')
import random
types = ['A', 'B', 'O', 'AB']
todayData = []
typeCnt=[]
for i in range(100):
type = types[random.randrange(len(types))]
todayData.append(type)
print(f'today num : {len(todayData)}')
for type in types :
print(f'{type} \t : {todayData.count(type)}')
리스트와 비슷하지만 아이템 변경 불가
아이템 존재 유무 판단하기
import random
ranInt = random.sample(range(1,11), 5)
check = int(input('숫자 입력'))
result = True
while result == True:
if check in ranInt :
print('있다')
result =False
print(ranInt)
else:
print('없다')
continue
wrongWord = ['쩔었다','짭새','꼽사리','먹튀','지린','쪼개다','뒷담 까다',]
sentence = '짭새 등장에 강도들은 모두 쩔었다. 그리고 당도 들은 지린 듯 도망갔다.'
for word in wrongWord :
if word in sentence :
print(f'비속어 : {word}')
myNum = (11,2,3,4,5,6,7,8,)
friendNum = (1,2,3,4,5,6,7,8,9,10)
print(myNum)
print(friendNum)
for number in myNum :
if number not in friendNum :
friendNum = friendNum + (number, )
print(friendNum)
원하는 아이템만 뽑아내자!