0% found this document useful (0 votes)
3 views

CS project

The document describes a text-based cricket game called the Odd-Even Game, where a user competes against a bot. The game involves a toss to determine who bats first, followed by two batting rounds where runs are scored, and the winner is determined based on total runs. It also discusses the modules used, particularly the random module for generating randomness in the game, and notes areas for code improvement.

Uploaded by

qu8477195
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CS project

The document describes a text-based cricket game called the Odd-Even Game, where a user competes against a bot. The game involves a toss to determine who bats first, followed by two batting rounds where runs are scored, and the winner is determined based on total runs. It also discusses the modules used, particularly the random module for generating randomness in the game, and notes areas for code improvement.

Uploaded by

qu8477195
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER SCIENCE

Odd-Even Game

FEBRUARY 15, 2024


CLASS 11-B

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

• random module (import random as rand):


• Explanation: The random module is used to introduce
randomness in the game. It provides functions for
generating random numbers. In this code,
rand.choice(sequence) is used to randomly select an
element from the given sequence. It is primarily used for
determining the bot's choices during the toss and while
batting.
• math module (import math):
• Explanation: Although the math module is imported, it is
not actively used in the provided code. This module
typically provides mathematical functions and constants. In
this code, there is no usage of math functions, so its import
statement could be removed without affecting the
program's functionality.
Let's take a closer look at the key functionality related to the
random module:
• Toss Decision: The random.choice function is used to
randomly select "ODD" or "EVEN" for the bot's toss decision.
The bot's choice is then compared with the user's choice to
determine the winner of the toss.
• Batting Runs: Random numbers are generated using
rand.choice to simulate the bot's runs during the batting
rounds. These random numbers are compared with the
user's input to determine if the user or the bot scores runs
or gets out.
Overall, the random module adds an element of unpredictability
to the game, making it more interactive and engaging for the
user. The randomness is crucial for simulating the actions of the
bot and ensuring that the outcomes of the toss and batting
rounds are not predetermined.
Source Code
Output

Bibliography- De bugging by Gemini for the code


Thank
You

You might also like