CS project
CS project
Odd-Even Game
Rishav Ranjan
S.NO Table of contents
1 About the code
2 Modules Used
3 Source code
4 Output
5 Bibliography
6 End
About the Code
The provided code is a simple text-based cricket game between a user
and a bot. The game includes a toss to determine which side (odd or
even) the user and the bot will play. The user and the bot then take
turns batting, and the winner is determined based on the total runs
scored in the match. Here's a breakdown of the code:
Toss and Decision: The game starts with a toss where the user inputs
a number. Based on the sum of the user's input and a random number
chosen by the bot, it is decided whether the user or the bot will bat
first. The user is then prompted to choose between "Odd" and "Even."
Batting Rounds: The game consists of two rounds - one for the user
and one for the bot. In each round, the player (user or bot) inputs a
number representing the runs scored on each ball. The bot's runs are
determined randomly. If the user's or bot's input matches the
randomly generated number, the player is considered "Out."
Scoring and Outcome: The total runs scored and the number of balls
played are calculated for each player. The winner is then determined
based on the total runs scored. If the user's runs are greater than the
bot's, the user wins; if the bot's runs are greater, the bot wins. If the
runs are equal, the match is declared a draw.
Input Validation: The code includes input validation to ensure that the
user inputs valid numbers within the range of 1 to 6 for both the toss
and the batting rounds.
Randomization: The random module is used to generate random
numbers for the bot's choices during the toss and batting.
Repetition: There is some repetition in the code that could be reduced
through refactoring. The batting logic for the user and the bot is
similar, and some parts of the code could be combined for better
readability and maintainability. It's worth noting that the code has
been revised to address indentation issues, improve input validation,
and correct the scoring logic.
Modules used
The modules used in this code are given below with a slight explanation of
how they will work in this project