CSP converted pseudocode into Python
Converting the themed pseudocode into python
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
username = "Alice1234"
course_progress = 67
print("Username: " + username)
print("Course Progress (%): " + str(course_progress))
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
username = input("Enter username:")
password = input("Enter a secure password:")
print("Welcome " + username + "!")
print("Your password is " + password)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
secureKeys = [85, 92, 78, 90] # Using a list to generate a sum of secure keysx
keySum = 0
for key in secureKeys:
keySum = key + keySum
print("Verified keysum: " + str(keySum))
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
passwordStrengthScore=int(88)
def isPasswordSecure(passwordStrengthScore): # Procedure to check password security
if passwordStrengthScore >= 80:
return("Yes")
elif passwordStrengthScore >= 70:
return("Consider Strengthening")
else:
return("Strengthen immediately") # Algorithm to determine password security based on score
securityMessage = isPasswordSecure(passwordStrengthScore)
print("Password security status: " + (securityMessage))
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
passwordStrengthScore = 85
programSecurityScore = 92
firewallScore = 88
passwordStrengthWeight = 0.4
programSecurityWeight = 0.3
firewallWeight = 0.3
finalScore = (passwordStrengthScore * passwordStrengthWeight) + (programSecurityScore * programSecurityWeight) + (firewallScore * firewallWeight)
print("Final Security Score: " + str(finalScore))
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
confidence = int(input("From 0 to 100, how confident are you in your system security? "))
whatToDo = "Unknown"
if confidence >= 90:
whatToDo = "You're already good. Don't do anything" # Boolean logic to determine what to do based on confidence level
else:
if confidence >= 80:
whatToDo = "Run a basic antivirus scan."
else:
if confidence >= 70:
whatToDo = "Run a complete antivirus scan."
else:
if confidence >= 60:
whatToDo = "Use a trusted third party antivirus and do a scan"
else:
whatToDo = "Reinstall your OS" # Algorithm to determine what action to take based on confidence level
print("What you should do: " + whatToDo)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
print("Cybersecurity Threat Entry System")
threats = []
threatCount = 0
totalRisk = 0
continueEntry = "yes"
while continueEntry != "no":
threat = int(input("Add a cybersecurity threat level: ")) # List of cybersecurity threats to calculate total risk score
threats.append(threat)
threatCount += 1
totalRisk += threat
continueEntry = input("Continue entering threats? (no to stop)") # Algorithm to enter cybersecurity threats and calculate total risk score
print("List of threats: " + threats)
print("Total threats entered: " + threatCount)
print("Total risk score: " + totalRisk)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
def calculate_average(risk_scores):
total = 0
count = 0
for score in risk_scores:
total += score
count += 1
if count > 0:
average = total / count
return average
else:
return 0
risk_scores = [85, 92, 78, 95, 88] # Using risk scores to calculate average security score
result = calculate_average(risk_scores)
print("Average security score:", result)
print("Risk Scores:", risk_scores)
m
if result >= 90:
print("Security Status: Excellent")
else:
print("Security Status: Needs Improvement")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
def find_threat(threats, threat_to_find):
index = 1
for threat in threats:
if threat == threat_to_find:
return index
index += 1
return -1
my_threats = ["Virus", "Malware", "Keylogger", "Worm"] # Generating a list of cybersecurity threats to search for a specific threat
search_for = input("Enter the threat you are looking for...")
position = find_threat(my_threats, search_for)
if position > 0:
print("Found threat at position:", position) # Boolean logic to find a specific cybersecurity threat in a list
else:
print("You don't have that threat :)")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
threats = ["malware", "phishing", "virus", "keylogger"]
print("Initial:", threats)
threats.append("ransomware")
print("After APPEND:", threats)
threats.insert(2, "broken firewall")
print("After INSERT at 2:", threats)
threats.pop(3)
print("After REMOVE at 3:", threats)
length = len(threats)
print("List length:", length) # Modifying a list to generate a list of cybersecurity threats
for threat in threats:
print("Threat:", threat)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
def find_threat(threat_list, target_threat):
index = 0
for threat in threat_list:
if threat == target_threat:
return index
index += 1
return -1
threats = ["Malware", "Phishing", "Ransomware", "Spyware"]
risk_scores = [92, 85, 88, 76]
search_threat = input("Enter cybersecurity threat to search:")
position = find_threat(threats, search_threat)
if position >= 0:
threat_risk = risk_scores[position]
print("Threat found at position:", position + 1)
print("Risk score:", threat_risk)
else:
print("Threat not found in database")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Python task #1
View IPYNB Source
%%python
# CODE_RUNNER: Python task #1
def find_threat_risk(threats, risk_scores, target_threat):
index = 0
for threat in threats:
if threat == target_threat:
risk = risk_scores[index]
return risk
index += 1
return -1 # Algorithm to find the risk score of a specific cybersecurity threat in a list
threats = ["Malware", "Phishing", "Ransomware", "Spyware"] # List to store cybersecurity threats
risk_scores = [92, 85, 88, 76]
search_threat = input("Enter cybersecurity threat:")
result = find_threat_risk(threats, risk_scores, search_threat)
if result > 0: # Boolean logic to find the risk score of a specific cybersecurity threat in a list
print("Risk score for " + search_threat + ":", result)
else:
print("Threat not found")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...