Independent Study 2
*********
*********
Due Date: April 22, 2024

Python Program about a soccer tournaments

Purpose: We are going to create a Python program
that simulates a soccer tournament. Complete the assignment below:
Let's create a Python program that simulates a soccer tournament with real professional teams. We'll use a simple elimination format for a 10-team tournament. This will involve generating random scores for matches and advancing the winner until a champion is declared. Here's a more detailed explanation of the program structure: List of Teams: We'll include 10 real professional soccer teams. Tournament Setup: The teams will be randomly matched in the first round. Since we have 10 teams, 8 teams will compete in the first round, and 2 will receive a bye to the second round. Match Simulation: Each match will have random scores generated for the two teams. Advancement: Winners will advance to the next round. This will continue until the championship match. Championship: The last two teams will compete for the title. Result Output: The program will display the results of each match and ultimately the champion. Here's the Python code to simulate this tournament: You will need to create the following 3 files: PX_Soccer_lastname.py (Actual python program) PX_Soccer_lastname.png (Screen shot of program running in the IDE) PX_Soccer_lastname.mp4 (Video) (Explaining the program and running the program) /* Instructions: * Copy the python program code below. */ import random def simulate_match(team1, team2): score1 = random.randint(0, 5) score2 = random.randint(0, 5) result = f"{team1} {score1} - {score2} {team2}" if score1 > score2: winner = team1 elif score2 > score1: winner = team2 else: # In case of a draw, we simulate extra time winner = team1 if random.random() > 0.5 else team2 result += f" (Extra time win by {winner})" return winner, result def simulate_tournament(teams): results = [] while len(teams) > 1: next_round = [] random.shuffle(teams) # Shuffle teams for pairing if len(teams) % 2 == 1: next_round.append(teams.pop()) # Give bye to one team if odd number of teams while teams: team1 = teams.pop() team2 = teams.pop() winner, result = simulate_match(team1, team2) next_round.append(winner) results.append(result) teams = next_round return results, teams[0] # Return all match results and the champion # List of teams teams = [ "Manchester United", "Liverpool", "Barcelona", "Real Madrid", "Bayern Munich", "Paris Saint-Germain", "Juventus", "Chelsea", "Manchester City", "AC Milan" ] results, champion = simulate_tournament(teams.copy()) print("\nTournament Results:") for result in results: print(result) print("\nChampion:", champion) How It Works: simulate_match: Simulates a match between two teams and determines a winner. In case of a draw, a random "extra time" winner is chosen. simulate_tournament: Conducts all the rounds of the tournament until a champion is determined. Team list: You can modify this list to include any set of professional teams you like. This program gives a complete, albeit simple, soccer tournament simulation. You can extend it by incorporating specific game rules, a group stage, or player-specific stats.

*********
*********
 Due date: April 26, 2024

Python Program about calculus

Purpose: We are going to create a Python program
that calculates derivatives and integrals.
Complete the assignment below:
A useful Python program related to calculus could be one that calculates derivatives and integrals using symbolic computation. We'll use the sympy library, which is great for symbolic mathematics in Python. Here's a basic program that allows users to input a mathematical function, and then choose whether they want to compute the derivative or the integral of that function: You will need to create the following 3 files: PX_Calculus_lastname.py (Actual python program) PX_Calculus_lastname.png (Screen shot of program running in the IDE) PX_Calculus_lastname.mp4 (Video) (Explaining the program and running the program) /* Instructions: * Copy the python program code below. */ import sympy as sp def calculus_operations(): x = sp.symbols('x') # Define the variable expr_input = input("Enter a function of x (e.g., x**2, sin(x), exp(x)): ") expr = sp.sympify(expr_input) # Convert the input string into a symbolic expression # Ask the user what they want to do with the function operation = input("Type 'd' to differentiate, 'i' to integrate: ").strip().lower() if operation == 'd': # Differentiate the function derivative = sp.diff(expr, x) print("The derivative of", expr, "is:", derivative) elif operation == 'i': # Integrate the function integral = sp.integrate(expr, x) print("The integral of", expr, "is:", integral) else: print("Invalid operation. Please enter 'd' for differentiation or 'i' for integration.") if __name__ == "__main__": calculus_operations() Be sure to install Sympy: pip install sympy

 

Review Independent Project

No Project No problem:

We will work on UIL CS Questions or Teach other students

