Computer Science 2
*********
*********


Click to access your sign on code for Code High School.
Or 
Sign into Code High School - click here 
and Use the sign in code: 315850


*********
*********
 
  
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

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

Assignment
-Running Python in a Kali Linux environment 

Mr. Cusack will lecture on this. 
  
Cyber Range Sign on ids and passwords (Period 7)
Click here and get your id and password.

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

Notes:

sudo apt install python3-pip

python3 --version

python3    

control-D to exit python

 









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

Assignment
-Running Python in a Kali Linux environment 

Mr. Cusack will lecture on this. 
  
Cyber Range Sign on ids and passwords (Period 7)
Click here and get your id and password.

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

Notes:
To edit and run a python program in Linux

Sample:
nano test.py
-Type print("Lastname");
close nano

Run the python program.
Python3 test.py

Show Mr. Cusack

See code below:
Your file name will be P7_GuessNum_lastname.py
see code below: (a couple of syntax error are in the program.)
 
control-D to exit python

*********
*********
Due Date: January 25, 2024
Use nano P7_GuessNum_lastname.py
Type the code.
Close nano.

Run the program
python3 P7_GuessNum_lastname.py

Your files to turn in:

- After you code your program you need to produce the follow artifacts.
P7_GuessNum_lastname.png (Screen Print of the python program)
P7_GuessNum_lastname.py (Actual python program)
P7_GuessNum_lastname.mp4 (Video of python program running)

Drop off your up to 7 files into google classroom.

Due Date: Feb 19, 2024

 

*********
*********
Due Date: Feb 19, 2024
Assignment
-Running Python in a Kali Linux environment 
-Generate Math Questions
The code is below:
---------------------------------------------------------
import random

def generate_addition_question():
    num1 = random.randint(1, 100)
    num2 = random.randint(1, 100)
    answer = num1 + num2
    question = f"What is {num1} + {num2}?"
    return question, answer

def generate_subtraction_question():
    num1 = random.randint(1, 100)
    num2 = random.randint(1, num1)
    answer = num1 - num2
    question = f"What is {num1} - {num2}?"
    return question, answer

def generate_multiplication_question():
    num1 = random.randint(1, 20)
    num2 = random.randint(1, 20)
    answer = num1 * num2
    question = f"What is {num1} * {num2}?"
    return question, answer

def generate_division_question():
    num1 = random.randint(1, 100)
    factors = [i for i in range(1, num1 + 1) if num1 % i == 0]
    num2 = random.choice(factors)
    answer = num1 // num2
    question = f"What is {num1} / {num2}?"
    return question, answer

def generate_math_question():
    question_type = random.choice(["addition", "subtraction", "multiplication", "division"])
    if question_type == "addition":
        return generate_addition_question()
    elif question_type == "subtraction":
        return generate_subtraction_question()
    elif question_type == "multiplication":
        return generate_multiplication_question()
    else:
        return generate_division_question()

def main():
    num_questions = 5
    correct_answers = 0

    print("Welcome to the Math Quiz!")
    print("Answer the following questions:")

    for i in range(num_questions):
        question, answer = generate_math_question()
        print(f"\nQuestion {i+1}: {question}")
        user_answer = input("Your answer: ")

        if user_answer.isdigit() and int(user_answer) == answer:
            print("Correct!")
            correct_answers += 1
        else:
            print(f"Sorry, the correct answer is {answer}.")

    print(f"\nYou got {correct_answers} out of {num_questions} questions correct.")

if __name__ == "__main__":
    main()

---------------------------------------------------------

Run the program
python3 P7_MathQuestions_lastname.py

Your files to turn in:

- After you code your program you need to produce the follow artifacts.
P7_MathQuestions_lastname.png (Screen Print of the python program) (using the Kali Linux machine)
P7_MathQuestions_lastname.py (Actual python program) (Use the google document)
P7_MathQuestions_lastname.mp4 (Video of python program running in side the Kali Linux virtual machine)

Drop off your up to 3 files into google classroom.

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

This program chooses a random math term as the word for the player to guess. The player has six attempts to guess the word correctly by inputting letters one at a time. If the guessed letter is in the word, the program reveals its position in the word; otherwise, the player loses an attempt. If the player correctly guesses all the letters in the word within the given attempts, they win; otherwise, they lose.
Guess Math terms

