먼저 random 라이브러리와 time 라이브러리를 사용합니다.
random : 난수
time : 프로그램의 안정성
import random
import time
list_1 = [1,2,3,4,5,6,7,8,9,10] # 숫자 범위
list_2 = [1,2,3] # 더하기 뺴기 곱하기 선택
list_3 = [1,2]
list_4 = (range(1, 101))
a = 0
b = 0
c = 0
moksum = 0
list_temporary_1 = [] # 랜덤 선택한 숫자를 저장할 공백 리스트
list_temporary_3 = [] # 공백 리스트
list_temporary_2 = [] # 공백 리스트
# 정답 임시저장
answer = 0
right = 0 # 맞은 문제
step = int(input("easy = 1 , normal = 2 , hard = 3")) # 단계 선택
if step == 1: # 선택한 단계가 1단계 일떄
moksum = 5 # 1단계 목숨
for i in range(1,6):
b = 0
c = 0
a = 0
list_temporary_1.append(random.choice(list_1)) # 랜덤 선택
list_temporary_2.append(random.choice(list_1)) # 랜덤 선택
b = (list_temporary_1[0]) # 비교를 위한 저장
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
if moksum == 0:
break
time.sleep(0.5)
step = 0
pass
elif step == 2:
moksum = 4
for i in range(1,11):
list_temporary_1.append(random.choice(list_1))
list_temporary_2.append(random.choice(list_1))
list_temporary_3.append(random.choice(list_3))
if (list_temporary_3[0]) == 1: # 1이면 더하기 1단계와 동일
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 2: # 2면 뺴기
b = (list_temporary_1[0])
c = (list_temporary_2[0])
if ((list_temporary_1[0]) - (list_temporary_2[0])) <= 0: # 결과가 음수로 나올때
a = input(f"{(list_temporary_2)[0]} - {(list_temporary_1)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(c) - int(b)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif ((list_temporary_1[0]) - (list_temporary_2[0])) > 0: # 결과가 양수로 나올때
a = input(f"{(list_temporary_1)[0]} - {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) - int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다") # 목숨이 0개면 코드 종료
time.sleep(0.5)
step = 0
pass
elif step == 3: # 3단계는 list_4를 사용해 더하기 뺴기는 1~ 100
moksum = 3
for i in range(1,16):
list_temporary_3.append(random.choice(list_2))
if (list_temporary_3[0]) == 1:
list_temporary_1.append(random.choice(list_4))
list_temporary_2.append(random.choice(list_4))
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 2:
list_temporary_1.append(random.choice(list_4))
list_temporary_2.append(random.choice(list_4))
b = (list_temporary_1[0])
c = (list_temporary_2[0])
if ((list_temporary_1[0]) - (list_temporary_2[0])) <= 0:
a = input(f"{(list_temporary_2)[0]} - {(list_temporary_1)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(c) - int(b)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif ((list_temporary_1[0]) - (list_temporary_2[0])) > 0:
a = input(f"{(list_temporary_1)[0]} - {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) - int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 3: # 3이면 곱셈
list_temporary_1.append(random.choice(list_1))
list_temporary_2.append(random.choice(list_1))
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} * {(list_temporary_2)[0]} = ?? ") # 더하기와 코드는 동일
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) * int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif moksum == 0:
break
time.sleep(0.5)
step = 0
else :
pass
print(right,"점 입니다")
import random
import time
# 리스트
list_1 = [1,2,3,4,5,6,7,8,9,10]
list_2 = [1,2,3]
list_3 = [1,2]
list_4 = (range(1, 101))
a = 0
b = 0
c = 0
moksum = 0
list_temporary_1 = []
list_temporary_3 = []
list_temporary_2 = []
# 정답 임시저장
answer = 0
# 맞은 문제
right = 0
step = int(input("easy = 1 , normal = 2 , hard = 3"))
if step == 1:
moksum = 5
for i in range(1,6):
b = 0
c = 0
a = 0
list_temporary_1.append(random.choice(list_1))
list_temporary_2.append(random.choice(list_1))
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
if moksum == 0:
break
time.sleep(0.5)
step = 0
pass
elif step == 2:
moksum = 4
for i in range(1,11):
list_temporary_1.append(random.choice(list_1))
list_temporary_2.append(random.choice(list_1))
list_temporary_3.append(random.choice(list_3))
if (list_temporary_3[0]) == 1:
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 2:
b = (list_temporary_1[0])
c = (list_temporary_2[0])
if ((list_temporary_1[0]) - (list_temporary_2[0])) <= 0:
a = input(f"{(list_temporary_2)[0]} - {(list_temporary_1)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(c) - int(b)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif ((list_temporary_1[0]) - (list_temporary_2[0])) > 0:
a = input(f"{(list_temporary_1)[0]} - {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) - int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
time.sleep(0.5)
step = 0
pass
elif step == 3:
moksum = 3
for i in range(1,16):
list_temporary_3.append(random.choice(list_2))
if (list_temporary_3[0]) == 1:
list_temporary_1.append(random.choice(list_4))
list_temporary_2.append(random.choice(list_4))
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} + {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) + int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 2:
list_temporary_1.append(random.choice(list_4))
list_temporary_2.append(random.choice(list_4))
b = (list_temporary_1[0])
c = (list_temporary_2[0])
if ((list_temporary_1[0]) - (list_temporary_2[0])) <= 0:
a = input(f"{(list_temporary_2)[0]} - {(list_temporary_1)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(c) - int(b)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif ((list_temporary_1[0]) - (list_temporary_2[0])) > 0:
a = input(f"{(list_temporary_1)[0]} - {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) - int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif (list_temporary_3[0]) == 3:
list_temporary_1.append(random.choice(list_1))
list_temporary_2.append(random.choice(list_1))
b = 0
c = 0
a = 0
b = (list_temporary_1[0])
c = (list_temporary_2[0])
a = input(f"{(list_temporary_1)[0]} * {(list_temporary_2)[0]} = ?? ")
print()
print()
print()
del (list_temporary_1[0:])
del (list_temporary_2[0:])
del (list_temporary_3[0:])
if int(a) - (int(b) * int(c)) == 0:
right += 1
print(f"현재목숨은{moksum}개 입니다")
else:
moksum -= 1
if moksum == 0:
break
print(f"현재목숨은{moksum}개 입니다")
elif moksum == 0:
break
time.sleep(0.5)
step = 0
else :
pass
print(right,"점 입니다")