# python-1 50q

1. What does the following code print to the console?

```a = s = b = c = 1
s = 2
b = 3
print(a)```

Question 1 of 50

2. What does the following code print to the console?

```a, b, c, d = 0, 0, 0.0, 0
e = f = g = h = 0

print((a, b, c, d) == (e, f, g, h))```

Question 2 of 50

3. What does the following code print to the console?

```string1 = 'hello'
string2 = "hello"
string3 = """
hello
"""

print(string1 == string2 == string3)```

Question 3 of 50

4. What does the following code print to the console?

```string1 = 'hello hello '
string2 = "hello "*2

print(type(string1) == type(string2))```

Question 4 of 50

5. What does the following code print to the console

```def multiplication(a, b, c):
return a * b * c

a = 55
b = 10.0
c = False

print(multiplication(a, b, c))```

Question 5 of 50

6. What does the following code print to the console?

```s = 'The quick brown fox'
a = 'Hot dog'
a = s
a = a[:-3] + s[-3:]
print(a)```

Question 6 of 50

7. We have a python dictionary that stores the names of vegetables and their prices. We need to buy 3 carrots, 2 pears ans 1 orange. Select the code that gets the price sum correctly.

```shop = {'fruits': [{'orange': '\$3'}, {'pear': '\$2.05'}],
'vegetables': {'potato': '\$1', 'carrot': '\$1.5'}}```

Question 7 of 50

8. What does the following code print to the console?

```a = "Rotator"
b = a[::-1]
c = a[-1] + a[-2] + a[-3] + a[-4] + a[-3] + a[-2] + a[-1]
d = a[:3] + 'a' + a[:3][::-1]
print(a.lower() == b.lower() == c.lower() == d.lower())```

Question 8 of 50

9. What does the following code print to the console?

```a = True
b = False
c = a | b
e =  1

if a & b or c == 1 and c is e:
print("Hello!")
elif c is not e or b:
print("How are you?")
else:
print("I`m fine!")```

Question 9 of 50

10. What does the following code print to the console?

```days = ['Monday', 'Friday', 'Sunday']
age = 20

if (days.count('Monday') or 'Tuesday' not in days[:2]) and age >= 2:
print("1")
age = ''*100
if age:
print('3')
else:
print('4')
else:
print("2")
age = {}
if age:
print('5')
else:
print('6')```

Question 10 of 50

11. What does the following code print to the console?

```a = 5

if (True if 5 >= 0 else False)  or (False if 5 >= 0 else True):
print('1')
if a in range(-5,5):
print('3')
else:
print(4)
else:
print('2')
if a in range(5):
print('5')
else:
print(6)

```

Question 11 of 50

12. What does the following code print to the console?

```a = ('a', [1, 2, 3], 'b', {'a': 3})

if type(a) == 'dict' and a[3]['a'] == '3':
print('1')
elif type(a[0]) == 'str':
print('2')
elif a[0] * a[1][2] == 'aaa':
print('3')
else:
print('4')```

Question 12 of 50

13. Which of the listed operators should we use  here (a [operator] b) to get the largest number?

```a = 5
b = 4```
`print(a [operator] b)`

Question 13 of 50

14. Which of the listed operators should we use here (a [operator] b) to get the smallest number?

```a = -2
b = 4

print(a [operator] b)```

Question 14 of 50

15. Which of the listed operators should we use instead of {operator} to get 'Success' printed?

```a = ['a', 'b', 'c']
b = ['a', 'b', 'c']

```
```if a[1] {operator} b[1] and a {operator} b:
pass
else:
print('Success!!')```

Question 15 of 50

16. What does the following code print to the console?

```a = 2
b = 3

if a|b is (a&b):
print(a<<b)
else:
print(a*b)```

Question 16 of 50

17. What does the following code print to the console?

```a = 10

if a > 8:
a += 10
if a > 18:
a += 10
if a > 28:
a += 10
elif a > 38:
a += 10
if a > 48:
a += 10
if a > 58:
a += 10

print(a)```

Question 17 of 50

18. What does the following code print to the console?

```i = 7

for i in range(5):
if i < 7:
i+=1

print(i)```

Question 18 of 50

19. What does the following code print to the console?

```a = 5

do:
a-=2
while a <= 0

print(a)```

Question 19 of 50

20. What does the following code print to the console?

```i = 20
for i in range(10):
while True:
i += 2
if i == 15:
break

print(i)```

Question 20 of 50

21. What does the following code print to the console?

```resut = 0
for i in range(15):
for item in ['cat', 'dog', 'hamster']:
if i == 3:
continue
if i == len(item):
result += 1

print(result)```

Question 21 of 50

22. What does the following code print to the console?

```items = ['a', 'b', 'c', 'd']

for i in range(len(items)):
for item in items:
item = '-'

print(items)```

Question 22 of 50

23. What does the following code print to the console?

```def func(a, b):
c = a + b

c = 0
for i in range(1, 5):
c += func(c, i)

print(c)```

Question 23 of 50

24. What does the following code print to the console?

```items = []
i = 0

while i == 0:
for i in range(2):
while True:
items.append('*')
i = 2
if len(items) == 5 or len(items) == 7:
break
break```

