Level 2
Level 2
In [1]:
import random
def guessing_game():
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
localhost:8888/notebooks/Untitled23.ipynb?kernel_name=python3 1/4
8/28/23, 11:42 AM Untitled23 - Jupyter Notebook
In [2]:
import random
localhost:8888/notebooks/Untitled23.ipynb?kernel_name=python3 2/4
8/28/23, 11:42 AM Untitled23 - Jupyter Notebook
In [6]:
import re
def password_strength(password):
# Check length
if len(password) < 8:
return "Weak: Password should be at least 8 characters long."
In [7]:
def generate_fibonacci(n):
fibonacci_sequence = [0, 1] # Initialize the sequence with the first two terms
return fibonacci_sequence
localhost:8888/notebooks/Untitled23.ipynb?kernel_name=python3 3/4
8/28/23, 11:42 AM Untitled23 - Jupyter Notebook
In [9]:
def count_word_occurrences(filename):
word_counts = {} # Dictionary to store word counts
try:
with open(filename, 'r') as file:
for line in file:
words = line.split()
for word in words:
word = word.lower() # Convert to lowercase to treat words case-insen
word = word.strip(".,!?\"'()[]") # Remove common punctuation
if word:
if word in word_counts:
word_counts[word] += 1
else:
word_counts[word] = 1
except FileNotFoundError:
print("File not found.")
return word_counts
localhost:8888/notebooks/Untitled23.ipynb?kernel_name=python3 4/4