Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CLASS VIII- COMPUTING

PROJECT REPORT

ACTIVITY 1 (PROJECT)
Simulate the roll of a dice (between 1 and 6). Repeat the simulation for two users. The one
who gets the first 6 wins the game. Display all intermediate throw values for both users. Also,
provide the verdict of the winner.

How to implement Roll the Dice Game in Python?

To implement the rolling dice game in Python, We will be using the random module. The
random module provides us with different functions to generate numbers within a range or
select numbers with a range from a list. Since we want to randomize the numbers we get from
the dice, we will use the randint() function and the choice() function defined in the random
module to implement the game in Python.

Rolling Dice using the randint() Function in Python

To implement the rolling dice game in Python using the randint() function, we will initialize
two variables min_value and max_value to the lowest and highest number of dice i.e. 1 and 6
respectively. Then, we will use the randint() function to generate a random integer from 1 to
6. The randint() function takes the minimum value and maximum value of a range as its input
arguments and returns a random integer within the range. We will pass the
variables min_value and max_value to the randint() function to imitate dice rolling by
generating a random number from 1 to 6.

To implement the functionality to repeatedly roll the dice, we will use a while loop so that the
user can choose to roll the dice again. For this, we will ask the user if they want to roll the
dice again. We will assign the user input to a variable roll_again. If the user
inputs "yes" or "y", we will roll the dice by executing the while loop again. Otherwise, we
will come out of the while loop.

After implementing the above functionalities, you can implement the rolling dice game in
Python as shown below.

PROJECT ACTIVITY 2:

Circle Calculation: Write a program that takes the radius of a circle as input and uses the pi()
function to calculate and display the area and circumference of the circle.

1
MS BHAGYASHREE B.
Cambridge Facilitator
PROJECT ACTIVITY 3:

Rounding Grades: Create a program to input a student's test score, then use the ceil() and
floor() functions to round the score up or down to the nearest integer, and display the rounded
grade.

PROJECT ACTIVITY 4:

Tax Calculator: Build a tax calculator program that takes an individual's annual income as
input. Use the ceil() function to round the income up to the nearest thousand dollars and the
floor() function to round it down. Then, calculate the tax based on the rounded income and
display the result.

PROJECT ACTIVITY 5:

Temperature Conversion: Develop a program for converting temperatures between


Fahrenheit and Celsius. Use the ceil() and floor() functions to ensure that the converted
temperatures are displayed as whole numbers.

PROJECT ACTIVITY 6:

Price Adjustment: Create a program that allows a store manager to input the original price of
a product. Use the ceil() function to increase the price to the nearest dollar and the floor()
function to decrease it to the nearest dollar. Display both the rounded-up and rounded-down
prices.

2
MS BHAGYASHREE B.
Cambridge Facilitator
SOLUTIONS:

1. Rolling Dice:

import random
min_value=1
max_value=6
roll_again = "yes"
while roll_again == "yes" or roll_again == "y":
print("Rolling the dices...")
print("The values are....")
value1=random.randint(min_value, max_value)
value2=random.randint(min_value, max_value)
print(value1,value2)
roll_again = input("Press 'y' or 'yes' to roll the dices again.")
print("Have a good day.")

Expected Outcome:

Rolling the dices...


The values are....
64
Press 'y' or 'yes' to roll the dices again.y
Rolling the dices...
The values are....
14
Press 'y' or 'yes' to roll the dices again.y
Rolling the dices...
The values are....
51
Press 'y' or 'yes' to roll the dices again.yes
Rolling the dices...
The values are....
52
Press 'y' or 'yes' to roll the dices again.N
Have a good day.

The above code keeps rolling the dice until you give any other input than 'y' or 'yes'.

IMPROVED VERSION OF THE ABOVE PROJECT :


https://www.youtube.com/watch?v=x-Ag2_bJ40Y

3
MS BHAGYASHREE B.
Cambridge Facilitator
2. Circle Calculation:

import math

# Input the radius from the user


radius = float(input("Enter the radius of the circle: "))

# Calculate the area and circumference


area = math.pi * radius**2
circumference = 2 * math.pi * radius

# Display the results


print("Area of the circle:", round(area, 2), "square units")
print("Circumference of the circle:", round(circumference, 2), "units")

Output:
Enter the radius of the circle: 5
Area of the circle: 78.54 square units
Circumference of the circle: 31.42 units

3. Rounding Grades:
import math

# Input the student's test score


test_score = float(input("Enter the student's test score: "))

# Round the score up and down


rounded_up = math.ceil(test_score)
rounded_down = math.floor(test_score)

# Display the rounded grades


print("Rounded-up grade:", rounded_up)
print("Rounded-down grade:", rounded_down)

OUTPUT:
Enter the student's test score: 87.5
Rounded-up grade: 88
Rounded-down grade: 87

4. Tax Calculator:
import math

# Input annual income


income = float(input("Enter the annual income: "))

# Round income up and down to the nearest thousand dollars


rounded_up_income = math.ceil(income)
4
MS BHAGYASHREE B.
Cambridge Facilitator
rounded_down_income = math.floor(income)

# Calculate tax based on rounded income (replace with your tax calculation formula)
tax = 0.2 * rounded_up_income # Example tax calculation, modify as needed

# Display the results


print("Rounded-up income: ", rounded_up_income)
print("Rounded-down income: ", rounded_down_income)
print("Tax to pay: ", tax)

OUTPUT:
Enter the annual income: 55000
Rounded-up income: 56000
Rounded-down income: 55000
Tax to pay: 11200.00

5. Temperature Conversion:
import math

# Input temperature in Fahrenheit


fahrenheit = float(input("Enter temperature in Fahrenheit: "))

# Convert to Celsius
celsius = (fahrenheit - 32) * 5/9

# Round the Celsius temperature using ceil and floor


rounded_up_celsius = math.ceil(celsius)
rounded_down_celsius = math.floor(celsius)

# Display the results


print("Temperature in Celsius (Rounded Up): ", rounded_up_celsius, "°C")
print("Temperature in Celsius (Rounded Down): ", rounded_down_celsius, "°C")

OUTPUT:
Enter temperature in Fahrenheit: 68
Temperature in Celsius (Rounded Up): 20 °C
Temperature in Celsius (Rounded Down): 20 °C

6. Price Adjustment:

import math

# Input the original price


original_price = float(input("Enter the original price: $"))

# Round the price up and down to the nearest dollar


rounded_up_price = math.ceil(original_price)
rounded_down_price = math.floor(original_price)
5
MS BHAGYASHREE B.
Cambridge Facilitator
# Display the rounded prices
print("Rounded-up price: $", rounded_up_price)
print("Rounded-down price: $", rounded_down_price)_down_celsius, "°C")

OUTPUT:
Enter the original price: $24.99
Rounded-up price: $ 25
Rounded-down price: $ 24

6
MS BHAGYASHREE B.
Cambridge Facilitator

You might also like