create account

Python practice tests by filler

View this thread on: hive.blogpeakd.comecency.com
· @filler ·
$1.74
Python practice tests
![python.JPG](https://cdn.steemitimages.com/DQmfK3NSLkgix84XPWi78DAAZrEooeNpkUsDg6Xsv55zdqC/python.JPG)

A set of practice questions that a beginner of Python should be able to answer quite quickly if he/she has grasped the subject. Practice can help and one should not just learn it by heart. 

* x = 3
    y = x + 3
    y = int(str(y) + "2")
    print(y)

Output - 62

* x = 3
num = 17
print(num % x)

Output - 2

*  list = [1, 1, 2, 3, 5, 8, 16]
print(list[list[4]])

Output - 8

A bit confusing for beginners but it is easy to grasp and do try substituting various numbers and practice it.

* letters = ['x', 'y', 'z']
letters.insert(1, 'w')
print(letters[2])

Output - y

* def print_nums(x):
  for i in range(x):
    print(i)
    return
print_nums(10)

Output - 0

* def func(x):
  res = 0
  for i in range(x):
     res += i
  return res

print(func(4))

Output - 6

* try:
  print(1)
  assert 2 + 2 == 5
except AssertionError:
  print(3)
except:
  print(4)

Output - 3

* nums = (55, 44, 33, 22, 11)
print(max(min(nums[:2]), abs(-42)))

Output - 44

Questions are from the Python learning app - Solo learn.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 113 others
properties (23)
authorfiller
permlinkpython-practice-tests
categorycoding
json_metadata{"tags":["coding","python","neoxian","computer","education"],"image":["https://cdn.steemitimages.com/DQmfK3NSLkgix84XPWi78DAAZrEooeNpkUsDg6Xsv55zdqC/python.JPG"],"app":"neoxiancity/0.1","format":"markdown","canonical_url":"https://www.neoxian.city/@filler/python-practice-tests"}
created2019-10-28 17:07:33
last_update2019-10-28 17:07:33
depth0
children4
last_payout2019-11-04 17:07:33
cashout_time1969-12-31 23:59:59
total_payout_value0.858 HBD
curator_payout_value0.883 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,113
author_reputation4,924,532,976,740
root_title"Python practice tests"
beneficiaries
0.
accountneoxianburn
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,986,943
net_rshares7,271,806,107,105
author_curate_reward""
vote details (177)
@emrebeyler ·
How come this outputs with 0? 

def print_nums(x):
for i in range(x):
print(i)
return
print_nums(10)
👍  
properties (23)
authoremrebeyler
permlinkq041dt
categorycoding
json_metadata{"app":"steemit/0.1"}
created2019-10-29 00:29:54
last_update2019-10-29 00:29:54
depth1
children3
last_payout2019-11-05 00:29:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length100
author_reputation448,535,049,068,622
root_title"Python practice tests"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,996,464
net_rshares5,577,140,777
author_curate_reward""
vote details (1)
@filler ·
> return is a construction used in the code block of a function definition + after the return instruction is inserted the code block will stop executing anything so :

> def print_nums(x):
  for i in range(x): 
    print(i)
    return
print_nums(10)

> Program takes 0, verifies that is in range of 10 and prints 0
Because of the return statement program stops executing the code 

> If return is deleted from code the output will be
0
1
2
3
4
5
6
7
8
9
properties (22)
authorfiller
permlinkq04d3d
categorycoding
json_metadata{"app":"steemit/0.1"}
created2019-10-29 04:42:54
last_update2019-10-29 04:42:54
depth2
children2
last_payout2019-11-05 04:42:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length453
author_reputation4,924,532,976,740
root_title"Python practice tests"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,000,955
net_rshares0
@emrebeyler ·
That depends on the indentation:-)
👍  
properties (23)
authoremrebeyler
permlinkq04iem
categorycoding
json_metadata{"app":"steemit/0.1"}
created2019-10-29 06:37:36
last_update2019-10-29 06:37:36
depth3
children1
last_payout2019-11-05 06:37:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation448,535,049,068,622
root_title"Python practice tests"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,002,759
net_rshares5,554,864,179
author_curate_reward""
vote details (1)