Due Date: January 25, 2024
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
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: January 25, 2024
Assignment
-Running Python in a Kali Linux environment
-Generate the fibonacci Sequence
--------------------------------------
def fibonacci_sequence(n):
"""
Generate a Fibonacci sequence up to the nth term.
:param n: Number of terms in the Fibonacci sequence to generate.
:return: List containing the Fibonacci sequence.
"""
sequence = [0, 1]
for i in range(2, n):
next_term = sequence[i-1] + sequence[i-2]
sequence.append(next_term)
return sequence
def main():
try:
num_terms = int(input("Enter the number of terms for the Fibonacci sequence: "))
if num_terms <= 0:
print("Please enter a positive integer.")
else:
fibonacci = fibonacci_sequence(num_terms)
print("Fibonacci Sequence up to", num_terms, "terms:")
print(fibonacci)
except ValueError:
print("Invalid input! Please enter a valid integer.")
if __name__ == "__main__":
main()
--------------------------------------
Run the program
python3 P7_fibonacci_lastname.py
Your files to turn in:
- After you code your program you need to produce the follow artifacts.
P7_fibonacci_lastname.png (Screen Print of the python program)
P7_fibonacci_lastname.py (Actual python program)
P7_fibonacci_lastname.mp4 (Video of python program running)
Drop off your up to 3 files into google classroom.
Due Date: Feb 7, 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.