Homework:

Assignment 1: How do you use functions?

Create a turtle python function that...

  1. Takes a single parameter as the number of sides
  2. Outputs a shape corresponding to the number of sides
  3. Call the function with the argument being a variable with the user input

Hint:

import turtle

pen = turtle.Turtle(); # pen is the instance of Turtle which has methods that do certain actions

# Necessary methods:
# .forward(50) - moves the pen forward 50 units
# .right(angle) - turns the pen angle degrees right   
# OR
# .left(angle) - turns the pen angle degrees left

def shape(sides):
    #code here

numsides = input('How many sides do yoUUUU wnat in YOUUUURRRR shape?!?!!?!: ')
shape(int(numsides))

Assignment 2:

Create a student class that...

  1. Has a constructor that takes three parameters as attributes
    • zipcode
    • name
    • grade
  2. Three getter methods to access the name, zipcode, and grade
  3. Three setter methods to modify the name, zipcode, and grade
  4. A to string method that returns the three instance variables in this format - "My name is {name}. My zipcode is {zipcode}. My grade is {grade}
  5. Create an instance of the class that corresponds with you
#Homework 1
#Base Verision

def distinct_values(arr):
    distinct_arr = []
    
    for item in arr:
        if item not in distinct_arr:
            distinct_arr.append(item)
    
    return distinct_arr

arr1 = [2, 1, 3, 2, 0, 2, 0, 0, 4, 2, 0, 0, 0, 2, 0, 0, 1, 2, 3, 0, 7, 4, 5, 2, 1, 2, 3, 4, 6]
distinct_arr1 = distinct_values(arr1)

print(distinct_arr1)

# Extra Verision with occurances
from collections import Counter

def enhanced_distinct_values(arr):
    distinct_counts = Counter(arr)
    distinct_arr = sorted(distinct_counts.keys())
    total_count = sum(distinct_counts.values())

    result = []
    for item in distinct_arr:
        count = distinct_counts[item]
        result.append((item, count))

    return result, total_count

def display_histogram(distinct_counts):
    print("Distinct Value Histogram:")
    for item, count in distinct_counts:
        print(f"Number: {item}, Occurrences: {count} {'*' * count}")

arr1 = [2, 1, 3, 2, 0, 2, 0, 0, 4, 2, 0, 0, 0, 2, 0, 0, 1, 2, 3, 0, 7, 4, 5, 2, 1, 2, 3, 4, 6]
distinct_counts_arr1, total_count_arr1 = enhanced_distinct_values(arr1)

display_histogram(distinct_counts_arr1)
print(f"Total Count: {total_count_arr1}")


[2, 1, 3, 0, 4, 7, 5, 6]
Distinct Value Histogram:
Number: 0, Occurrences: 9 *********
Number: 1, Occurrences: 3 ***
Number: 2, Occurrences: 8 ********
Number: 3, Occurrences: 3 ***
Number: 4, Occurrences: 3 ***
Number: 5, Occurrences: 1 *
Number: 6, Occurrences: 1 *
Number: 7, Occurrences: 1 *
Total Count: 29
#BASE VERISION
# Homework 2


class Student:
    def __init__(self, name, zipcode, grade):
        self.name = name
        self.zipcode = zipcode
        self.grade = grade

    def get_name(self):
        return self.name

    def set_name(self, name):
        self.name = name

    def get_email(self):
        return self.zipcode

    def set_email(self, zipcode):
        self.zipcode = zipcode

    def get_grade(self):
        return self.grade

    def set_grade(self, grade):
        self.grade = grade

    def __str__(self):
        return f"My name is {self.name}. My zipcode is {self.zipcode}. My grade is {self.grade}"

# Creating an instance of the Student class
my_student = Student("ronit", "ronit.joe@gmail.com", 90)

print("Original Information:")
print(my_student)
my_student.set_name("Billie Joe Armstrong")
my_student.set_email("green.day@zipcode.com")
my_student.set_grade(95)

print("\nNew Data:")
print(my_student)

#EXTRA VERISION
students = []

# Repeating loop to add new students
num_students = int(input("Enter the number of students to add: "))
for i in range(num_students):
    name = input("Enter student name: ")
    zipcode = input("Enter student zipcode: ")
    grade = float(input("Enter student grade: "))
    
    new_student = Student(name, zipcode, grade)
    students.append(new_student)

# Display the added students
print("\nList of Students:")
for student in students:
    print(student)
Original Information:
My name is ronit. My zipcode is ronit.joe@gmail.com. My grade is 90

New Data:
My name is Billie Joe Armstrong. My zipcode is green.day@zipcode.com. My grade is 95

List of Students:
My name is Ronti. My zipcode is ronitt@gmail.com. My grade is 98.0
My name is Vance. My zipcode is vance@sigeoc.om. My grade is 97.0
My name is Bill. My zipcode is billisdumb@stupid.com. My grade is 3.0