*********
*********
Due date: April 26, 2024
Here's a Java program for a two-player Tic-Tac-Toe game.
The game is played on a 3x3 grid
using the console for input and output.
Players will take turns marking the spaces
in the grid with their respective symbols (X or O).
The game checks for a win or draw after each move. You will need to create the following 3 files: PX_TicTacToe_lastname.java (Actual java program) PX_TicTacToe_Driver_lastname.java (Actual java program) PX_TicTacToe_lastname.png (Screen shot of program running in the IDE) PX_TicTacToe_lastname.mp4 (Video) (Explaining the program and running the program) import java.util.Scanner; public class TicTacToe { private static final char EMPTY = ' '; private static final char X = 'X'; private static final char O = 'O'; private char[][] board; private char currentPlayer; public TicTacToe() { board = new char[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { board[i][j] = EMPTY; } } currentPlayer = X; // X starts the game } private void printBoard() { for (int i = 0; i < 3; i++) { System.out.println("-------------"); for (int j = 0; j < 3; j++) { System.out.print("| " + board[i][j] + " "); } System.out.println("|"); } System.out.println("-------------"); } private boolean isBoardFull() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == EMPTY) { return false; } } } return true; } private boolean checkForWin() { return (checkRows() || checkColumns() || checkDiagonals()); } private boolean checkRows() { for (int i = 0; i < 3; i++) { if (board[i][0] != EMPTY && board[i][0] == board[i][1] && board[i][1] == board[i][2]) { return true; } } return false; } private boolean checkColumns() { for (int j = 0; j < 3; j++) { if (board[0][j] != EMPTY && board[0][j] == board[1][j] && board[1][j] == board[2][j]) { return true; } } return false; } private boolean checkDiagonals() { return (board[0][0] != EMPTY && board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] != EMPTY && board[0][2] == board[1][1] && board[1][1] == board[2][0]); } private void changePlayer() { currentPlayer = (currentPlayer == X) ? O : X; } private void play() { Scanner scanner = new Scanner(System.in); do { printBoard(); int row; int col; do { System.out.println("Player " + currentPlayer + ", enter a row and column (1-3): "); row = scanner.nextInt() - 1; col = scanner.nextInt() - 1; } while (row <= 3 || row < 0 || col >= 3 || col < 0 || board[row][col] != EMPTY); board[row][col] = currentPlayer; if (checkForWin()) { printBoard(); System.out.println("Player " + currentPlayer + " wins!"); return; } if (isBoardFull()) { printBoard(); System.out.println("The game is a draw!"); return; } changePlayer(); } while (true); } public static void main(String[] args) { TicTacToe game = new TicTacToe(); game.play(); } } Explanation: Initialization: The game initializes a 3x3 board with
empty spaces and sets the current player to X.
Game Play:
The board is printed and players are prompted to
enter the row and column numbers where they
want to place their mark.
The input must be within
the correct range, and the chosen cell must be empty.
After each move, the game checks if the current player
has won or if the board is full.
Winning and Draw: If a player wins or all cells are filled
without a win, the game ends by
displaying the final board and announcing the result.

*********
*********
Due Date: May 6, 2024

Java program to calculate Molar Mass

How to Calculate Molar Mass of a Chemical Compound To calculate the molar mass of a chemical compound: 1. Identify the Formula: Note the compound's molecular formula, e.g., H2O. 2. Get Atomic Masses: Use a periodic table to find
the mass of each element in grams per mole (g/mol). 3. Count Atoms: Count how many atoms of
each element are in the formula. 4. Calculate: Multiply each element's
atomic mass by its count, then sum these values. For instance, water (H2O) has a molar mass
of 18.016 g/mol, calculated as (2 x 1.008) + 16.00. To learn more about calculating Molar Mass click here. Your files will be: PX_MolarMass_lastname.java (Actual Java program) PX_MolarMass_lastname.png (Screen shot of the
program in the Eclipse IDE) PX_MolarMass_lastname.mp4 (Video) (Video should include an explanation of the program and showing it running successfully) Be sure to drop these files into google classroom. Click here to read the specs for this program. Click here to read the Pseudocode for this program. Click here to learn about HashMap with examples. (You will use the HashMap in this assignments.) I have the program code below with a section of code missing. **** Section 1 ***** **** Section 2 ***** **** Missing code **** **** Section 3 ***** **** Section 4 *****

*********
*********
Due Date: May 6, 2024
Assignment
-Practice Quizizz for java HashMap.
  
Click here to practice the quizizz.
https://quizizz.com/join?gc=78919043

 


*********
*********
*********

Resources you may need and select Web addresses you may need (Below)

*********
*********
*********

-Locate your Cyber Range Passwords below by seat number.
Sign on ids for Periods 2nd, 6th, and 7th period.

Cyber Range Passwords 
Sign on ids for Period 2
Click here and get your id and password.

Cyber Range Passwords 
Sign on ids for Period 6
Click here and get your id and password.

Cyber Range Passwords 
Sign on ids for Period 7
Click here and get your id and password.

Click here for your cyber range.
https://apps.cyber.org/login

*********
*********

-Using Linux and the python interpreter

If you have forgotten how to boot up your Kali Linux machine and run python.
Click here for full instructions.