Last active
February 13, 2017 20:14
-
-
Save hugot/19de1a2771ac81c4917e97afa1263bef to your computer and use it in GitHub Desktop.
I am doing python tutorials in bash, call me crazy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#----- Functions ----- | |
divide() { | |
echo $(( $(($1 * 100)) / $2)) | |
} | |
multipleOfFour() { | |
result=$(divide $1 2) | |
[[ ${result#*0} == *0* ]] | |
} | |
even() { | |
result=$(divide $1 4) | |
[[ ${result#*0} == *0* ]] | |
} | |
checkResultIsEven() { | |
result=$(divide $1 $2) | |
if even $result; then | |
echo Dividation resulted in an even number | |
else | |
echo Dividation resulted in an uneven number | |
fi | |
} | |
#----- application logic ----- | |
while true; do | |
echo enter a number | |
read number | |
if multipleOfFour $number; then # Exercise 2 | |
echo your number is a multiple of four | |
elif even $number; then # Exercise 1 | |
echo your number is even | |
else | |
echo Your number is uneven | |
fi | |
# Exercise 3 | |
echo enter two numbers, one to check, one to divide by, in that order | |
read num1 num2 | |
checkResultIsEven $num1 $num2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made this inspired by this python tutorial http://www.practicepython.org/exercise/2014/02/05/02-odd-or-even.html