CSI Final Example Questions Python and computer security

Ace your homework & exams now with Quizwiz!

2. What symbol can you use to comment out one line of code? *, (comment), //, #

#

13. What is the output of this program: n = 0 c = 0 for i in range(6): print(i) n = i + n c = c +1 print ("i = ", i) print ("c = ", c) print ("n = ", n)

0 1 2 3 4 5 i = 5 c = 6 n = 15

12. What is the Output of the following code segment? x = 3 counter = 0 while x < 100: print x counter = counter+1 x = x + 3 print ("There are ",counter,"counters")

Syntax Error: Missing parentheses in call to 'print'.

11. What is the Output of the following code segment? Number = 11 while number >= 0: print number number = number - 1 print ('Blastoff!)

Syntax Error: multiple statements found while compiling single statement

31. Which of the following is the use of function in python? a) Functions are reusable pieces of programs b) Functions don't provide better modularity for your application c) you can't also create your own functions d) All of the mentioned

a

36. what is the output of the following code: def say(message, times = 1): print(message * times) say('Hello') say('World', 5) a) HelloWorldWorldWorldWorldWorld b) HelloWorld 5 c) HelloWorld,World,World,World,World d) Hello

a

14. What is the output of the following? x = ['ab', 'cd'] for i in x: i.upper() print(x) a) ['ab', 'cd'].b) ['AB', 'CD'].c) [None, None].d) none of the mentioned

a) ['ab', 'cd']

21. Which of the following is an invalid variable? a) my_string_1 b) 1st_string c) foo d) _

b

24. What is the average value of the code that is executed below? grade1 = 80 grade2 = 90 average = (grade1 + grade2) / 2 a) 85 b) 85.0 c) 95 d) 95.0

b

35. What is the output of the below program? x = 50 def func(): global x print('x is', x) x = 2 print('Changed global x to', x) func() print('Value of x is', x) a) x is 50 Changed global x to 2 Value of x is 50 b) x is 50 Changed global x to 2 Value of x is 2 c) x is 50 Changed global x to 50 Value of x is 50 d) None of the mentioned

b

32. Which keyword is use for function? a) Fun b) Define c) Def d) Functi

c) Def

4. What is the type of a a = 10//6 ? float, int

int

22. Give an equivalent expression for the expression below so that x will end up with an integer value: x = int(13 / 2)

x//2

8. What is printed after the following code is executed? count = 0 while (count < 5): print ('The count is:', count) count = count + 1 print ("Good bye!")

The count is: 0 The count is: 1 The count is: 2 The count is: 3 The count is: 4 Good bye!

6. Given the following code: name = input("What is your name? ") password = input("What is the password? ") if name == "Josh" or password == "Friday": print ("Welcome!") elif name == "Fred" and password == "Rock": print ("Welcome Fred") else: print ("I don't know you.") 7. What will be printed if the user enters "Sara" for the name and "Friday" for the password?

Welcome!

20. Is Python case sensitive when dealing with identifiers? a) yes b) no c) sometimes only d) none of the mentioned

a

33. What is the output of the below program? def sayHello(): print('Hello World!') sayHello() sayHello() a) Hello World! b) 'Hello World!' Hello World! 'Hello World!' c) Hello d) None of the mentioned

a) Hello World!

17. What is the output of the following? i = 1 while True: if i%3 == 0: break print(i) i + = 1 a) 1 2 b) 1 2 3 c) error d) none of the mentioned

c) error

19. What arithmetic operators cannot be used with strings? a) + b) * c) - d) **

c, d

25. Select all options that print hello-how-are-you a) print('hello', 'how', 'are', 'you') b) print('hello', 'how', 'are', 'you' + '-' * 4) c) print('hello-' + 'how-are-you') d) print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')

c,d

23. In order to store values in terms of key and value we use what core datatype. a) List b) tuple c) class d) dictionary

d

3. What is the type of b a = "bay" b = a[0] ? chr, ord, int, str

str

5. What is a a = 4 % 6 *12/3 ? 0.0, 16.0, 4.0, 6.0

16

34. What is the output of the below program ? x = 50 def func(x): print('x is', x) x = 2 print('Changed local x to', x) func(x) print('x is still', x) a) x is still 50 b) x is still 2 c) x is still 100 d) None of the mentioned

Answer: x is 50. Changed local x to 2x is still 50

18. What is the output of the following? i = 5 while True: if i%0O9 == 0: break print(i) i += 1 a) 5 6 7 8 b) 5 6 7 8 9 c) 5 6 7 8 9 10 11 12 13 14 15 ....d) error

d) error

15. What is the output of the following? x = ['ab', 'cd'] for i in x: x.append(i.upper()) print(x) a) ['AB', 'CD'].b) ['ab', 'cd', 'AB', 'CD'].c) ['ab', 'cd'].d) none of the mentioned

d) none of the mentioned

1. In Python, what is one function to output content to the console? echo, output, print, console.log

print

10. Find and correct any logical or syntax errors in the following code so that the program produces the desired result: response = input("would you like to enter numbers" y/n: ) total = 0 while response = y: num 1 = input("Please enter the first number: ") 2num = input("Please enter the second number: ") if num1 < 2num: total = total + num1 else total = total + 2 num print (total)

response = input("would you like to enter numbers y/n:" ) total = 0 while response = y: num 1 = input("Please enter the first number: ") 2num = input("Please enter the second number: ") if num1 < 2num: total = total + num1 print(total) else: total = total + 2 num print (total)


Related study sets

ECO 3250 Nontariff Barriers to Imports (BOOKS)

View Set

Statistics final exam from professor

View Set

Modul 1 - Lektion 1 Hallo, ich bin Nicole

View Set

Marketing Multiple Choice Practice Questions

View Set

Nacionalidades masculino - femenino

View Set

Letter 'M' : Prefixes, Combining Forms, and Suffixes

View Set

EU - cycle 8 - Free movement of Persons

View Set