diff --git a/week-2/assignment-2/mini_project.py b/week-2/assignment-2/mini_project.py new file mode 100644 index 0000000..87dd084 --- /dev/null +++ b/week-2/assignment-2/mini_project.py @@ -0,0 +1,8 @@ +fahrenheit = float(input("Enter a temperature in Fahrenheit:")) + +celcius = (fahrenheit - 32) * 5 / 9 + +print(f'{fahrenheit:.1f}°F is {celcius:.1f}°C.') + + + \ No newline at end of file diff --git a/week-2/assignment-2/warmup1.py b/week-2/assignment-2/warmup1.py new file mode 100644 index 0000000..f7ae2bf --- /dev/null +++ b/week-2/assignment-2/warmup1.py @@ -0,0 +1,3 @@ +print ('Python is working!') + + diff --git a/week-2/assignment-2/warmup2.py b/week-2/assignment-2/warmup2.py new file mode 100644 index 0000000..cd5eef7 --- /dev/null +++ b/week-2/assignment-2/warmup2.py @@ -0,0 +1,10 @@ +#navigations commands I used: +# cd python-intro-homework +#ls +#cd week-2 +#cd assignment-2 +#pwd + + +date = input("What is today's date? ") +print(f'You said today is {date}.') diff --git a/week-2/assignment-2/warmup3.py b/week-2/assignment-2/warmup3.py new file mode 100644 index 0000000..7654760 --- /dev/null +++ b/week-2/assignment-2/warmup3.py @@ -0,0 +1,7 @@ +# git log --oneline output: +# 194c8fa add warmup2.py +# 294742d add week 2 folder +# 58d836d Add files via upload +# d8c0c05 Update README.md + +print("This week I learned how to use Python input, work with strings, and run Git commands in the terminal!") diff --git a/week-2/assignment-2/warmup4.py b/week-2/assignment-2/warmup4.py new file mode 100644 index 0000000..44072ed --- /dev/null +++ b/week-2/assignment-2/warmup4.py @@ -0,0 +1,16 @@ + +# 1. What the error message said: + # NameError: name 'naame' is not defined. Did you mean: 'name'? + +#2. What caused it: + # I misspelled the variable name as 'naame' inside the print statement + # and forgot to include input() on line 1, so Python didn't know what 'naame' was. + +#3. How I fixed it: + # I added input() to line 1 to capture the user's input and corrected + # the spelling of the variable to 'name' in the print statement.''' + +# Fixed, working code: + +name = input("What is your name? ") +print(f"Your name is {name}.") diff --git a/week-3/assignment-3/mini_project.py b/week-3/assignment-3/mini_project.py new file mode 100644 index 0000000..db455c5 --- /dev/null +++ b/week-3/assignment-3/mini_project.py @@ -0,0 +1,33 @@ +day = input('Please enter a day of the week: ').strip().lower() +time_of_day = input("Please enter a time of day (morning, afternoon, or evening): ").strip().lower() + +if day == "monday": + if time_of_day == "morning": + print("Activity: Go for an early morning walk!! ") + elif time_of_day == "afternoon": + print('Activity: Make yourself a yummy snack!! ') + elif time_of_day == "evening": + print('Activity: Make yourself a yummy and healthy dinner') + else: + print('Invalid time of day') +elif day == "saturday": + if time_of_day == "morning": + print('Activity: Make yourself a nice cup of coffee to start your day!!') + elif time_of_day == "afternoon": + print('Activity: Spend your afternoon in a park or somewhere outdoors') + elif time_of_day == "evening": + print('Activity: Go and have nice dinner with a special someone') + else: + print('Invalid time of day') +elif day == "sunday": + if time_of_day == "morning": + print('Activity: Visit a local farmers market!!') + elif time_of_day == "afternoon": + print('Activity: Visit family or friends') + elif time_of_day == "evening": + print('Activity: Movie night!!') + else: + print('Invalid time of day') +else: + print('Invalid day of the week. Please choose Monday, Saturday, or Sunday!') + diff --git a/week-3/assignment-3/warmup1.py b/week-3/assignment-3/warmup1.py new file mode 100644 index 0000000..df9a800 --- /dev/null +++ b/week-3/assignment-3/warmup1.py @@ -0,0 +1,20 @@ +score = 100 +if score >= 90: + grade = 'A' +elif score >= 80: + grade = 'B' +elif score >= 70: + grade = 'C' +elif score >= 60: + grade = 'D' +else: + grade = 'F' + +print(f'Score: {score}') +print(f'Grade: {grade}') + + + + + + diff --git a/week-3/assignment-3/warmup2.py b/week-3/assignment-3/warmup2.py new file mode 100644 index 0000000..8e85828 --- /dev/null +++ b/week-3/assignment-3/warmup2.py @@ -0,0 +1,13 @@ +age = int(input('What is your age ')) + +if age >=0 and age <= 12: + print('You are a Child. ') +elif age >= 13 and age <= 17: + print(' You are a Teen. ') +elif age >= 18 and age <= 64: + print(' You are an Adult. ') +elif age >= 65: + print('You are a Senior') +else: + print('Invalid Age') + diff --git a/week-3/assignment-3/warmup3.py b/week-3/assignment-3/warmup3.py new file mode 100644 index 0000000..bef1175 --- /dev/null +++ b/week-3/assignment-3/warmup3.py @@ -0,0 +1,14 @@ +# 'not True' is False and since one side is False False and False gives False +print(not True and False) + +# 'True or False' only needs one to ne True so it gives True +print(True or False and False) + +# 5 is greater than 3 so thats True and adding not flips True to False so its False. +print(not (5 > 3)) + +# 10 equals 10 is true, but 4 not equal to 4 is False. Both arent True 'and' gives False +print(10 == 10 and 4 != 4) + +# 'not False' is True, and 'not True' is False. It gives True +print(not False or not True) \ No newline at end of file diff --git a/week-3/assignment-3/warmup4.py b/week-3/assignment-3/warmup4.py new file mode 100644 index 0000000..84f6b5b --- /dev/null +++ b/week-3/assignment-3/warmup4.py @@ -0,0 +1,16 @@ +number = int(input('Enter a number: ')) + +if number > 0: + print(f'{number} is positive.') +elif number < 0: + print(f'{number} is negative.') +else: + print(f'{number} is zero. ') + + + +if number % 2 == 0: + print(f'{number} is even. ') + +else: + print(f'{number} is odd.') diff --git a/week-4/assignment-4/mini_project.py b/week-4/assignment-4/mini_project.py new file mode 100644 index 0000000..75cc5c8 --- /dev/null +++ b/week-4/assignment-4/mini_project.py @@ -0,0 +1,36 @@ +students = [ + {"name": "Jazmine", "score": 88, "subject": "Python"}, + {"name": "Luis", "score": 74, "subject": "Data"}, + {"name": "Sara", "score": 91, "subject": "Python"}, + {"name": "Marcus", "score": 68, "subject": "Web"}, + {"name": "Priya", "score": 95, "subject": "Data"}, + {"name": "Devon", "score": 72, "subject": "Python"}, + {"name": "Mia", "score": 83, "subject": "Web"}, + {"name": "Eli", "score": 79, "subject": "Data"}, +] + +highest_score = 0 +top_scorer_name = "" +total = 0 +subject = set() +high_scorers = [] + +for student in students: + if student["score"] > highest_score: + highest_score = student["score"] + top_scorer_name = student["name"] + + total += student["score"] + + + subject.add(student["subject"]) + + if student["score"] > 75: + high_scorers.append(student["name"]) + + average = total / len(students) + +print(f"Top scorer: {top_scorer_name} ({highest_score})") +print(f"Class average: {average}") +print(f"Subjects offered: {subject}") + diff --git a/week-4/assignment-4/warmup1.py b/week-4/assignment-4/warmup1.py new file mode 100644 index 0000000..e5124e7 --- /dev/null +++ b/week-4/assignment-4/warmup1.py @@ -0,0 +1,13 @@ +num = ["2", "4", "6", "8", "10", "12", "14", "16"] + +#first item +print(num[0]) + +#last item(negative index) +print(num[-1]) + +##slice, only the middle four numbers +print(num[2:6]) +#the full list in reverse +num.reverse() +print(num) \ No newline at end of file diff --git a/week-4/assignment-4/warmup2.py b/week-4/assignment-4/warmup2.py new file mode 100644 index 0000000..5a8a28e --- /dev/null +++ b/week-4/assignment-4/warmup2.py @@ -0,0 +1,10 @@ +student = {"name": "Genesis", + "Grade": "B", + 'subjects': ["english", "math", "history"]} + +for key, value in student.items(): + print(f"{key}: {value}") + +student["graduated"] = False + +print(student) \ No newline at end of file diff --git a/week-4/assignment-4/warmup3.py b/week-4/assignment-4/warmup3.py new file mode 100644 index 0000000..ec95ce6 --- /dev/null +++ b/week-4/assignment-4/warmup3.py @@ -0,0 +1,9 @@ +list1 = ["Python", "Java", "C++", "Javascript"] +list2 = ["HTML", "CSS", "Bash Script", "Javascript"] + +set1 = set(list1) +set2 = set(list2) + +print(set1.union(set2)) +print(set1.intersection(set2)) +print(set1.difference(set2)) \ No newline at end of file diff --git a/week-5/assignment-5/mini_project.py b/week-5/assignment-5/mini_project.py new file mode 100644 index 0000000..3e1e5c5 --- /dev/null +++ b/week-5/assignment-5/mini_project.py @@ -0,0 +1,59 @@ +numbers = [42, 17, 83, 5, 61, 29, 74, 8, 55, 93, 31, 66, 14, 47, 78, 3, 59, 22, 86, 40] + +def show_menu(): + print('=== Number Cruncher ===') + print('1. Find the minimum number') + print('2. Find the maximum number') + print('3. Search for a number') + print('4. Sort the list') + print('5. Quit') + + +running = True +while running: + show_menu() + choice = input("\nEnter your choice: ") + + ##user input validation + + if choice == '1': + min_number = numbers[0] + for number in numbers: + if number < min_number: + min_number = number + print(f'The minimum number is: {min_number}') + + elif choice == '2': + max_number = numbers[0] + for number in numbers: + if number > max_number: + max_number = number + print(f'The maximum number is: {max_number}') + + elif choice == '3': + search = input("Enter a number to search for: ") + found = False #this is set to keep track of if its found or not + + #this is to loop through every index of the list to find the number + + for i in range(len(numbers)): + if numbers[i] == search: + print(f'Found {search} at index {i}.') + found = True + break + if not found: + print(f'{search} was not found in the list.') + + ##This is bubble sort without .sort() or sorted() + elif choice == '4': + + for i in range(len(numbers)): + for j in range(0, len(numbers) - i - 1): + if numbers[j] > numbers[j + 1]: + numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] + print(f'The sorted list is: {numbers}') + elif choice == '5': + print('Goodbye!') + running = False + else: + print('Invalid choice. Please try again.') diff --git a/week-5/assignment-5/warmup1.py b/week-5/assignment-5/warmup1.py new file mode 100644 index 0000000..e35dbc5 --- /dev/null +++ b/week-5/assignment-5/warmup1.py @@ -0,0 +1,5 @@ + +total = 0 +for number in range(1,101): + total += number +print(f'The sum of 1 to 100 is: {total} ') \ No newline at end of file diff --git a/week-5/assignment-5/warmup2.py b/week-5/assignment-5/warmup2.py new file mode 100644 index 0000000..103deb7 --- /dev/null +++ b/week-5/assignment-5/warmup2.py @@ -0,0 +1,16 @@ + +while True: + + try: + user_in = input('Please enter a number: ') + if user_in.isdigit(): + number = int(user_in) + break + else: + print("That's not a positive integer. Try again.") + + except ValueError: + + print("That's not a positive integer. Try again.") + +print(f'Got it: {number}') \ No newline at end of file diff --git a/week-5/assignment-5/warmup3.py b/week-5/assignment-5/warmup3.py new file mode 100644 index 0000000..26ca8ef --- /dev/null +++ b/week-5/assignment-5/warmup3.py @@ -0,0 +1,14 @@ +name = ["Genesis", "John", "Alice", "Bob", "Mary", "Jane", "Tom", "Jerry", "Sam", "Lucy"] + +find = input("Enter a name to find: ") + +counter = 0 + +for n in name: + if n == find: + print(f" Found {find} at index {counter}.") + else: + counter += 1 + +if counter == len(name): + print(f"{find} is not in the list.") \ No newline at end of file diff --git a/week-5/assignment-5/warmup4.py b/week-5/assignment-5/warmup4.py new file mode 100644 index 0000000..4f1e4c0 --- /dev/null +++ b/week-5/assignment-5/warmup4.py @@ -0,0 +1,10 @@ + +for number in range(1, 31): + if number % 3 == 0 and number % 5 == 0: + print("FizzBuzz") + elif number % 3 == 0: + print("Fizz") + elif number % 5 == 0: + print("Buzz") + else: + print(number) diff --git a/week-6/assignment-6/mini_project.py b/week-6/assignment-6/mini_project.py new file mode 100644 index 0000000..c94a817 --- /dev/null +++ b/week-6/assignment-6/mini_project.py @@ -0,0 +1,90 @@ +numbers = [42, 17, 83, 5, 61, 29, 74, 8, 55, 93, 31, 66, 14, 47, 78, 3, 59, 22, 86, 40] + +#Findind minimum number +def find_minimum(numbers): + min_number = numbers[0] + for number in numbers: + if number < min_number: + min_number = number + return min_number + +#Finding maximum number +def find_maximum(numbers): + max_number = numbers[0] + for number in numbers: + if number > max_number: + max_number = number + return max_number + +#Searching for a number +def search_number(numbers, target): + + for i in range(len(numbers)): + if numbers[i] == target: + return i + return -1 + +#Bubble sort + +def bubble_sort(numbers): + +#make copy of the list to avoid modifying the original list + sorted_numbers = numbers.copy() + + for i in range(len(sorted_numbers)): + for j in range(0, len(sorted_numbers) - i - 1): + if sorted_numbers[j] > sorted_numbers[j + 1]: + sorted_numbers[j], sorted_numbers[j + 1] = sorted_numbers[j + 1], sorted_numbers[j] + print(f'The sorted list is: {sorted_numbers}') + + return bubble_sort + +#Prints the menu options +def show_menu(): + print('=== Number Cruncher ===') + print('1. Find the minimum number') + print('2. Find the maximum number') + print('3. Search for a number') + print('4. Sort the list') + print('5. Quit') + + return show_menu + +#Main program loop that calls for show_menu() and takes user input to call the appropriate function + +if __name__ == "__main__": + running = True + while running: + show_menu() + choice = input("\nEnter your choice: ") + + ##user input validation + + if choice == '1': + min_number = find_minimum(numbers) + print(f'The minimum number is: {min_number}') + + elif choice == '2': + max_number = find_maximum(numbers) + print(f'The maximum number is: {max_number}') + + elif choice == '3': + target = int(input("Enter a number to search for: ")) + index = search_number(numbers, target) + + if index != -1: + print(f'Found {target} at index {index}.') + else: + print(f'{target} was not found in the list.') + + elif choice == '4': + bubble_sort(numbers) + + elif choice == '5': + print('Goodbye!') + running = False + else: + print('Invalid choice. Please try again.') + + + \ No newline at end of file diff --git a/week-6/assignment-6/warmup1.py b/week-6/assignment-6/warmup1.py new file mode 100644 index 0000000..1b047c1 --- /dev/null +++ b/week-6/assignment-6/warmup1.py @@ -0,0 +1,14 @@ +def greet(name, greeting= "Hello"): + + print(f"{greeting}, {name}!") + +greet("Alex") + +#call with a name and custom greeting +greet("Alex", "Good morning") + +#greeting passed as a keyword argument +greet(name="Alex", greeting="Hello") + + + diff --git a/week-6/assignment-6/warmup2.py b/week-6/assignment-6/warmup2.py new file mode 100644 index 0000000..345303d --- /dev/null +++ b/week-6/assignment-6/warmup2.py @@ -0,0 +1,15 @@ +# celsius to fahrenheit + +# 1. Function definitions returning rounded values +def celsius_to_fahrenheit(c): + return round((c * 9/5) + 32, 1) + +def fahrenheit_to_celsius(f): + return round((f - 32) * 5/9, 1) + +# 2. Test values and print calls using f-strings +print(f"35°C = {celsius_to_fahrenheit(35)}°F") +print(f"10°C = {celsius_to_fahrenheit(10)}°F") +print(f"72°F = {fahrenheit_to_celsius(72)}°C") + + diff --git a/week-6/assignment-6/warmup3.py b/week-6/assignment-6/warmup3.py new file mode 100644 index 0000000..9e73fa5 --- /dev/null +++ b/week-6/assignment-6/warmup3.py @@ -0,0 +1,12 @@ +def set_name(): + name = "Harry" + return name # prints "Harry" + +print(set_name()) + + + +#print(name)# +# print(name) # NameError: name 'name' is not defined + ## ^^^^ +#NameError: name 'name' is not defined \ No newline at end of file diff --git a/week-6/assignment-6/warmup4.py b/week-6/assignment-6/warmup4.py new file mode 100644 index 0000000..1985a20 --- /dev/null +++ b/week-6/assignment-6/warmup4.py @@ -0,0 +1,11 @@ +def is_valid_score(score): + if score < 0 or score > 100: + return False + else: + return True + +user_score = int(input("Enter a score between 0 and 100: ")) +if is_valid_score(user_score): + print("Valid score.") +else: + print("Invalid score - must be between 0 and 100.") \ No newline at end of file