*********
*********
Due Date: Feb 22, 2024
import random

def choose_word():
    math_terms = ["algebra", "geometry", "calculus", "trigonometry", "statistics", "probability", "equation", "fraction", "matrix", "variable"]
    return random.choice(math_terms)

def display_word(word, guessed_letters):
    displayed = ""
    for letter in word:
        if letter in guessed_letters:
            displayed += letter
        else:
            displayed += "_"
    return displayed

def get_guess(guessed_letters):
    while True:
        guess = input("Guess a letter: ").lower()
        if len(guess) != 1:
            print("Please enter a single letter.")
        elif not guess.isalpha():
            print("Please enter a letter.")
        elif guess in guessed_letters:
            print("You've already guessed that letter.")
        else:
            return guess

def play_hangman():
    word = choose_word()
    guessed_letters = []
    attempts = 6

    print("Welcome to Hangman - Math Terms Edition!")
    print("Try to guess the math term. You have 6 attempts.")

    while attempts > 0:
        print("\n" + display_word(word, guessed_letters))
        guess = get_guess(guessed_letters)
        guessed_letters.append(guess)

        if guess not in word:
            attempts -= 1
            print(f"Sorry, '{guess}' is not in the word. You have {attempts} attempts left.")
        
        if "_" not in display_word(word, guessed_letters):
            print("\nCongratulations! You've guessed the word:", word)
            break

    if attempts == 0:
        print("\nSorry, you ran out of attempts. The word was:", word)

if __name__ == "__main__":
    play_hangman()

---------------------------------------------------------

Run the program
python3 P7_MathTerms_lastname.py

Your files to turn in:

- After you code your program you need to produce the follow artifacts.
P7_MathTerms_lastname.png (Screen Print of the python program) (using the Kali Linux machine)
P7_MathTerms_lastname.py (Actual python program) (Use the google document)
P7_MathTerms_lastname.mp4 (Video of python program running in side the Kali Linux virtual machine)

Drop off your up to 3 files into google classroom.

*********
*********
Due Date: February 22, 2024

New Assignment (Mr. Cusack will talk about this more in class)

Purpose: Verify new Cyber Range id and password. Also, practice python.

Run this in interactive mode.

Starting screen recording for this sessions.
Name of saved file: PX_Interactive_lastname.mp4 (Video of you running the program)
Be sure to drop these off into google classroom.

Split the program into two parts
Half way into the program.
run the commands below
 
1. print("Hello my name is Joe Cusack") 2. x = 5 3. y = 8 4. z = -34 5. m = x + y + z 6. print("The value of x is: " + x) 7. print("The value of y is: " + y) 8. print("The value of z is: " + z) 9. print("The value of m is: " + m) 10. if m > 0: 11. print("Positive number") 12. else: 13. print("Negative number") l4. for i in range(10) 15. print("Value of i" + i) 16. greet("Hello World") 17. my_list = [20, 18, 16, 14, 12] 18. text = "awesome" 19. print(text.upper()) Insert bottom part for time. use nano to create a python file. example nano PX_rockPaper_lastname.py Be sure to create the following files: PX_rockPaper_lastname.py (Actual python program) PX_rockPaper_lastname.txt (Copy of python program (use google docs)) PX_rockPaper_lastname.png (Screen shot of program running) PX_rockPaper_lastname.mp4 (Video of you running the program) Be sure to drop these off into google classroom. Source code: from random import randint #create a list of play options t = ["Rock", "Paper", "Scissors"] #assign a random play to the computer computer = t[randint(0,2)] #set player to False player = False while player == False: #set player to True player = input("Rock, Paper, Scissors?") if player == computer: print("Tie!") elif player == "Rock": if computer == "Paper": print("You lose!", computer, "covers", player) else: print("You win!", player, "smashes", computer) elif player == "Paper": if computer == "Scissors": print("You lose!", computer, "cut", player) else: print("You win!", player, "covers", computer) elif player == "Scissors": if computer == "Rock": print("You lose...", computer, "smashes", player) else: print("You win!", player, "cut", computer) else: print("That's not a valid play. Check your spelling!") #player was set to True, but we want it to be False so the loop continues player = False computer = t[randint(0,2)]

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