Overview
List of Programs
Games
GuessTheNumber
HangMan
RockPaperScissors
Utilities
ANSIColors
DiceSim
Operational Mannual
Games
GuessTheNumber
Utilities
ANSIColors
DiceSim
Here, I try to create simple python program, but overcomlicate things.
The general rule is:
- Some elements of output in terminal should be colorful.
- There should be heavy implementation of fail-safe practice, like error handeling.
Ctrl + Cshould never crash the program. Termination must be done safely.- One program should be done and dusted in one file only. One program can have multiple assets as a file, but only one executable. This is to ensure program itself is simple. Just over complicated.
GuessTheNumber.py - Computer thinks of the number, you have to guess it.
ANSIColors.py - All color codes to make terminal colorful. DiceSim.py - Create your own dice, and roll it.
python ./GuessTheNumber.py
python3 ./GuessTheNumber.py
You are offered to enter lower limit and upper limit. Lower limit is minimum value computer can think of, and Higher limit is the maximim value computer can think of. Upper limit cannot be less than or equal to lower limit. Then you have to enter your guessed number. Your guess cannot be less than Lower limit and it cannot be more than Upper limit. Next, you will enter the number of guesses. Any value less than or equal to 0 will be considered as infinite guess.
If your guess is less than computer's number, computer will say "More than that". If your guess is more than computer's number, computer will say more than that. otherwise, whatever exception the universe may bring (like if your guess exatly matches the computer's number), you will get Bingo! with number of trials you took to get here.
Then, new game will restart. The game will run for infinitely long time. Just press Ctrl + C while cursor focus on terminal screen to quite out of game. If you want to play the game again with different Lower limit, Upper limit, or number of guess allowed, you need to quite the game by pressing Ctrl + C in your keyboard and re-run the program again.
- Python 3 or more
- ANSI Color supported Terminal. [Windows Terminal, Almost all GUI Terminal application in GNU/Linux]
python ./ANSIColors.py
python3 ./ANSIColors.py
ANSI stands for American National Standards Institute. They have set up a standard for colorcodes in terminal screen like 46 is lime color and 126 is red color. Ofcourse no one can remember all those 256 colors. So, this simple script can print out color code in their respective color. The script also has the way it is implemented for python.
- Python 3 or more
- ANSI Color supported Terminal. [Windows Terminal, Almost all GUI Terminal application in GNU/Linux]
python ./ANSIColors.py
python3 ./ANSIColors.py
On running program, you are offered to enter the number of sides in dice. Following example will help you to understand what I mean.
2 for Head and Tail
3 for Head, Tail, Side
4 for Tetrahedron
5 for Trapezohedron
6 for Dice Cube
8 for Octahedron
and so on...
Dice cannot have less than 2 sides.
After that, you are offered to ehter the number of dice you can roll each time. Number of dice cannot be less than 1.
Then you just press enter again and again to roll the dice. the output could be 2 1 2 which mean you rolled 2 with first dice (may be coin), rolled 1 with second dice and 2 again with third dice.
To exit the program, you just type exit when even input is requested. Or you may as well press Ctrl + C in keyboard.
- Python 3 or more
- ANSI Color supported Terminal. [Windows Terminal, Almost all GUI Terminal application in GNU/Linux]