diff --git a/Latoya's student_code.py b/Latoya's student_code.py new file mode 100644 index 0000000..1194093 --- /dev/null +++ b/Latoya's student_code.py @@ -0,0 +1,198 @@ +"""Learning Outcome: Functions""" +def sum_of_squares(n: int): + for i in range(1, n + 1): + sum = i ** 2 + return sum + if n < 0: + raise ValueError("n must be a postive integer") + +def evaluate_performance(grades: list, min_pass: int): + avg = sum(grades) / len(grades) + return "Pass" if avg >= min_pass else "Fail" + if not grades: + return "Fail" + +def calculate_cumulative_performance(scores: dict): + average = sum(scores.values()) / len(scores) + below_average = [] + for subject, score in scores.items(): + if score < avg: + below_average.append(subject) + return {"average": average, "below_average_subjects": below_average} + + if not scores: + return {"average": 0, "below_average_subjects": []} + +def analyze_improvement(scores: list): + if len(scores) < 2: + return {"trend": "neutral", "improved": False} + + diff = scores[-1] - scores[0] + + if diff > 0: + return {"trend": "positive", "improved": True + elif diff < 0: + return {"trend": "negative", "improved": False} + else: + return {"trend": "neutral", "improved": False} + + +def rank_students(students: list[tuple[str, int]]): + sorted_students = sorted(students, key=get_score, reverse=True) + return sorted_students + +"""Learning Outcome: Basic Loops""" +def even_numbers(n: int): + for i in range(1, n + 1): + if i % 2 == 0: + return i + pass + +def odd_numbers(n: int): + for i in range(1, n + 1): + if i % 2 != 0: + return i + +def sum_multiples_of_num(num: int, length: int): + for i in range(1, length + 1): + sum = num * i + return sum + pass + +def skip_num(n: int, length: int): + for i in range(1, length + 1): + if i != n: + return i +def break_test(n: int, length: int): + result = [] + for i in range(1, length + 1): + if i == n: + break + result.append(i) + return result + pass + +def sum_numbers_until_zero(nums: list): + total = 0 + for num in nums: + if num == 0: + break + total += num + return total + pass + +def count_positive_numbers(nums: list): + count = 0 + for num in nums: + if num > 0: + count += 1 + return count + pass + +def sum_dictionary_values(dictionary: dict): + return sum(dictionary.values()) + pass + +def sum_unique_elements(elements: list): + return sum(set(elements)) + pass + +def skip_divisible_by_num(n: int, length: int): + result = [] + for i in range(1, length + 1): + if i % n != 0: + result.append(i) + return result + pass + +"""Learning Outcome: Processing Data""" + +def square_numbers(nums: list): + for num in nums: + square = num ** 2 + return square + pass + +def transform_string(input: str, transform: str): + if transform == "capitalize": + return input.capitalize() + elif transform == "upper": + return input.upper() + elif transform == "lower": + return input.lower() + else: + raise ValueError("Unknown transformation type") + pass + +def sum_and_average(nums: list[int]): + total = sum(nums) + average = total / len(nums) + return (total, average) + if not nums: + return (0, 0) + pass + +def word_frequency_count(words: list[str]): + freq = {} + for word in words: + freq[word] = freq.get(word, 0) + 1 + return freq + pass + +def filter_even_numbers(nums: list[int]): + for num in nums: + if num % 2 == 0: + return num + pass + +"""Learning Outcome: Simple Algorithms(Problem Solving)""" + +def find_median(nums: list[int]): + """ + Find the median of a list of numbers. + + Parameters: + nums (list[int]): A list of integers. + + Returns: + float: The median value of the list. + + Raises: + ValueError: If the list is empty. + """ + pass + +def reverse_string(input: str): + reversed_text = input("Enter Text: ") + for char in input: + reversed_text = char + reversed_text + return reversed_text + + pass + +def largest_number(nums: list[int]): + largest = nums[0] + for num in nums: + if num > largest: + largest = num + return largest + + if not nums: + return None + pass + +def is_prime(n: int): + """ + Check if a number is prime. + + Parameters: + n (int): The number to check. + + Returns: + bool: True if the number is prime, False otherwise. + """ + pass + +def count_character_occurrences(word_sentence: str, char_count: str): + return word_sentence.count(char_count) + pass diff --git a/student_code.py b/student_code.py deleted file mode 100644 index d7fdfd0..0000000 --- a/student_code.py +++ /dev/null @@ -1,322 +0,0 @@ -"""Learning Outcome: Functions""" -def sum_of_squares(n: int): - """ - Calculate the sum of the squares of all integers from 1 to n. - - Parameters: - n (int): A non-negative integer up to which the squares will be summed. - - Returns: - int: The sum of the squares of all integers from 1 to n. - - Raises: - ValueError: If n is a negative integer. - """ - pass - -def evaluate_performance(grades: list, min_pass: int): - """ - Evaluate the performance based on a list of grades and a minimum passing grade. - - Parameters: - grades (list): A list of integers representing student grades. - min_pass (int): The minimum average grade required to pass. - - Returns: - str: "Pass" if the average grade is greater than or equal to min_pass, otherwise "Fail". - """ - pass - -def calculate_cumulative_performance(scores: dict): - """ - Calculate the cumulative performance based on student scores. - - Parameters: - scores (dict): A dictionary where keys are subject names and values are the corresponding scores. - - Returns: - dict: A dictionary containing the average score and a list of subjects where the score is below average. - """ - pass - -def analyze_improvement(scores: list): - """ - Analyze the improvement trend based on a list of scores. - - Parameters: - scores (list): A list of integers representing scores over time. - - Returns: - dict: A dictionary containing the trend of improvement ("positive", "negative", or "neutral") - and a boolean indicating whether there has been an improvement. - """ - pass - -def rank_students(students: list[tuple[str, int]]): - """ - Rank students based on their scores. - - Parameters: - students (list): A list of tuples where each tuple contains a student's name and their score. - - Returns: - list: A sorted list of tuples in descending order based on scores. - """ - pass - -"""Learning Outcome: Basic Loops""" -def even_numbers(n: int): - """ - Generate a list of even numbers from 1 to n. - - Parameters: - n (int): The upper limit for generating even numbers. - - Returns: - list: A list of even integers from 1 to n. - """ - pass - -def odd_numbers(n: int): - """ - Generate a list of odd numbers from 1 to n. - - Parameters: - n (int): The upper limit for generating odd numbers. - - Returns: - list: A list of odd integers from 1 to n. - """ - pass - -def sum_multiples_of_num(num: int, length: int): - """ - Calculate the sum of multiples of a given number up to a specified length. - - Parameters: - num (int): The number whose multiples are to be summed. - length (int): The upper limit for the range of multiples. - - Returns: - int: The sum of multiples of num from 1 to length. - """ - pass - -def skip_num(n: int, length: int): - """ - Generate a list of numbers from 1 to length, skipping a specific number. - - Parameters: - n (int): The number to skip. - length (int): The upper limit for generating numbers. - - Returns: - list: A list of integers from 1 to length, excluding n. - """ - pass - -def break_test(n: int, length: int): - """ - Generate a list of numbers from 1 to length, stopping when a specific number is encountered. - - Parameters: - n (int): The number at which to stop adding to the list. - length (int): The upper limit for generating numbers. - - Returns: - list: A list of integers from 1 to length, excluding n and stopping before it. - """ - pass - -def sum_numbers_until_zero(nums: list): - """ - Calculate the sum of numbers in a list until a zero is encountered. - - Parameters: - nums (list): A list of integers. - - Returns: - int: The sum of integers in the list up to (but not including) the first zero. - """ - pass - -def count_positive_numbers(nums: list): - """ - Count the number of positive integers in a list. - - Parameters: - nums (list): A list of integers. - - Returns: - int: The count of positive integers in the list. - """ - pass - -def sum_dictionary_values(dictionary: dict): - """ - Calculate the sum of all values in a dictionary. - - Parameters: - dictionary (dict): A dictionary with numeric values. - - Returns: - int: The sum of all values in the dictionary. - """ - pass - -def sum_unique_elements(elements: list): - """ - Calculate the sum of unique elements in a list. - - Parameters: - elements (list): A list of integers. - - Returns: - int: The sum of unique integers in the list. - """ - pass - -def skip_divisible_by_num(n: int, length: int): - """ - Generate a list of numbers from 1 to length, skipping those that are divisible by a specific number. - - Parameters: - n (int): The number to skip multiples of. - length (int): The upper limit for generating numbers. - - Returns: - list: A list of integers from 1 to length, excluding those divisible by n. - """ - pass - -"""Learning Outcome: Processing Data""" - -def square_numbers(nums: list): - """ - Calculate the square of each number in a list. - - Parameters: - nums (list): A list of integers. - - Returns: - list: A list containing the squares of the input integers. - """ - pass - -def transform_string(input: str, transform: str): - """ - Transform a string based on the specified transformation type. - - Parameters: - input (str): The string to be transformed. - transform (str): The type of transformation ('capitalize', 'upper', 'lower'). - - Returns: - str: The transformed string. - - Raises: - ValueError: If the transformation type is unknown. - """ - pass - -def sum_and_average(nums: list[int]): - """ - Calculate the sum and average of a list of numbers. - - Parameters: - nums (list[int]): A list of integers. - - Returns: - tuple: A tuple containing the sum and average of the numbers. - """ - pass - -def word_frequency_count(words: list[str]): - """ - Count the frequency of each word in a list. - - Parameters: - words (list[str]): A list of words. - - Returns: - dict: A dictionary with words as keys and their frequencies as values. - """ - pass - -def filter_even_numbers(nums: list[int]): - """ - Filter out even numbers from a list. - - Parameters: - nums (list[int]): A list of integers. - - Returns: - list: A list containing only the even integers from the input list. - """ - pass - -"""Learning Outcome: Simple Algorithms(Problem Solving)""" - -def find_median(nums: list[int]): - """ - Find the median of a list of numbers. - - Parameters: - nums (list[int]): A list of integers. - - Returns: - float: The median value of the list. - - Raises: - ValueError: If the list is empty. - """ - pass - -def reverse_string(input: str): - """ - Reverse the given string. - - Parameters: - input (str): The string to be reversed. - - Returns: - str: The reversed string. - """ - pass - -def largest_number(nums: list[int]): - """ - Find the largest number in a list. - - Parameters: - nums (list[int]): A list of integers. - - Returns: - int or None: The largest number in the list, or None if the list is empty. - """ - pass - -def is_prime(n: int): - """ - Check if a number is prime. - - Parameters: - n (int): The number to check. - - Returns: - bool: True if the number is prime, False otherwise. - """ - pass - -def count_character_occurrences(word_sentence: str, char_count: str): - """ - Count the occurrences of a character in a given sentence. - - Parameters: - word_sentence (str): The sentence in which to count occurrences. - char_count (str): The character to count. - - Returns: - int: The number of occurrences of the character in the sentence. - """ - pass \ No newline at end of file