이름 : 학번 : A. True or False: 각각항목마다 True 인지 False 인지적으세요. 1. (Python:) randint 함수를사용하려면, random 모듈을 import 해야한다. 2. (Python:) '' (single quote) 는한글자를표현할때, (double quote) 는문자열을표현할때사용한다. B. 다음에러를수정하는방법을적으세요. 1. >>> print 'adsf'+3 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects functiona(); 2. a.py 파일내용 functiona(); def functiona() : print 'asdf' $ python a.py Traceback (most recent call last): File "a.py", line 1, in <module> functiona(); NameError: name 'functiona' is not defined 3. (C:) #include <stdio.h> int main() { char a[10]; a[0]='a'; a[1]='s'; a[2]='d'; a[3]='f'; printf("%s\n",a); return 0; } Segmentation fault.
4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona C. (Python:) 1. Fill in the blanks with a proper data type among integer, floating point number, str, list, tuple, and dict. 1, 3, 5, 7, 9, 11 1.0, 2.0, 3.0, 4.0 ( a, b, c ) "7 apples, 14 oranges, 3 lemons" 3.14, 6.05, 2.68 [125603806, 1,1] 'O*&#wY%*&gfC%YO*&%3yc8r2' { a : b } {1: asdf } "10", "20", "30", "40", "50" 2. Fill in the blanks with a proper entire statement. (8) A B A or B A and B True True False False True False True False
3. Guess the results. >>> int('42') >>> int(42) >>> int('hello') >>> int('two') >>> int(' 42 ') >>> 2 + int('2') >>> '2' + '2' >>> 'Hello' == 'HELLO' >>> not True >>> False not 4. Fill in the blanks in the following source code. Height : 3 * ** *** 6 Source code: def CountStars(height) : i=0 cnt=0 while i!=height : i=i+1 print return cnt print 'Height :' height = int(raw_input()) print str(countstars(height))
5. 1) Fill in the blank. print He said, "I can't believe you let him borrow your car." 2) Fill in the blank. >>> spam = [2, 4, 6, 8, 10, 12, 14] >>> >>> spam [2, 4, 8, 10, 12, 14] 3) Guess the results. >>> animals = ['aardvark', 'anteater', 'antelope', 'albert'] >>> animals[0:2] _ >>> animals[0: 1] _ >>> 'Hello world!'[3:8] _ 6. Answer one term in each description. candidates: variable, function, parameter, argument, index, condition, interpreter, boolean, expression, methods, module (1) Another name for an expression, one that exists in an if or while statement that evaluates to a boolean True or False value. (2) Values and function calls connected by operators. This can be evaluated down to a single value. (3) An integer between square brackets that is placed at the end of an ordered container variable(most often a list) to evaluate to a specific item in that container. (4) A program that translates instructions written in a higher level programming language to machine code that the computer can understand and execute.
7. Guess the result. def problemdescription(num) : cnt=0 for i in range(1,num+1) : if num%i == 0 : cnt=cnt+1 return cnt fnum = 3 snum = 7 result1 = problemdescription(fnum) print str(result1) result2 = problemdescription(snum) print str(result2) 8. Fill in the blanks. Result Input the length of the string: 5 Generated random word is 'wdhac' >>> ======================= RESTART ======================= Input the length of the string: 8 Generated random word is 'inhksmhl' >>> ======================= RESTART ======================= Input the length of the string: 20 Generated random word is 'cwpohdgflamxutsqjeni' Source code: #Random String Generator import random def string_generator(leng): i = 0; basic = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split() st = str('') while i < leng: temp = return length = int(raw_input('input the length of the string : ')) gen_string = string_generator(length) print 'Generated random word is \'' + gen_string + '\''
9. Guess the result. >>>a=[1, 3, 2] >>>b=a >>>d=b[:] >>>d.sort() >>>b >>>a D. (c 언어 ) 1. 변수 x 가 integer type 적으시오. x = (3 + 7) * 3; x= x = (12 + 6) / 2 * 3; x= x=(int)((3.4+7)/2); x= x=(int)(3.4/2)+(int)(7.4/2); x= 이라가정하고다음빈칸에 x 와 y 의계산결과값을 x= 3 + 2.5*2.5; X=, y= 2. 변수 x 가 char type 이라가정하고다음빈칸에 x 의계산결과값을적으시오. x='a'+4; x= x='a'+256; x= 3. Guess the result. #include <stdio.h> #include <stdlib.h> void main() { printf("%d\n", strcmp( YES, YES )); } 4. Guess the result. >>> wordindex = 2 >>> print(wordindex) >>> print(['apple', 'orange', 'grape'][wordindex])
5. Guess the result. >>> mydict = {'0':'a string', 0:'an integer'} >>> mydict[0] 6. 다음문장을간단히설명하세요. srand(time(null)); 7. Guess the result. for i in range(1,6): strline = str('') for j in range(5 i): strline = strline + ' ' for j in range(i 1): strline = strline + '*' print strline for i in range(0,4): k = 4 i strline = str('') for j in range(4): strline = strline + ' ' for j in range(k): strline = strline + '*' print strline 8. In this question, where appropriate, you may use a short fragment of code to complement your explanation. What is the difference between function declaration and definition?
9. 다음과같은프로그램을작성하시오. 1. 100 개의임의의숫자를발생시켜, 이를하나의 List 에저장한다. 숫자들은 1 에서부터 1000 까지의범위를가진다. 2. for 문을이용하여이 List 안의숫자들을출력한다. 숫자들간에는한칸의빈간격을둔다. 3. for 문을이용하여이 List 안의숫자중에서가장큰숫자를찾아서출력한다. 실행예제 )