forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs_example_1.py
More file actions
23 lines (19 loc) · 713 Bytes
/
args_example_1.py
File metadata and controls
23 lines (19 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
# -*- coding: utf-8 -*-
# *params is just a placeholder(try putting other name)
# for n number of arguments
# so that n can be any number, instead of params
# any name can be used, but the * asterisk is important
# Below function, is a generator
# generates a tuple containing arg, and a boolean value
# every time it encounters argument
def squared(*params):
for arg in params:
yield((arg, arg % 2 == 0))
# Quick Test
print("Divisibility Test(by 2): ")
for n, bool_ in squared(12, 13, 34, 4576, 234536, 2341):
if bool_:
print(" [" + str(n) + "] -> is divisible by 2!")
else:
print(" [" + str(n) + "] -> is NOT divisible by 2!")