Skip to content

Commit 7248a6f

Browse files
committed
add exercise 2
1 parent 1691027 commit 7248a6f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

exerices_2.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
'''
5+
Ask the user for a number.
6+
Depending on whether the number is even or odd, print out an appropriate message to the user.
7+
Hint: how does an even / odd number react differently when divided by 2?
8+
9+
Extras:
10+
11+
If the number is a multiple of 4, print out a different message.
12+
Ask the user for two numbers: one number to check (call it num) and one number to divide by (check).
13+
If check divides evenly into num, tell that to the user. If not, print a different appropriate message.
14+
'''
15+
16+
n = raw_input('Please input a number: ')
17+
18+
n = int(n)
19+
20+
if n % 2 == 0:
21+
print 'The number you input is even'
22+
23+
else:
24+
print 'The number you input is odd'
25+
26+
if n % 4 == 0:
27+
print 'and the number is a multiple of 4'
28+
29+
print 'Check if a number could be divided evenly by another one: '
30+
31+
num = raw_input('Please input a number to check: ')
32+
divider = raw_input('Please input a divider number: ')
33+
34+
num = int(num)
35+
divider = int(divider)
36+
37+
remainder = num % divider
38+
39+
if remainder == 0:
40+
print '{0} could be divided by {1} evenly'.format(num, divider)
41+
else:
42+
print '{0} could not be divided by {1} evenly, the remainder is {2}'.format(num, divider, remainder)

0 commit comments

Comments
 (0)