Question 24 of 50

25. The following code has an error, which line is it on?

```1: f = open("demofile.txt", "r")
4: f.write('Hello!')
5: f.close()```

Question 25 of 50

26. What does the following code print to the console? ('demofile.txt' exists. Size of the file: 64 kb)

```1: file = open('demofile.txt', 'rb')
3: file.close()
4: a = a[2:4]

5: file = open('demofile.txt', 'rb')
8: file.close()

9: print(a==c)```

Question 26 of 50

27. You need to check if some file exists in file system, how do you do it?

Question 27 of 50

28. You need to check if some file exists and delete them, how do you do it?

Question 28 of 50

29. You need to safely get acces to the second console argument, how do you do it?
Example:
\$python3 script.py 'A' 'B' 'C'
You need to access 'B'

Question 29 of 50

30. You are asking the user to enter an integer number between 1 and 30, inclusive, into the console.
What code validates this input correctly?

Question 30 of 50

31. You have list of lists:

`a = [['1', '2', '3'],  ['4', '5', '6'], '7']`

What is the correct way to get

`'1|2|3;4|5|6;7'`

printed?

Question 31 of 50

32. The following code has an error, which line is it on?

```1: ##this is a comment
2: #this is a comment
3: """this is a  comment"""
4: """
5: this is a  comment
6: """
7: //this is  a  comment```

Question 32 of 50

33. The following code has an error, which line is it on?

```1: #comment
2: a = 5
3:      #comment
4: a = 7
5:      """comment"""
6: a = 9
7: """
8: comment
9: """
```

Question 33 of 50

34. What does the following code print to the console?

```1: def func1(a, b):
2:    """
3:    :param a:
4:    :param b:
5:    :return:
6:    """
7:
8:    for i in range(5):
9:    #increment a
10:        a+=b
11:        """:return a"""
12:    """return a"""
13:    return a
14:
15:c = func1(3, 5)
16:print(c)```

Question 34 of 50

35. What does the following code print to the console?

```def func1(a=5, b=6, c):
return a*b*c
a = func1(2)
print(a)```

Question 35 of 50

36. What does the following code print to the console?

```def func1(*args):
return args

a = func1('a', 'c')

print(a)```

Question 36 of 50

37. What does the following code print to the console?

```def func1(a, b, c=5, d=-1):
a = a+b*c
if a > 10:
return a*b
return c*d

a = func1(2,1)
b = func1(3,2)
print(a == b)
print(a is b)```

Question 37 of 50

38. What does the following code print to the console?

```def func1(a, b, *args):
a = (a+10)*args[0]
return a

def func1(a, b, c = 6):
return c

a = func1(1,2,3)

print(a)```

Question 38 of 50

39. Which exception will the following code raise?

```def func1(a, b, c=6):
a = a-c
b = c/a*2
return b

a = 6
b = 2
c =  func1(a, b)```

Question 39 of 50

40. Which exception will the following code raise?

```people_list = ['Joe', 'Markus', 'Jennifer']

for item in people_list:
next = people_list.index(item) + 1
print("{} and {} are friends!".format(item, people_list[next]))```

Question 40 of 50

41. Which exception will the following code raise?

```a = "quick brown fox jumps over the lazy dog"
a = a[:-3] + 'fox'
a[-3:] = 'fox'
print(a)```

Question 41 of 50

42. What does the following code print to the console?

```dict1 = {'a':'1', 'b':'2'}
dict2 = {'a':'3', 'b':'4'}
type = 'dictionary'

for k, v in dict1.items():
dict2[k] = dict1[k]

print(type(dict1['a']) == type(dict2['a']))```

Question 42 of 50

43. What does the following code print to the console?

```def check_exception(a):
try:
c = a/0
except ZeroDivisionError:
print("1")
else:
print('2')
c = 2
finally:
c = 3
print('3')
print('4')
return c

a = check_exception(5)
print(a)```

Question 43 of 50

44. Which code correctly handles the import of a non-existent module?

Question 44 of 50

45. What does the following code print to the console?

```def check_exception():
try:
raise Exception('1')
except ValueError as e:
print(str(e))
print('2')
finally:
print('3')

check_exception()```

Question 45 of 50

46. What is the correct way to create combo of random color and number from 1 to 22 using code given?

```import random
colors = ['Red', 'Green',  'Blue']```

Question 46 of 50

47. What does the following code print to the console?

```import math
a = 2.9
b = 2.95

c = math.abs(a*b)
print(c)```

Question 47 of 50

48. What is the correct way to get new path without folderD: 'C:/folderA/folderB/folderC/myfile.zip'
?

```import os
path = 'C:/folderA/folderB/folderC/folderD/myfile.zip'```

Question 48 of 50

49. How many full years have passed since that date?
Which function does this correctly?

```import datetime
born = datetime.datetime(1960, 5, 17)
years_now = get_age(born)
print(years_now)```

Question 49 of 50

50. What is the lowest and highest possible value of 'result'?

```import random
numbers = [1, 2, 3, 4]
result = random.randint(2, 4)*random.randint(1, 3)*random.choice(numbers[0:2])/random.choice(random.shuffle(numbers))
print(result)
```

Question 50 of 50