티스토리 뷰
2. 어린이에게 산술을 가르치는 응용 프로그램을 작성하시오.
각 교육 세션마다 2개의 수에 대행 더하기, 빼기, 나누기 및 곱셈을 포함하는
10 개의 질문을 임의로 생성한다. 각 세션이 시작될 때 사용자는 질문에 응답하기위한
시간 제한을 지정할 수 있습니다.
시간제한이 지정되지 않은 경우 기본 시간제한으로 30초로 정한다.
질문을 한 후 사용자가 질문에 응답 할 때까지 기다린다.
점수를 주는 방법은 다음 규칙을 사용한다.
답 시간 점수
============================================================
맞음 제한시간 이내 10
맞음 제한시간 초과 6
틀림 제한시간 이내 3
틀림 제한시간 초과 0
각 세션이 끝난 후에 다음과 같은 방법으로 콘솔에 총 점수를 출력하시오.
제한시간 이내 제한시간 초과
정답 4 3
오답 2 1
총점: 64 (40 + 18 + 6 + 0)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import random import time in_correct = 0 #시간 이내 정답 in_wrong = 0 #시간 이내 오답 out_correct = 0 #시간 초과 정답 out_wrong = 0 #시간 초과 오답 def get_score(answer, correct_answer, tm):#입력 값, 문제 정답, 실행 시간 global in_correct, in_wrong, out_correct, out_wrong if answer == correct_answer and tm < 30: #답과 입력이 같고, 실행 시간이 30초 이내 in_correct = in_correct + 1 #시간 이내 정답 갯수 + 1 elif answer == correct_answer and tm > 30:#답과 입력이 같고, 실행 시간이 30초 초과 out_correct = out_correct + 1#시간 초과 정답 갯수 + 1 elif answer != correct_answer and tm < 30:#답과 입력이 다르고, 실행 시간이 30초 이내 in_wrong = in_wrong + 1 #시간 이내 오답 갯수 + 1 elif answer != correct_answer and tm > 30:#답과 입력이 다르고, 실행 시간이 30초 초과 out_wrong = out_wrong + 1 #시간 초과 오답 갯수 + 1 for i in range(0, 10):# 10문제이기 때문에 0~9 x = random.randrange(1,10) # 1이상 10미만 랜덤값 x y = random.randrange(1,10) # 1이상 10미만 랜덤값 y for_op = random.randrange(0,4) # 0이상 4미만 랜덤값 operator op = ['+', '-', '*', '/'] #연산자들을 list에 넣어둠 correct_answer = 0 #초기화 if op[for_op] == '+': #save_op가 '+'' 일때 correct_answer = x + y #정답 = 랜덤값(0~9) + 랜덤값(0~9) print(x, " + ", y, " = ??") # 출력 start_time = time.time() # 시작 시간 # print(correct_answer) answer = input("input your answer:") # 사용자 입력 end_time = time.time() #끝나는 시간 tm = end_time - start_time # 소요 시간 = 끝나는 시간 - 시작 시간 get_score(int(answer), correct_answer, tm) #사용자 입력, 문제의 정답, 소요 시간 #이 아래로 위와 같음 elif op[for_op] == '-': correct_answer = x - y print(x, " - ", y, " = ??") start_time = time.time() # print(correct_answer) answer = input("input your answer:") end_time = time.time() tm = end_time - start_time get_score(int(answer), correct_answer, tm) elif op[for_op] == '*': correct_answer = x * y print(x, " * ", y, " = ??") start_time = time.time() # print(correct_answer) answer = input("input your answer:") end_time = time.time() tm = end_time - start_time get_score(int(answer), correct_answer, tm) elif op[for_op] == '/': correct_answer = int(x / y) # 나누면 소숫점이 나와서 몫만 구하도록 int로 casting print(x, " / ", y, " = ??") start_time = time.time() # print(correct_answer) answer = input("input your answer(only integer):") end_time = time.time() tm = end_time - start_time get_score(int(answer), correct_answer, tm) score = in_correct * 10 + out_correct * 6 + in_wrong * 3 + out_wrong * 0 print(" 제한시간 이내 제한시간 초과") print("정답 ", in_correct, " ", out_correct) print("오답 ", in_wrong, " ", out_wrong) print("총점:", score, "(",in_correct * 10, "+",out_correct*6,"+",in_wrong*3,"+",out_wrong*0,")") | cs |
'Python > Note' 카테고리의 다른 글
selenium 안드로이드 앱 크롤링 (0) | 2019.02.13 |
---|---|
Python one key, multiple values(string in list) dictionary (파이썬 키 하나 여러 밸류 리스트 스트링 ) (0) | 2018.11.11 |
django 기본 프로젝트 생성 등등 (0) | 2018.09.29 |
Python 입력 단어의 모음 출력하기 (0) | 2018.08.01 |
python for문 예제 (0) | 2018.06.30 |
티스토리 방명록
- Total
- Today
- Yesterday
Contact: j0n9m1n1@gmail.com