-
Notifications
You must be signed in to change notification settings - Fork 1
/
exercise_17.py
49 lines (44 loc) · 1.24 KB
/
exercise_17.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
print(
'-----------------------------------------\n'\
'Practical python education || Exercise-17:\n'\
'-----------------------------------------\n'
)
print(
'Task:\n'\
'-----------------------------------------\n'\
'Write a Python program to get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference."\n'
)
print(
'Solution:\n'\
'-----------------------------------------'\
)
#Task: b = a - 17;
#Conditions:
# a > 17 => b = 2(a - 17);
# a <= 17 => b = a - 17;
#First solution:
'''
print("Calculation the difference between a given number and 17:")
a = int(input("Please enter the number = "))
if (a > 17):
b = 2 * (a - 17)
print("%d > 17, then = %d" % (a, b))
else:
b = a - 17
print("%d <= 17, then = %d" % (a, b))
'''
#Second appropriate solution:
def diff(n):
if n <= 17:
b = 17 - n
print("%d <= 17, then = %d" % (n, b))
else:
b = (n - 17) * 2
print("%d > 17, then = %d" % (n, b))
diff(int(input("Please, enter the number = ")))
diff(int(input("Please, enter the number = ")))
print(
'\n-----------------------------------------\n'\
'Copyright 2018 Vladimir Pavlov. All Rights Reserved.\n'\
'-----------------------------------------'
)