diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7d353cf3..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/1 gradetracker/GradeTracker.py b/1 gradetracker/GradeTracker.py index 54f12d7b..3e79601b 100644 --- a/1 gradetracker/GradeTracker.py +++ b/1 gradetracker/GradeTracker.py @@ -9,7 +9,7 @@ import statistics as s #add constants next -admins = {'Dominic':'Hacker','Faculty2':'ABC123','Faculty3':'123ABC'} +admins = {'Dominic':'Hacker','Faculty2':'ABC123','Faculty3':'123ABC','Benjamin':'Reed'} # Like the admins above is a dictionary but of students. # Dictionaries use curly brackets with colons to associate keys with values. diff --git a/2 ksu scrape/ksu_scrape_new.py b/2 ksu scrape/ksu_scrape_new.py index 20300aca..0a295aa2 100644 --- a/2 ksu scrape/ksu_scrape_new.py +++ b/2 ksu scrape/ksu_scrape_new.py @@ -16,10 +16,11 @@ def scrape_ksu(ksu_url,page): #using the lxml parser to process the web page text content soup = BeautifulSoup(source, 'lxml') #create a csv file in "w" write mode so we can add content to it. - ksu_news_csv = open("ksu_news_"+"{:%m_%d_%Y}".format(datetime.now())+"_p"+page+".csv","w") + ksu_news_csv = open("ksu_news_"+"{:%m_%d_%Y}".format(datetime.now())+"_all.csv", "a", newline="", encoding="utf-8") csv_writer = csv.writer(ksu_news_csv) #write the header row into our csv file - csv_writer.writerow(["Number","Title","URL","Date"]) + if page == "1": + csv_writer.writerow(["Number","Title","URL","Date"]) #show the content of the website we retrieved so that we can find the unique tags around the content we want #print(soup.prettify()) diff --git a/2 ksu scrape/ksu_scrape_one_csv.py b/2 ksu scrape/ksu_scrape_one_csv.py new file mode 100644 index 00000000..3bb7554b --- /dev/null +++ b/2 ksu scrape/ksu_scrape_one_csv.py @@ -0,0 +1,55 @@ +''' +To use this code, you will first need to install the three packages being imported below using pip or a manual install method. +This code was updated in August 2021 to use the new KSU news feed design. +''' +from bs4 import BeautifulSoup +import requests +import csv +from datetime import datetime + +def scrape_ksu(ksu_url, page): + ''' + This function is made for scraping the KSU news feed as of its redesign in August 2022. + Now returns rows instead of writing a CSV. + ''' + # grab the basic content from a web page + source = requests.get(ksu_url + page).text + # using the lxml parser to process the web page text content + soup = BeautifulSoup(source, 'lxml') + + # find posts + blog_list = soup.find('ul', class_='blog_listing') + blog_posts = blog_list.find_all('li') + + rows = [] + i = 1 + for blog_post in blog_posts: + title = blog_post.h3.text + + date = blog_post.p.text + date = date.strip().strip('"').strip() + + URL = blog_post.find('a')['href'] + + rows.append([i, title, URL, date]) + i += 1 + + return rows + +# -------- main driver: scrape many pages, write one CSV -------- +all_rows = [] +base_url = 'https://www.kennesaw.edu/news/news-releases/index.php?&p=' + +# loop the pages you want (1..9); adjust range as needed +for i in range(1, 10): + page_rows = scrape_ksu(base_url, str(i)) + all_rows.extend(page_rows) + +# write everything once into one CSV +outfile = f"ksu_news_{datetime.now():%m_%d_%Y}_all.csv" +with open(outfile, "w", newline="", encoding="utf-8") as f: + writer = csv.writer(f) + writer.writerow(["Number", "Title", "URL", "Date"]) + writer.writerows(all_rows) + +print(f"Wrote {len(all_rows)} rows to {outfile}") diff --git a/3 calcGUI/calcGUI.py b/3 calcGUI/calcGUI.py index 42c3fe17..e1950c71 100644 --- a/3 calcGUI/calcGUI.py +++ b/3 calcGUI/calcGUI.py @@ -1,5 +1,6 @@ from tkinter import * from math import sqrt as sqr +from math import sin, cos, tan class Calculator(Frame): @@ -144,6 +145,16 @@ def create_widgets(self): Creates the widgets to be used in the grid. :return: None """ + + self.sin_bttn = Button(self, text="sin", width=20, height=3, bg="lightgrey", command=lambda: self.add_chr("sin")) + self.sin_bttn.grid(row=2, column=6, columnspan=1) + + self.cos_bttn = Button(self, text="cos", width=20, height=3, bg="lightgrey", command=lambda: self.add_chr("cos")) + self.cos_bttn.grid(row=3, column=6, columnspan=1) + + self.tan_bttn = Button(self, text="tan", width=20, height=3, bg="lightgrey", command=lambda: self.add_chr("tan")) + self.tan_bttn.grid(row=4, column=6, columnspan=1) + self.eq_bttn = Button(self, text="=", width=20, height=3, bg="lightgrey", command=lambda: self.calculate()) self.eq_bttn.grid(row=4, column=4, columnspan=2) @@ -186,7 +197,7 @@ def create_widgets(self): self.six_bttn = Button(self, text="6", width=9, height=3, command=lambda: self.add_chr(6)) self.six_bttn.grid(row=2, column=2) - self.one_bttn = Button(self, text="1", width=9, height=3, command=lambda: self.add_chr(1)) + self.one_bttn = Button(self, text="Ben", width=9, height=3, command=lambda: self.add_chr("Reed")) self.one_bttn.grid(row=3, column=0) self.two_bttn = Button(self, text="2", width=9, height=3, command=lambda: self.add_chr(2)) diff --git a/4 DB in Python/.DS_Store b/4 DB in Python/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/4 DB in Python/.DS_Store and /dev/null differ diff --git a/4 DB in Python/SQLite Demo/myinventory.db b/4 DB in Python/SQLite Demo/myinventory.db index 1164ad38..902425d2 100644 Binary files a/4 DB in Python/SQLite Demo/myinventory.db and b/4 DB in Python/SQLite Demo/myinventory.db differ diff --git a/5 RaspberryPi button/.DS_Store b/5 RaspberryPi button/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/5 RaspberryPi button/.DS_Store and /dev/null differ diff --git a/6 Web Page with Flask/.DS_Store b/6 Web Page with Flask/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/6 Web Page with Flask/.DS_Store and /dev/null differ diff --git a/6 Web Page with Flask/basic page/script1.py b/6 Web Page with Flask/basic page/script1.py index 61717531..c64d1131 100644 --- a/6 Web Page with Flask/basic page/script1.py +++ b/6 Web Page with Flask/basic page/script1.py @@ -26,5 +26,9 @@ def home(): def about(): return render_template("about.html") +@app.route('/benjamin/') +def benjamin(): + return render_template("benjamin.html") + if __name__=="__main__": app.run(debug=True) diff --git a/6 Web Page with Flask/basic page/templates/benjamin.html b/6 Web Page with Flask/basic page/templates/benjamin.html new file mode 100644 index 00000000..89953120 --- /dev/null +++ b/6 Web Page with Flask/basic page/templates/benjamin.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} +{% block content %} +
+

Reed

+

This is Benjamin's Flask Website Demo project website. {{myName}}

+

+ Please type your name:
+ +

+
+{% endblock %} diff --git a/Ben_Reed_script1.py b/Ben_Reed_script1.py new file mode 100644 index 00000000..d14cd6d5 --- /dev/null +++ b/Ben_Reed_script1.py @@ -0,0 +1,34 @@ +''' +This is a basic web page running with Flask. +''' + +from flask import Flask, render_template, request +#This is the Flask object, we are creating an instance of the Flask class and storing it in the variable app +#__name__ is a special variable in Python that is the name of the module, which is this file's name without the .py extension +app=Flask(__name__) + +#This is a decorator, it is a function that takes a function as a parameter! +#A decorator is a function that wraps another function +#This decorator is saying that when someone goes to the URL /greet, run the greet function +@app.route('/greet', methods=['POST']) +def greet(): + inputName = request.form['myName'] + ip = request.remote_addr + #write data to file or to DB + inputName = inputName.upper()+" hi! Visiting from " + str(ip) + return render_template("home.html",myName=inputName) + +@app.route('/') +def home(): + return render_template("home.html",myName="Type your name in the box and click submit!") + +@app.route('/about/') +def about(): + return render_template("about.html") + +@app.route('/benjamin/') +def benjamin(): + return render_template("benjamin.html") + +if __name__=="__main__": + app.run(debug=True) \ No newline at end of file diff --git a/Grade Tracker App Project.py b/Grade Tracker App Project.py new file mode 100644 index 00000000..2181d92a --- /dev/null +++ b/Grade Tracker App Project.py @@ -0,0 +1,273 @@ +# ---------------------------------------------------------------------- +# 🐍 COMPLETE COURSE-SPECIFIC WEIGHTED GRADE TRACKER APP +# Features: Course-specific category weights, Add/Delete Course, +# Single GPA breakdown, All GPA summary. +# ---------------------------------------------------------------------- + +# GLOBAL DATA STRUCTURES +# Structure: +# grades = { +# 'Course Name': { +# 'grades': [ (score, category_name), ... ], +# 'weights': { 'Category Name': weight_percentage, ... } +# }, +# } +grades = {} +FILE_NAME = 'grades_data.txt' + +# ---------------------------------------------------------------------- +## 1. Helper Functions (Pure Python File I/O) + +def load_grades(): + """Loads grades data from a plain text file, rebuilding the nested structure.""" + global grades + + try: + with open(FILE_NAME, 'r') as file: + grades = {} + for line in file: + # Format: CourseName,Score,CategoryName,CategoryWeight + parts = line.strip().split(',') + if len(parts) == 4: + course, score_str, category, weight_str = parts + score = float(score_str) + weight = float(weight_str) + course = course.title() + category = category.title() + + # Rebuild the nested dictionary structure + if course not in grades: + grades[course] = {'grades': [], 'weights': {}} + + grades[course]['grades'].append((score, category)) + grades[course]['weights'][category] = weight + + print(f"Loaded {len(grades)} courses from {FILE_NAME}.") + + except FileNotFoundError: + print("No existing grades file found. Starting fresh.") + except Exception: + print("Error reading grades file. Data might be corrupt. Starting fresh.") + +def save_grades(): + """Saves all courses, grades, and their course-specific weights to one text file.""" + global grades + + try: + with open(FILE_NAME, 'w') as file: + for course, data in grades.items(): + course_weights = data['weights'] + + # Check if course has any grades before saving + if data['grades']: + for score, category in data['grades']: + # The weight must exist since it was required during add_grade + weight = course_weights[category] + + # Write in the format: CourseName,Score,CategoryName,CategoryWeight + file.write(f"{course},{score},{category},{weight}\n") + print(f"Grades and course-specific weights saved to {FILE_NAME}.") + except Exception as e: + print(f"Error saving grades: {e}") + +# ---------------------------------------------------------------------- +## 2. Core Logic Functions + +def add_course(course_name): + """Adds a new course, initializing its nested data structure.""" + course_name = course_name.title() + if course_name not in grades: + grades[course_name] = {'grades': [], 'weights': {}} + print(f"Course '{course_name}' added.") + else: + print(f"Course '{course_name}' already exists.") + +def delete_course(course_name): + """Deletes a specified course and all its grades/weights.""" + global grades + course_name = course_name.title() + + if course_name in grades: + del grades[course_name] + print(f"Course '{course_name}' has been deleted. (Remember to save before exiting!)") + else: + print(f"Error: Course '{course_name}' not found.") + +def add_grade(course_name, score, category_name): + """Adds a grade, checks for course-specific category weight, and prompts if needed.""" + course_name = course_name.title() + category_name = category_name.title() + + if course_name not in grades: + print(f"Error: Course '{course_name}' not found. Please add the course first (Menu 1).") + return + + course_weights = grades[course_name]['weights'] + + # Handle new category type and its course-specific weight + if category_name not in course_weights: + print(f"'{category_name}' is a NEW assignment type for {course_name}.") + while True: + try: + weight = float(input(f"Enter the percentage weight for ALL '{category_name}' assignments in {course_name} (e.g., 20): ")) + if 0 <= weight <= 100: + course_weights[category_name] = weight + print(f"Category '{category_name}' weight set to {weight}% for {course_name}.") + break + else: + print("Weight must be between 0 and 100.") + except ValueError: + print("Invalid input. Please enter a number for the weight.") + + # Add the grade to the course's grades list + grades[course_name]['grades'].append((score, category_name)) + print(f"Grade {score}% added to {course_name} under category '{category_name}'.") + +def calculate_gpa(course_name, show_breakdown=True): + """Calculates the weighted average grade for a single course. + If show_breakdown is True, prints the category details.""" + course_name = course_name.title() + if course_name not in grades or not grades[course_name]['grades']: + return "N/A" + + course_data = grades[course_name] + course_weights = course_data['weights'] + + category_scores = {} + + # 1. Organize scores by category + for score, category in course_data['grades']: + category = str(category).title() + if category not in category_scores: + category_scores[category] = [] + category_scores[category].append(score) + + total_weighted_sum = 0 + total_category_weight = 0 + + # 2. Calculate average for each category and apply the course's specific weight + for category, scores in category_scores.items(): + if category in course_weights: + category_weight = course_weights[category] + category_average = sum(scores) / len(scores) + + total_weighted_sum += (category_average * category_weight) + total_category_weight += category_weight + + if show_breakdown: + print(f" > {category} Avg: {category_average:.2f}% (Weight: {category_weight}%)") + + # 3. Final GPA calculation + if total_category_weight > 0: + final_gpa = total_weighted_sum / total_category_weight + return f"{final_gpa:.2f}%" + else: + return "No grades in weighted categories." + +def calculate_all_gpas(): + """Calculates and prints the weighted average GPA for all stored courses.""" + global grades + + if not grades: + print("No courses added yet.") + return + + print("\n--- Summary of All Course GPAs 📈 ---") + print("-----------------------------------") + + for course_name in grades.keys(): + # Call calculate_gpa with show_breakdown=False to avoid clutter + gpa_result = calculate_gpa(course_name, show_breakdown=False) + print(f" > {course_name}: {gpa_result}") + + print("-----------------------------------") + +# ---------------------------------------------------------------------- +## 3. Main Application Loop + +def grade_tracker_app(): + """The main user interface for the application.""" + load_grades() + + while True: + print("\n--- Grade Tracker Menu ---") + print("1. Add a New Course") + print("2. Add a Grade (Score and Category)") + print("3. View GPA for ALL Courses 📈") + print("4. View GPA for a Single Course (with Breakdown)") + print("5. View Course Category Weights") + print("6. Delete a Course 🗑️") + print("7. Save and Exit") + + choice = input("Enter your choice (1-7): ") + + if choice == '1': + name = input("Enter the course name: ") + add_course(name) + + elif choice == '2': + if grades: + print("\nAvailable Courses:", ", ".join(grades.keys())) + course = input("Enter course name to add grade: ") + category = input("Enter assignment type (e.g., Quiz, Test, Homework): ") + try: + score = float(input(f"Enter score for {category} (e.g., 92.5): ")) + add_grade(course, score, category) + except ValueError: + print("Invalid input for score. Please use a number.") + else: + print("Please add a course first (Menu 1).") + + elif choice == '3': + calculate_all_gpas() + + elif choice == '4': + if grades: + print("\nAvailable Courses:", ", ".join(grades.keys())) + course = input("Enter course name to view GPA: ") + print(f"\n--- GPA Calculation for {course.title()} ---") + # Call calculate_gpa with default show_breakdown=True + gpa = calculate_gpa(course) + print(f"\nFINAL GPA for {course.title()}: **{gpa}**") + else: + print("No courses available to calculate GPA.") + + elif choice == '5': + if grades: + print("\nAvailable Courses:", ", ".join(grades.keys())) + course_to_view = input("Enter course name to view weights: ").title() + + if course_to_view in grades: + weights = grades[course_to_view]['weights'] + print(f"\n--- {course_to_view} Category Weights ---") + if weights: + for cat, weight in weights.items(): + print(f" > {cat}: {weight}%") + else: + print(f"No categories defined for {course_to_view} yet.") + else: + print(f"Error: Course '{course_to_view}' not found.") + else: + print("No courses available to view weights.") + + elif choice == '6': + if grades: + print("\nAvailable Courses:", ", ".join(grades.keys())) + course_to_delete = input("Enter the course name to DELETE: ") + delete_course(course_to_delete) + else: + print("No courses available to delete.") + + elif choice == '7': + save_grades() + print("Exiting application. Goodbye!") + break + + else: + print("Invalid choice. Please enter a number from 1 to 7.") + +# ---------------------------------------------------------------------- + +# Run the application +if __name__ == "__main__": + grade_tracker_app() \ No newline at end of file diff --git a/P1 Python Absolute Beginner/Module_1.0_Tutorials_START_HERE.ipynb b/P1 Python Absolute Beginner/Module_1.0_Tutorials_START_HERE.ipynb index b162afaf..3ed32256 100644 --- a/P1 Python Absolute Beginner/Module_1.0_Tutorials_START_HERE.ipynb +++ b/P1 Python Absolute Beginner/Module_1.0_Tutorials_START_HERE.ipynb @@ -86,13 +86,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "slideshow": { "slide_type": "subslide" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World!\n" + ] + } + ], "source": [ "# Review the code, run the code\n", "print(\"Hello World!\")" @@ -100,19 +108,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello programmer!\n" + ] + } + ], "source": [ "print(\"Hello programmer!\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'Print' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[18]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mPrint\u001b[49m(\u001b[33m\"\u001b[39m\u001b[33mHello programmer!\u001b[39m\u001b[33m\"\u001b[39m)\n", + "\u001b[31mNameError\u001b[39m: name 'Print' is not defined" + ] + } + ], + "source": [ + "Print(\"Hello programmer!\")" + ] }, { "cell_type": "code", @@ -141,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -163,10 +193,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello App Dev 1!!!\n" + ] + } + ], + "source": [ + "# I am making this comment to explain the next line of code\n", + "print(\"Hello App Dev 1!!!\") # this is an inline comment" + ] }, { "cell_type": "markdown", @@ -239,6 +280,24 @@ "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "after edit, save!\n" + ] + } + ], + "source": [ + "# \"create a new cell\"\n", + "print(\"after edit, save!\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -270,6 +329,23 @@ "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cntrl+s to save\n" + ] + } + ], + "source": [ + "print(\"cntrl+s to save\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -356,14 +432,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a string with single quotes\n", + "This is a string with double quotes\n" + ] + } + ], "source": [ "# [ ] enter a string in the print() function using single quotes\n", + "print('This is a string with single quotes')\n", "\n", "# [ ] enter a string in the print() function using double quotes\n", - "\n" + "print(\"This is a string with double quotes\")\n" ] }, { @@ -391,9 +477,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123\n", + "123\n" + ] + } + ], "source": [ "print(123) #integer, with numeric value\n", "print(\"123\") #string, represents text characters" @@ -454,15 +549,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123\n", + "123\n" + ] + } + ], "source": [ "# [ ] print an Integer\n", - "\n", + "print(123)\n", "\n", "# [ ] print a strings made of Integer characters\n", - "\n", + "print('123')\n", "\n" ] }, @@ -520,13 +624,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am a string\n", + "I am a string\n" + ] + } + ], "source": [ "# [ ] Review code and Run\n", "# initialize the variable\n", - "#current_msg = \"I am a string\"\n", + "current_msg = \"I am a string\"\n", "\n", "# print literal string\n", "print(\"I am a string\")\n", @@ -537,15 +650,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I ran this cell using ctrl+enter\n" + ] + } + ], "source": [ "# [ ] Review code and Run\n", "# assign a new string to the current_msg\n", - "current_msg = \"Run this cell using Ctrl+Enter\"\n", + "current_msg = \"I ran this cell using ctrl+enter\"\n", "\n", "print(current_msg)" ] @@ -566,12 +687,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is me changing current_msg\n", + "This is me changing current_msg\n" + ] + } + ], "source": [ "# { ] run cell above then run this cell after completing the code as directed\n", - "\n" + "print(current_msg)\n", + "\n", + "current_msg = \"This is me changing current_msg\"\n", + "\n", + "print(current_msg)\n" ] }, { @@ -608,18 +742,19 @@ "### Variables can start initialized as an Integer number data type \n", ">```python \n", "x = 22\n", - "``` \n", - "here the Integer `22`  value was assigned to the variable  **`x`** \n", + " \n", + "here the Integer `22` value was assigned to the variable **`x`** \n", "\n", "### The type of data a variable holds can be changed,\n", "### Python variables can change the **type** of data a variable holds \n", "\n", ">```python\n", "x = 22\n", + "\n", "x = \"I am a string\"\n", - "``` \n", "\n", - "**` x `**  changed type from Integer  **`x = 22`**  to string  **`x = \"I am a string\"`** \n", + "\n", + "**` x ` changed type from Integer  **`x = 22`**  to string  **`x = \"I am a string\"`** \n", " \n", ">>|Best Practice: Friendly Names |\n", "|------------------------------------------------------------------------------------------|\n", @@ -651,9 +786,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "22\n", + "Joana\n" + ] + } + ], "source": [ "test_value = 22\n", "print(test_value)\n", @@ -673,18 +817,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "slideshow": { "slide_type": "subslide" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben Reed\n" + ] + } + ], "source": [ "# [ ] assign a string value to a variable student_name\n", - "\n", + "student_name = \"Ben Reed\"\n", "# [ ] print the value of variable student_name\n", - "\n" + "print(student_name)\n" ] }, { @@ -699,18 +851,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mabel Reed\n", + "Rocky Balboa\n" + ] + } + ], "source": [ "# [ ] assign the student_name variable a different string value (a different name)\n", - "\n", + "student_name = \"Mabel Reed\"\n", "# [ ] print the value of variable student_name\n", - "\n", + "print(student_name)\n", "# [ ] assign a 3rd different string value, to the variable name \n", - "\n", + "student_name = \"Rocky Balboa\"\n", "# [ ] print the value of variable name\n", - "\n" + "print(student_name)\n" ] }, { @@ -726,18 +887,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a bucket\n", + "123\n" + ] + } + ], "source": [ "# [ ] assigning a value to a variable called bucket\n", - "\n", + "bucket = \"This is a bucket\" # string\n", "# [ ] print the value of bucket \n", - "\n", + "print(bucket)\n", "# [ ] assign an Integer value (no quotes) to the variable bucket\n", - "\n", + "bucket = 123 # integer\n", "# [ ] print the value of bucket \n", - "\n", + "print(bucket)\n", "\n" ] }, @@ -800,9 +970,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Read and run the code\n", "type(\"Hello World!\")" @@ -810,27 +991,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(501)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(8.33333)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "student_name = \"Colette Browning\"\n", "type(student_name)" @@ -850,103 +1064,220 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] show the type after assigning bucket = a whole number value such as 16 \n", - "\n", - "\n" + "bucket = 16\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] show the type after assigning bucket = a word in \"double quotes\"\n", - "\n", - "\n" + "bucket = \"This is a bucket\"\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of 'single quoting' (use single quotes) \n", - "\n", - "\n" + "bucket = 'single quotes'\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of \"double quoting\" (use double quotes)\n", - "\n" + "bucket = \"double quotes\"\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of \"12\" (use quotes)\n", + "bucket = \"12\"\n", + "type(bucket)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of 12 (no quotes)\n", - "\n" + "bucket = 12\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of -12 (no quotes)\n", - "\n" + "bucket = -12\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of 12.0 (no quotes)\n", - "\n" + "bucket = 12.0\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] display the type of 1.55\n", - "\n" + "bucket = 1.55\n", + "type(bucket)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "type" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] find the type of the type(3) statement (no quotes) - just for fun\n", - "\n" + "type(type(3))\n" ] }, { @@ -1017,9 +1348,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "41" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding a pair of 2 digit Integers\n", "23 + 18" @@ -1027,19 +1369,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'My name is Alyssa Brown'" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding 2 strings\n", - "\"my name is \" + \"Alyssa\" " + "Introduction = \"my name is\"\n", + "My_name = \"Alyssa\"\n", + "\n", + "\n", + "Introduction.capitalize() + \" \" + My_name + \" \" + shoe_color.capitalize()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'my shoe color is brown'" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding a variable string and a literal string\n", "shoe_color = \"brown\"\n", @@ -1057,52 +1425,110 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] add 3 integer numbers\n", - "\n" + "2 + 2 + 2\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "12.5" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] add a float number and an integer number\n", - "\n" + "10.5 + 2\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This notebook belongs to Ben'" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Add the string \"This notebook belongs to \" and a string with your first name\n", - "\n" + "\"This notebook belongs to \"+ \"Ben\"\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Create variables sm_number and big_number and assign numbers then add the numbers\n", - "\n" + "sm_number = 3\n", + "big_number = 10\n", + "sm_number + big_number\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Ben, remember to save the notebook frequently'" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] assign a string value to the variable first_name and add to the string \", remember to save the notebook frequently\"\n", - "\n" + "first_name = \"Ben\"\n", + "first_name + \", remember to save the notebook frequently\"\n" ] }, { @@ -1129,9 +1555,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n", + "Happy Birthday Alton\n" + ] + } + ], "source": [ "# [ ] review & run code for assigning variables & using addition\n", "add_two = 34 + 16\n", @@ -1144,27 +1579,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "13\n", + "26\n", + "24\n" + ] + } + ], "source": [ "# [ ] review & run code for Integer addition in variables and in a print function\n", "int_sum = 6 + 7\n", "print(int_sum)\n", "print(11 + 15)\n", - "print()" + "print(11 + int_sum)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I do not wear a hat\n", + "I do not wear a hat at dinner, Alton\n" + ] + } + ], "source": [ "# string addition in variables and in print()function\n", "hat_msg = \"I do not wear \" + \"a hat\" \n", "print(hat_msg)\n", - "print(\"at \" + \"dinner\")" + "print(hat_msg +\" at \" + \"dinner\" + \",\" + \" \" + first_name)" ] }, { @@ -1178,37 +1632,62 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My favorite food is pizza\n" + ] + } + ], "source": [ "# [ ] perform string addition in the variable named new_msg (add a string to \"my favorite food is \")\n", "new_msg = \"My favorite food is\"\n", - "print(new_msg)\n", + "print(new_msg + \" pizza\")\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ "# [ ] perform Integer addition in the variable named new_sum (add 2 or more Integers)\n", "new_sum = 0\n", - "print(new_sum)\n", + "print(new_sum + 5)\n", "\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My favorite food is ice cream\n" + ] + } + ], "source": [ "# [ ] create and print a new string variable, new_msg_2, that concatenates new_msg + a literal string\n", - "\n" + "new_msg_2 = new_msg + \" ice cream\"\n", + "print(new_msg_2)\n" ] }, { @@ -1230,13 +1709,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my number is 123\n", + "my number is 123\n" + ] + } + ], "source": [ "# [ ] review & run code\n", "print(\"my number is \" + \"123\") #string, represents a text character\n", - "print(\"my number is \" + 123) #number, with numeric value " + "print(\"my number is \" + \"123\") #number, with numeric value " ] }, { @@ -1269,33 +1757,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "345\n" + ] + } + ], "source": [ "# [ ] review and run the code - then fix any Errors\n", - "total_cost = 3 + \"45\"\n", + "total_cost = \"3\" + \"45\"\n", "print(total_cost)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the street number of Central School is 123\n" + ] + } + ], "source": [ "# [ ] review and run the code - then fix any Errors\n", - "school_num = 123\n", + "school_num = \"123\"\n", "print(\"the street number of Central School is \" + school_num)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "6.3\n" + ] + } + ], "source": [ "# [ ] Read and run the code - write a hypothesis for what you observe adding float + int\n", "# [ ] HYPOTHESIS: \n", @@ -1337,14 +1851,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi!\n", + "I like the morning\n" + ] + } + ], "source": [ "# [ ] review and run the code for properly and improperly formatted print statement\n", "print(\"Hi!\")\n", "## Improper format - non matching quotes\n", - "print('I like the morning\") " + "print(\"I like the morning\") " ] }, { @@ -1356,12 +1879,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hi\n" + ] + } + ], "source": [ "# [ ] review and run the code \n", - "prin('hi')" + "print('hi')" ] }, { @@ -1374,12 +1905,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "where are my socks?\n" + ] + } + ], "source": [ "# [ ] review and run the code missing the closing parenthesis \n", - "print(\"where are my socks?\" " + "print(\"where are my socks?\")" ] }, { @@ -1391,12 +1930,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my socks are in the wrong bin\n" + ] + } + ], "source": [ "# { ] review and run the code \n", - "print(\"my socks are in the wrong bin)\" " + "print(\"my socks are in the wrong bin\")" ] }, { @@ -1417,58 +1964,98 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my socks do not match\n" + ] + } + ], "source": [ "# [ ] repair the syntax error \n", - "print('my socks do not match\") \n", + "print(\"my socks do not match\") \n", " \n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my socks match now\n" + ] + } + ], "source": [ "# [ ] repair the NameError \n", - "pront(\"my socks match now\") \n", + "print(\"my socks match now\") \n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Save the notebook frequently\n" + ] + } + ], "source": [ "# [ ] repair the syntax error \n", - "print\"Save the notebook frequently\")\n", + "print(\"Save the notebook frequently\")\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Alton\n" + ] + } + ], "source": [ "# [ ] repair the NameError \n", "student_name = \"Alton\"\n", - "print(STUDENT_NAME)\n", + "print(student_name)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 108, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total students are signed up for tutoring\n" + ] + } + ], "source": [ "# [ ] repair the TypeError\n", "total = 3\n", - "print(total + \" students are signed up for tutoring\")\n", + "print(\"total\" + \" students are signed up for tutoring\")\n", "\n" ] }, @@ -1522,9 +2109,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 109, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " *\n", + " * *\n", + " *****\n", + " * *\n", + "* *\n", + "\n" + ] + } + ], "source": [ "# the letter 'A'\n", "print(\" *\")\n", @@ -1554,12 +2154,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 117, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "_ _\n", + " \\ / \n", + " \\ / \n", + " \\ . . / \n", + " V \n" + ] + } + ], "source": [ "# create # [ ] flying bird character art \n", - "\n" + "print(\"_ _\")\n", + "print(\" \\\\ / \")\n", + "print(\" \\\\ / \")\n", + "print(\" \\\\ . . / \")\n", + "print(\" V \")" ] }, { @@ -1572,10 +2188,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "#######\n", + "##\n", + "####\n", + "##\n", + "#######\n", + "\n" + ] + } + ], + "source": [ + "print(\"\"\"\n", + "#######\n", + "##\n", + "####\n", + "##\n", + "#######\n", + "\"\"\")\n" + ] }, { "cell_type": "markdown", @@ -1629,9 +2267,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enter a small int: \n", + "small int: \n", + "3\n" + ] + } + ], "source": [ "# review and run code - enter a small integer in the text box\n", "print(\"enter a small int: \")\n", @@ -1655,14 +2303,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student name type is \n" + ] + } + ], "source": [ "# [ ] get input for the variable student_name\n", - "\n", + "student_name = input(\"Please give me a student name: \")\n", "# [ ] determine the type of student_name\n", - "\n", + "print(\"Student name type is \" + str(type(student_name)))\n", "\n" ] }, @@ -1683,13 +2339,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enter a name or number\n", + "Test input is: 5\n" + ] + } + ], "source": [ "# [ ] run cell several times entering a name a int number and a float number after adding code below\n", "print(\"enter a name or number\")\n", "test_input = input()\n", + "print(\"Test input is: \" + test_input)\n", "# [ ] insert code below to check the type of test_input\n", "\n", "\n" @@ -1717,9 +2383,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi Ben Reed\n" + ] + } + ], "source": [ "student_name = input(\"enter the student name: \") \n", "print(\"Hi \" + student_name)" @@ -1738,14 +2412,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "City name is: Kennesaw\n" + ] + } + ], "source": [ "# [ ] get user input for a city name in the variable named city\n", - "\n", + "city = input(\"Please enter a city name\")\n", "# [ ] print the city name\n", - "\n", + "print(\"City name is:\" + \" \" + city)\n", "\n" ] }, @@ -1773,12 +2455,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben\n", + "36\n", + "Do you want email? no\n", + "No email provided\n" + ] + } + ], "source": [ "# [ ]create variables to store input: name, age, get_mail with prompts\n", "# for name, age and yes/no to being on an email list\n", + "name = input(\"please enter your name:\")\n", + "age = input(\"please enter your age: \")\n", + "get_email = input(\"Do you want email? (yes or no)\")\n", + "if get_email in (\"yes\", \"Yes\"):\n", + " email = input(\"Please enter your email address: \")\n", + "else:\n", + " email = \"No email provided\"\n", + "print(name)\n", + "print(age)\n", + "print(\"Do you want email?\" + \" \" + get_email)\n", + "print(email)\n", "\n", "\n", "# [ ] print a description + variable value for each variable\n", @@ -1854,9 +2558,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "41" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding a pair of 2 digit Integers\n", "23 + 18" @@ -1864,9 +2579,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'my name is Alyssa'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding 2 strings\n", "\"my name is \" + \"Alyssa\" " @@ -1874,9 +2600,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'my shoe color is brown'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Review and run code for adding a variable string and a literal string\n", "shoe_color = \"brown\"\n", @@ -1894,42 +2631,88 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] add 3 integer numbers\n", - "\n" + "3 + 5 + 6\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "15.5" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] add a float number and an integer number\n", - "\n" + "10.5 + 5\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This notebook belongs to Ben'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Add the string \"This notebook belongs to \" and a string with your first name\n", - "\n" + "\"This notebook belongs to \" + \"Ben\"\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Create variables sm_number and big_number and assign numbers then add the numbers\n", - "\n" + "sm_number = 3\n", + "big_number = 5\n", + "sm_number + big_number\n" ] }, { @@ -1986,9 +2769,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Collette!\n", + "Hello to Collette who is from the city\n" + ] + } + ], "source": [ "# review and run code\n", "\n", @@ -2012,12 +2804,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Collette welcome to our world.\n" + ] + } + ], "source": [ "# [ ] print 3 strings on the same line using commas inside the print() function \n", - "\n" + "print(\"Hello\", name, \"welcome to our world.\")\n" ] }, { @@ -2044,9 +2844,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I will pick you up @ 6 for the party\n" + ] + } + ], "source": [ "# review and run code\n", "print(\"I will pick you up @\",6,\"for the party\")" @@ -2054,9 +2862,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "An Integer of 14 combined with strings causes 0 TypeErrors in comma formatted print!\n" + ] + } + ], "source": [ "# review and run code\n", "number_errors = 0\n", @@ -2074,11 +2890,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I have 3 dogs and 2 cats\n" + ] + } + ], "source": [ "# [ ] use a print() function with comma separation to combine 2 numbers and 2 strings\n", + "print(\"I have\", 3, \"dogs and\", 2, \"cats\")\n", "\n" ] }, @@ -2101,16 +2926,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "115 Hemlock Street\n" + ] + } + ], "source": [ "# [ ] get user input for a street name in the variable, street\n", - "\n", + "st_number = input(\"What is your street number:\")\n", + "street = input(\"Enter your street name: \")\n", + "street_type = input(\"Enter your street type: \")\n", "# [ ] get user input for a street number in the variable, st_number\n", "\n", "# [ ] display a message about the street and st_number\n", - "\n", + "print(st_number, street, street_type)\n", "\n" ] }, @@ -2125,15 +2960,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of the variable is 3 and it is a number.\n" + ] + } + ], "source": [ "# [ ] define a variable with a string or numeric value\n", - "\n", + "variable = 3\n", "# [ ] display a message combining the variable, 1 or more literal strings and a number\n", - "\n", - "\n" + "print(\"The value of the variable is\", variable, \"and it is a number.\")\n" ] }, { @@ -2169,28 +3011,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reminder: The class for Ben Reed is scheduled for 10:30am with 10 participants. Please arrive at least 5 minutes early.\n" + ] + } + ], "source": [ "# [ ] get input for variables: owner, num_people, training_time - use descriptive prompt text\n", - "owner = \n", - "num_people = \n", - "training_time = \n", + "owner = input(\"Owner of the Res? \")\n", + "num_people = input(\"How many people will be in the class? \")\n", + "training_time = input(\"What is the time of the class? \")\n", "# [ ] create a integer variable min_early and \"hard code\" the integer value (e.g. - 5, 10 or 15)\n", - "min_early = \n", + "min_early = 5\n", "# [ ] print reminder text using all variables & add additional strings - use comma separated print formatting\n", - "\n", - "\n" + "print(\"Reminder: The class for\", owner, \"is scheduled for\", training_time, \"with\", num_people, \"participants. Please arrive at least\", min_early, \"minutes early.\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben, remember to save the notebook frequently\n" + ] + } + ], "source": [ - "# [ ] assign a string value to the variable first_name and add to the string \", remember to save the notebook frequently\"\n" + "# [ ] assign a string value to the variable first_name and add to the string \", remember to save the notebook frequently\"\n", + "first_name = \"Ben\"\n", + "print(first_name + \",\" + \" remember to save the notebook frequently\")\n" ] }, { @@ -2248,9 +3107,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Collette!\n", + "Hello to Collette who is from the city\n" + ] + } + ], "source": [ "# review and run code\n", "\n", @@ -2306,9 +3174,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I will pick you up @ 6 for the party\n" + ] + } + ], "source": [ "# review and run code\n", "print(\"I will pick you up @\",6,\"for the party\")" @@ -2316,9 +3192,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "An Integer of 14 combined with strings causes 0 TypeErrors in comma formatted print!\n" + ] + } + ], "source": [ "# review and run code\n", "number_errors = 0\n", @@ -2497,9 +3381,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It's time to save your code\n", + "I said to the class 'sometimes it's need to shut down and restart a notebook when cells refuse to run'\n" + ] + } + ], "source": [ "# review and run the code\n", "\n", @@ -2507,7 +3400,7 @@ "print(\"It's time to save your code\")\n", "\n", "# Double quote surrounded by Single\n", - "print('I said to the class \"sometimes you need to shut down and restart a notebook when cells refuse to run\"')" + "print('I said to the class \\'sometimes it\\'s need to shut down and restart a notebook when cells refuse to run\\'')" ] }, { @@ -2587,45 +3480,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"Python\".isalpha()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"3rd\".isalnum()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "\"A Cold Stromy Night\".istitle()" + "\"A Cold Stormy Night\".istitle()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"1003\".isdigit()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cm height: 176 is all digits = True\n" + ] + } + ], "source": [ "cm_height = \"176\"\n", "print(\"cm height:\",cm_height, \"is all digits =\",cm_height.isdigit())" @@ -2633,9 +3578,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], "source": [ "print(\"SAVE\".islower())\n", "print(\"SAVE\".isupper())" @@ -2643,11 +3597,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "\"Boolean\".startswith(\"B\")" + "\"Boolean\".startswith(\"b\")" ] }, { @@ -2661,22 +3626,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Use .isalpha() on the string \"alphabetical\"\n", - "\n" + "\"alphabetical\".isalpha()\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] Use .isalpha() on the string: \"Are spaces and punctuation Alphabetical?\"\n", - "\n" + "\"Are spaces and punctuation Alphabetical?\".isalpha()\n" ] }, { @@ -2920,7 +3907,7 @@ "outputs": [], "source": [ "# [ ] initailize variable alpha_test with input\n", - "\n", + "alpha_test = input(\"Please enter a string to test if it is alphabetical: \")\n", "# [ ] use .isalpha() on string variable alpha_test\n", "\n" ] @@ -2979,18 +3966,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ms. browning is in her office.\n" + ] + } + ], "source": [ "print(\"ms. Browning is in her office.\".capitalize())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Green green green and GREEN!\n" + ] + } + ], "source": [ "fav_color = \"green\"\n", "print(fav_color.capitalize(), fav_color, fav_color,\"and\", fav_color.upper()+\"!\")" @@ -3008,23 +4011,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "GRASS\n", + "grass\n", + "GRASS\n", + "Grass\n" + ] + } + ], "source": [ "# [ ] get input for a variable, fav_food, that describes a favorite food\n", - "\n", + "fav_food = input(\"please enter your favorite food: \")\n", "# [ ] display fav_food as ALL CAPS, used in a sentence\n", - "\n", + "print(fav_food.upper())\n", "\n", "# [ ] dispaly fav_food as all lower case, used in a sentence\n", - "\n", + "print(fav_food.lower())\n", "\n", "# [] display fav_food with swapped case, used in a sentence\n", - "\n", + "print(fav_food.swapcase())\n", "\n", "# [] display fav_food with capitalization, used in a sentence\n", - "\n", + "print(fav_food.capitalize())\n", "\n", "\n" ] @@ -3064,9 +4078,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "blue\n" + ] + } + ], "source": [ "# review and run code - test a capitalized color input\n", "fav_color = input('What is your favorite color?: ').lower()\n", @@ -3084,9 +4106,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "BLUE reversed\n", + "NBLAH blahblah\n" + ] + } + ], "source": [ "def short_rhyme(r1,r2):\n", " print(r1.upper(),r2.lower())\n", @@ -3123,11 +4154,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ "# review and run code to test if a string is to be found in another string\n", "menu = \"salad, pasta, sandwich, pizza, drinks, dessert\"\n", @@ -3136,9 +4175,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'hello' in greeting = False\n", + "'Hello' in greeting = True\n" + ] + } + ], "source": [ "# review and run code to test case sensitive examples \n", "greeting = \"Hello World!\"\n", @@ -3155,9 +4203,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'hello' in greeting = False\n", + "'Hello' in greeting = True\n", + "'hello' in greeting if lower used = True\n" + ] + } + ], "source": [ "# review and run code to test removing case sensitivity from a string comparison\n", "greeting = \"Hello World!\"\n", @@ -3179,9 +4237,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your name is BEN\n" + ] + } + ], "source": [ "# [] print 3 tests, with description text, testing the menu variable for 'pizza', 'soup' and 'dessert'\n", "menu = \"salad, pasta, sandwich, pizza, drinks, dessert\"\n", @@ -3204,13 +4270,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cheeseburger is not available on the menu.\n" + ] + } + ], "source": [ "# Create a program where the user supplies input to search the menu\n", - "\n", - "\n" + "menu = \"salad, pasta, bread, cheese, sandwich, pizza, drinks, dessert\"\n", + "search_item = input(\"Please enter a menu item to search for: \")\n", + "if search_item in menu:\n", + " print(search_item, \"is available on the menu.\")\n", + "else:\n", + " print(search_item, \"is not available on the menu.\")\n" ] }, { @@ -3258,9 +4336,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'red' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[94]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# [ ] fix the error\u001b[39;00m\n\u001b[32m 2\u001b[39m paint_colors = \u001b[33m\"\u001b[39m\u001b[33mred, blue, green, black, orange, pink\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m'\u001b[39m\u001b[33mRed in paint colors = \u001b[39m\u001b[33m'\u001b[39m,\u001b[43mred\u001b[49m \u001b[38;5;129;01min\u001b[39;00m paint_colors)\n", + "\u001b[31mNameError\u001b[39m: name 'red' is not defined" + ] + } + ], "source": [ "# [ ] fix the error\n", "paint_colors = \"red, blue, green, black, orange, pink\"\n", @@ -3300,7 +4390,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.1" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_1.1_Practice.ipynb b/P1 Python Absolute Beginner/Module_1.1_Practice.ipynb index ad652b39..549c06dc 100644 --- a/P1 Python Absolute Beginner/Module_1.1_Practice.ipynb +++ b/P1 Python Absolute Beginner/Module_1.1_Practice.ipynb @@ -39,10 +39,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello and remember to save the notebook\n" + ] + } + ], + "source": [ + "print('Hello' + \" \" + \"and remember to save the notebook\")" + ] }, { "cell_type": "markdown", @@ -55,9 +65,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "watch for the cat\n" + ] + } + ], "source": [ "print('watch for the cat')" ] @@ -94,8 +112,21 @@ "metadata": { "collapsed": true }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is Ben Reed's notebook and today's date is 2025-08-29 13:15:49.094333\n" + ] + } + ], + "source": [ + "# this is Ben Reed's notebook, today is 8/29/25\n", + "from datetime import datetime\n", + "\n", + "print(\"This is Ben Reed\\'s notebook and today\\'s date is \" + str(datetime.now()))" + ] }, { "cell_type": "markdown", @@ -108,14 +139,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben Reed\n", + "is using python\n" + ] + } + ], "source": [ "# [ ] print your name\n", - "\n", + "print(\"Ben Reed\")\n", "# [ ] print \"is using Python\"\n", - "\n" + "print(\"is using python\")\n" ] }, { @@ -990,14 +1030,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "True\n" + "True\n", + "True\n", + "True\n", + "False\n" ] } ], @@ -1013,9 +1056,12 @@ "\n", "# 4[ ] Check if \"nuts\" are in the input\n", "print(\"nuts\" in test_food)\n", + "\n", "# 4+[ ] Challenge: Check if \"seafood\" is in the input\n", + "print(\"seafood\" in test_food)\n", "\n", "# 4+[ ] Challenge: Check if \"chocolate\" is in the input\n", + "print(\"chocolate\" in test_food)\n", "\n" ] }, @@ -1044,7 +1090,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.1" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_1.2_Required_Code.ipynb b/P1 Python Absolute Beginner/Module_1.2_Required_Code.ipynb index be0b3c0e..2379e921 100644 --- a/P1 Python Absolute Beginner/Module_1.2_Required_Code.ipynb +++ b/P1 Python Absolute Beginner/Module_1.2_Required_Code.ipynb @@ -33,26 +33,41 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 48, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "True\n", + "False\n" + ] + } + ], "source": [ "# Create name check code\n", "\n", "# [ ] get input for input_test variable\n", - "\n", + "input_test = input(\"Please enter a names of people met in the last 24 hours: \")\n", "# [ ] print \"True\" message if \"John\" is in the input or False message if not\n", - "\n", + "print(\"John\".lower() in input_test.lower())\n", "\n", "# [ ] print True message if your name is in the input or False if not\n", - "\n", + "my_name = \"Ben\"\n", + "print(my_name.lower() in input_test.lower())\n", "\n", "# [ ] Challenge: Check if another person's name is in the input - print message\n", + "other_name = \"Rhonda\"\n", + "print(other_name.lower() in input_test.lower())\n", "\n", - "\n", - "# [ ] Challenge: Check if a fourth person's name is in the input - print message" + "# [ ] Challenge: Check if a fourth person's name is in the input - print message\n", + "fourth_name = \"Apple\"\n", + "print(fourth_name.lower() in input_test.lower())" ] }, { @@ -79,7 +94,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_3.0_Tutorials_Conditionals.ipynb b/P1 Python Absolute Beginner/Module_3.0_Tutorials_Conditionals.ipynb index 12292b89..70fbff15 100644 --- a/P1 Python Absolute Beginner/Module_3.0_Tutorials_Conditionals.ipynb +++ b/P1 Python Absolute Beginner/Module_3.0_Tutorials_Conditionals.ipynb @@ -45,9 +45,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True means do something\n" + ] + } + ], "source": [ "if True:\n", " print(\"True means do something\")\n", @@ -57,9 +65,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enjoy some hot tea!\n" + ] + } + ], "source": [ "hot_tea = True\n", "\n", @@ -71,9 +87,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pass executed\n" + ] + } + ], "source": [ "someone_i_know = False\n", "if someone_i_know:\n", @@ -86,9 +110,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "how have you been?\n" + ] + } + ], "source": [ "# changed the value of someone_i_know\n", "someone_i_know = True\n", @@ -114,11 +146,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It is sunny.\n" + ] + } + ], "source": [ - "sunny_today = False\n", + "sunny_today = True\n", "# [ ] test if it is sunny_today and give proper responses using if and else\n", "if sunny_today:\n", " print(\"It is sunny.\")\n", @@ -128,13 +168,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "it is not sunny\n" + ] + } + ], "source": [ "sunny_today = False\n", "# [ ] use code you created above and test sunny_today = False\n", - "\n" + "if sunny_today:\n", + " print(\"It is sunny.\")\n", + "else:\n", + " print(\"it is not sunny\")\n" ] }, { @@ -165,9 +216,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Harry potter - consider capitalization throughout for book titles.\n" + ] + } + ], "source": [ "# review code and run cell\n", "favorite_book = input(\"Enter the title of a favorite book: \")\n", @@ -180,9 +239,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- bear is not a positive integer\n" + ] + } + ], "source": [ "# review code and run cell\n", "a_number = input(\"enter a positive integer number: \")\n", @@ -201,9 +268,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "prowler starts with \"P\"\n" + ] + } + ], "source": [ "# review code and run cell\n", "vehicle_type = input('\"enter a type of vehicle that starts with \"P\": ')\n", @@ -230,14 +305,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "welcome is all lowercase\n", + "and\n", + "I have $3 is not lowercase\n" + ] + } + ], "source": [ "test_string_1 = \"welcome\"\n", "test_string_2 = \"I have $3\"\n", "# [ ] use if, else to test for islower() for the 2 strings\n", - "\n" + "if test_string_1.islower():\n", + " print(test_string_1, \"is all lowercase\")\n", + "else:\n", + " print(test_string_1, \"is not all lowercase\")\n", + "print(\"and\")\n", + "\n", + "if test_string_2.islower():\n", + " print(test_string_2, \"is all lowercase\")\n", + "else:\n", + " print(test_string_2, \"is not lowercase\")\n" ] }, { @@ -252,16 +346,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], "source": [ "test_string_1 = \"welcome\"\n", "test_string_2 = \"I have $3\"\n", "test_string_3 = \"With a function it's efficient to repeat code\"\n", "# [ ] create a function w_start_test() use if & else to test with startswith('w')\n", "def w_start_test(test_string):\n", - " print(test_string.startswith('w'))\n", + " print(test_string.lower().startswith('w'))\n", " \n", "# [ ] Test the 3 string variables provided by calling w_start_test()\n", "w_start_test(test_string_1)\n", @@ -315,9 +419,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run code to see if 3 greater than 5\n", "3 > 5" @@ -325,9 +440,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run code to see if 3 less than or equal to 5\n", "3 <= 5" @@ -335,9 +461,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run code \n", "\n", @@ -350,9 +487,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x not equal 9 is True\n", + "x equal 3 is True\n" + ] + } + ], "source": [ "# [ ] review and run code \n", "x = 3\n", @@ -373,9 +519,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ "x = 9 + 4\n", "# [ ] create a test to print() True or False for x is equal to 13\n", @@ -387,12 +541,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true\n" + ] + } + ], "source": [ "# [ ] create a test to print True or False for 3 + 3 is greater than 2 + 4\n", - "\n" + "x = 3 + 3\n", + "if x >= 2 + 4:\n", + " print(\"true\")\n", + "else:\n", + " print(\"false\")\n" ] }, { @@ -419,9 +585,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x was 21\n", + "now x is 25\n" + ] + } + ], "source": [ "# review code and run cell\n", "x = 21\n", @@ -435,9 +610,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25\n", + "Pass: x + 18 is equal to 36\n" + ] + } + ], "source": [ "# review code and run cell\n", "print(x)\n", @@ -450,9 +634,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x is 18\n" + ] + } + ], "source": [ "# review code and run cell. \"!\" means \"not\"\n", "x = 18\n", @@ -465,15 +657,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"==\" tests for, is equal to\n" + ] + } + ], "source": [ "# review code and run cell\n", "# DON'T ASSIGN (x = 2) when you mean to COMPARE (x == 2)\n", "x = 2\n", "\n", - "if x = 2:\n", + "if x == 2:\n", " print('\"==\" tests for, is equal to')\n", "else:\n", " pass" @@ -492,14 +692,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "y is greater than or equal x + x is\n" + ] + } + ], "source": [ "# [ ] create an if/else statement that tests if y is greater than or equal x + x \n", "# [ ] print output: \"y greater than or equal x + x is\" True/False ...or a similar output\n", "x = 3\n", "y = x + 8\n", + "\n", + "if y >= x + x:\n", + " print(\"y is greater than or equal x + x is\")\n", "\n" ] }, @@ -546,9 +757,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# review and run code\n", "\"hello\" < \"Hello\"" @@ -556,19 +778,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# review and run code\n", - "\"Aardvark\" > \"Zebra\"" + "\"Aardvark\" < \"Zebra\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# review and run code\n", "'student' != 'Student'" @@ -576,9 +820,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'student' >= 'Student' is True\n", + "'Student' != 'Student' is False\n" + ] + } + ], "source": [ "# review and run code\n", "print(\"'student' >= 'Student' is\", 'student' >= 'Student')\n", @@ -587,9 +840,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# review and run code\n", "\"Hello \" + \"World!\" == \"Hello World!\"" @@ -606,7 +870,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -617,15 +881,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true\n" + ] + } + ], "source": [ "greeting = \"Hello\"\n", "# [ ] get input for variable named msg, and ask user to 'Say \"Hello\"'\n", "# [ ] print the results of testing if msg string equals greeting string\n", "\n", - "\n" + "msg = input('Say \"Hello\" ')\n", + "if msg == greeting:\n", + " print(\"true\")\n", + "else:\n", + " print(\"false\")\n" ] }, { @@ -646,9 +922,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "message as expected\n" + ] + } + ], "source": [ "# [ ] review and run code\n", "msg = \"Save the notebook\"\n", @@ -661,9 +945,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "message as expected\n" + ] + } + ], "source": [ "# [ ] review and run code\n", "msg = \"Save the notebook\"\n", @@ -686,12 +978,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "nope\n" + ] + } + ], "source": [ "# [ ] get input for a variable, answer, and ask user 'What is 8 + 13? : '\n", + "answer = input('What is 8 + 13? : ')\n", "# [ ] print messages for correct answer \"21\" or incorrect answer using if/else\n", + "if answer == \"21\":\n", + " print(\"correct\")\n", + "else:\n", + " print(\"nope\")\n", "# note: input returns a \"string\"\n", "\n", "\n" @@ -722,12 +1027,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The correct answer was True\n", + "The correct answer was Yes you can!\n" + ] + } + ], "source": [ "# [ ] Create the program, run tests\n", - "def tf_quiz(question=\"Should save your notebook after edit?(T/F): \",correct_ans=True):\n", + "def tf_quiz(question=\"Should save your notebook after edit?(T/F): \",correct_ans=\"True\"):\n", " user_answer = input(question)\n", " if user_answer == correct_ans:\n", " print(\"Correct!\",question,correct_ans)\n", @@ -795,9 +1109,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bring an umbrella and boots\n" + ] + } + ], "source": [ "# [ ] review the code then run testing different inputs\n", "# WHAT TO WEAR\n", @@ -815,9 +1137,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Guess is too high\n" + ] + } + ], "source": [ "# [ ] review the code then run testing different inputs\n", "# SECRET NUMBER GUESS\n", @@ -854,12 +1184,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We do not have an xs\n" + ] + } + ], "source": [ "# [ ] code and test SHIRT SALE\n", - "\n" + "shirt_size = input(\"Enter shirt size S,M,L, or XL: \")\n", + "if shirt_size.upper() == \"S\":\n", + " print(\"Small shirt is $6\")\n", + "elif shirt_size.upper() == \"M\":\n", + " print(\"Medium shirt is $7\")\n", + "elif shirt_size.upper() == \"L\":\n", + " print(\"Large shirt is $8\")\n", + "elif shirt_size.upper() == \"XL\":\n", + " print(\"Extra Large shirt is $9\")\n", + "else:\n", + " print(\"We do not have an\", shirt_size)\n" ] }, { @@ -910,28 +1258,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + } + ], "source": [ "str_num_1 = \"11\"\n", "str_num_2 = \"15\"\n", "int_num_3 = 10\n", "# [ ] Add the 3 numbers as integers and print the result\n", - "\n" + "total_number = int(str_num_1) + int(str_num_2) + int_num_3\n", + "print(total_number)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "111510\n" + ] + } + ], "source": [ "str_num_1 = \"11\"\n", "str_num_2 = \"15\"\n", "int_num_3 = 10\n", "# [ ] Add the 3 numbers as test strings and print the result\n", - "\n" + "total_number = str_num_1 + str_num_2 + str(int_num_3)\n", + "print(total_number)\n" ] }, { @@ -948,12 +1314,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + } + ], "source": [ "# [ ] code and test: adding using int casting\n", - "\n" + "str_integer = \"3\"\n", + "int_number = 5\n", + "number_total = int(str_integer) + int_number\n", + "print(number_total)\n" ] }, { @@ -975,9 +1352,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Next year student will be 6\n" + ] + } + ], "source": [ "# [ ] review and run code\n", "student_age = input('enter student age (integer): ')\n", @@ -987,9 +1372,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "In a decade the student will be 15\n" + ] + } + ], "source": [ "# [ ] review and run code\n", "# cast to int at input\n", @@ -1018,12 +1411,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n" + ] + } + ], "source": [ "# [ ] code and test the adding calculator\n", - "\n" + "first_number = input(\"enter first number\")\n", + "second_number = input(\"enter second nuber\")\n", + "total = int(first_number) + int(second_number)\n", + "print(total)\n" ] }, { @@ -1071,9 +1475,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3 + 5 = 8\n", + "3 + 5 - 9 = -1\n", + "48/9 = 5.333333333333333\n", + "5*5 = 25\n", + "(14 - 8)*(19/4) = 28.5\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "print(\"3 + 5 =\",3 + 5)\n", @@ -1085,9 +1501,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Now you have 5000000\n" + ] + } + ], "source": [ "# [ ] review and run example - 'million_maker'\n", "def million_maker():\n", @@ -1108,12 +1532,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "43 - 15 = 28\n" + ] + } + ], "source": [ "# [ ] print the result of subtracting 15 from 43\n", - "\n" + "print(\"43 - 15 = \", 43 - 15)\n" ] }, { @@ -1187,12 +1619,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 100, "metadata": {}, "outputs": [], "source": [ "# [ ] create and test multiply() function\n", - "\n", + "def multiply():\n", + " num1 = input(\"enter first number to multiply: \")\n", + " num2 = input(\"enter second number to multiply: \")\n", + " product = int(num1) * int(num2)\n", + " return f\"{num1_str} * {num2_str} = {product}\"\n", " " ] }, @@ -1236,15 +1672,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 102, "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 5)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m elif student_name.startswith(\"G\")\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben please wait for students with names staring with 'F' and 'G' to go first today.\n" ] } ], @@ -1253,7 +1688,7 @@ "student_name = input(\"enter name: \").capitalize()\n", "if student_name.startswith(\"F\"):\n", " print(student_name,\"Congratulations, names starting with 'F' get to go first today!\")\n", - "elif student_name.startswith(\"G\")\n", + "elif student_name.startswith(\"G\"):\n", " print(student_name,\"Congratulations, names starting with 'G' get to go second today!\")\n", "else:\n", " print(student_name, \"please wait for students with names staring with 'F' and 'G' to go first today.\")\n", @@ -1285,7 +1720,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_3.1_Practice.ipynb b/P1 Python Absolute Beginner/Module_3.1_Practice.ipynb index 8ee62fc4..2d121a20 100644 --- a/P1 Python Absolute Beginner/Module_3.1_Practice.ipynb +++ b/P1 Python Absolute Beginner/Module_3.1_Practice.ipynb @@ -17,17 +17,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Input your age (use only whole numbers): 23\n", "Age's first type is: \n", "Age's second type is: \n", - "In ten years you will be 33.\n" + "In ten years you will be 28.\n" ] } ], @@ -51,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": { "collapsed": true }, @@ -60,8 +59,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "True\n", - "3\n" + "101 is greater than 100 is: True\n" ] } ], @@ -71,10 +69,11 @@ "# print number \"greater than 100 is\" True/False\n", "# if number is NOT a digit string then message the user that \"only int is accepted\"\n", "\n", - "print(\"Dominic\".isalpha())\n", - "my_var = \"123\"\n", - "\n", - "print(len(my_var))\n" + "number = input(\"Input a number here: \")\n", + "if number .isdigit():\n", + " print(number + \" is greater than 100 is: \", int(number) >100)\n", + "else:\n", + " print(\"only int is accepted\")\n" ] }, { @@ -90,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -99,10 +98,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "Low\n", "Invalid - not alphabetical\n", - "Correct\n", - "On the third try! Sortta slow.\n" + "Invalid - not alphabetical\n", + "Invalid - not alphabetical\n", + "You lose.\n" ] } ], @@ -160,10 +159,19 @@ "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Correct\n", + "On the first try! What a mensch.\n" + ] + } + ], "source": [ "# [ ] call check_guess with user input\n", - "\n" + "letter_game(\"B\")\n" ] }, { @@ -182,15 +190,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Correct\n", + "Correct\n", + "On the first try! What a mensch.\n" + ] + } + ], "source": [ "# [ ] create letter_guess() function, call the function to test\n", + " \n", + "check_guess(\"A\", \"A\")\n", "\n", - "\n" + "def letter_guess(correct_answer):\n", + " this_guess = input(\"Guess the letter (provide one letter): \")\n", + " if True == check_guess(correct_answer,this_guess):\n", + " print(\"On the first try! What a mensch.\")\n", + " else:\n", + " #second guess\n", + " this_guess = input(\"Guess the letter (provide one letter): \")\n", + " if True == check_guess(correct_answer,this_guess):\n", + " print(\"On the second try! What a mensch.\")\n", + " else:\n", + " #third guess\n", + " this_guess = input(\"Guess the letter (provide one letter): \")\n", + " if True == check_guess(correct_answer,this_guess):\n", + " print(\"On the third try! Sortta slow.\")\n", + " else:\n", + " print(\"You lose.\")\n", + " \n", + "letter_guess(\"A\")\n" ] }, { @@ -210,14 +247,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You should get a dog, cat, or bird\n", + "thank you for the story\n" + ] + } + ], "source": [ "# [ ] complete pet conversation\n", - "\n" + "about_pet = input(\"What kind of pet do you have? \")\n", + "if about_pet.lower() == \"dog\":\n", + " print(\"That is great that you have a dog\")\n", + "elif about_pet.lower() == \"cat\":\n", + " print(\"that is great that you have a cat\")\n", + "elif about_pet == \"bird\":\n", + " print(\"that is great that you have a bird\")\n", + "else:\n", + " print(\"You should get a dog, cat, or bird\")\n", + "\n", + "print(\"thank you for the story\")" ] }, { @@ -262,25 +318,82 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Green\n", + "Thank you for playing\n" + ] + } + ], "source": [ "# [ ] complete rainbow colors\n", - "\n", + "fav_color = input(\"Give me your favorite color of the rainbow, only use first letter\")\n", + "if fav_color.lower() == \"r\":\n", + " print(\"Red\")\n", + "elif fav_color.lower() == \"o\":\n", + " print(\"Orange\")\n", + "elif fav_color.lower() == \"y\":\n", + " print(\"Yellow\")\n", + "elif fav_color.lower() == \"g\":\n", + " print(\"Green\")\n", + "elif fav_color.lower() == \"b\":\n", + " print(\"Blue\")\n", + "elif fav_color.lower() == \"i\":\n", + " print(\"Indigo\")\n", + "elif fav_color.lower() == \"v\":\n", + " print(\"Violet\")\n", + "else:\n", + " print(\"Not a rainbow color\")\n", + "print(\"Thank you for playing\")\n", "\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Red\n" + ] + } + ], "source": [ "# [ ] make the code above into a function rainbow_color() that has a string parameter, \n", "# get input and call the function and return the matching color as a string or \"no match\" message.\n", "# Call the function and print the return string.\n", - "\n" + "def rainbow_color(fav_color):\n", + " letter = fav_color.lower()\n", + " if letter.lower() == \"r\":\n", + " return \"Red\"\n", + " elif letter.lower() == \"o\":\n", + " return \"Orange\"\n", + " elif letter.lower() == \"y\":\n", + " return \"Yellow\"\n", + " elif letter.lower() == \"g\":\n", + " return \"Green\"\n", + " elif letter.lower() == \"b\":\n", + " return \"Blue\"\n", + " elif letter.lower() == \"i\":\n", + " return \"Indigo\"\n", + " elif letter.lower() == \"v\":\n", + " return \"Violet\"\n", + " else:\n", + " return (\"No match\")\n", + "\n", + "user_input = input(\"Give me your favorite color of the rainbow, only use first letter\")\n", + "\n", + "matching_color = rainbow_color(user_input)\n", + "\n", + "print(matching_color)" ] }, { @@ -296,12 +409,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"5 years old, 20 years diffence from now\"\n" + ] + } + ], "source": [ "# [ ] complete age_20()\n", - "\n" + "\n", + "def age_20(current_age):\n", + " if current_age >= 20:\n", + " return current_age - 20\n", + " else:\n", + " return current_age + 20\n", + " \n", + "age = input(\"Enter your age\")\n", + "age_int = int(age)\n", + "\n", + "new_age = age_20(age_int)\n", + "\n", + "print(f'\"{new_age} years old, 20 years diffence from now\"')" ] }, { @@ -316,66 +449,200 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "23" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] create rainbow_or_age()\n", - "\n" + "\n", + "def age_20(current_age):\n", + "\n", + " if current_age >= 20:\n", + " return current_age - 20\n", + " else:\n", + " return current_age + 20\n", + "\n", + "def rainbow_color(color_letter):\n", + "\n", + " letter = color_letter.lower()\n", + " \n", + " if letter == \"r\":\n", + " return \"Red\"\n", + " elif letter == \"o\":\n", + " return \"Orange\"\n", + " elif letter == \"y\":\n", + " return \"Yellow\"\n", + " elif letter == \"g\":\n", + " return \"Green\"\n", + " elif letter == \"b\":\n", + " return \"Blue\"\n", + " elif letter == \"i\":\n", + " return \"Indigo\"\n", + " elif letter == \"v\":\n", + " return \"Violet\"\n", + " else:\n", + " return \"no match\"\n", + "\n", + "\n", + "\n", + "def rainbow_or_age():\n", + " user_input = input(\"Give me your favorite color of the rainbow, only use first letter or your age as a number\")\n", + " if user_input.isdigit():\n", + " age = int(user_input)\n", + " return age_20(age)\n", + " elif user_input.isalpha():\n", + " return rainbow_color(user_input)\n", + " else:\n", + " return False\n", + " \n", + "rainbow_or_age()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n" + ] + } + ], "source": [ "# [ ] add 2 numbers from input using a cast to integer and display the answer \n", - "\n" + "age = input(\"enter your age: \")\n", + "age_2 = input(\"enter a second age: \")\n", + "\n", + "print(int(age) + int(age_2))\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the answer is... 25\n" + ] + } + ], "source": [ "# [ ] Multiply 2 numbers from input using cast and save the answer as part of a string \"the answer is...\"\n", "# display the string using print\n", + "num_1 = input(\"Number 1\")\n", + "num_2 = input(\"Number 2\")\n", + "\n", + "product = int(num_1) * int(num_2)\n", + "\n", + "print(\"the answer is... \" + str(product)) \n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15.0\n" + ] + } + ], "source": [ "# [ ] get input of 2 numbers and display the average: (num1 + num2) divided by 2\n", - "\n" + "num_3 = input(\"Number 3\")\n", + "num_4 = input(\"Number 4\")\n", + "\n", + "print((int(num_3) + int(num_4)) / 2)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The difference is: 10\n" + ] + } + ], "source": [ "# [ ] get input of 2 numbers and subtract the largest from the smallest (use an if statement to see which is larger)\n", "# show the answer\n", - "\n" + "num_5 = input(\"Number 5\")\n", + "num_6 = input(\"Number 6\")\n", + "\n", + "num_5_int = int(num_5)\n", + "num_6_int = int(num_6)\n", + "\n", + "if num_5_int > num_6_int:\n", + " differnece = num_5_int - num_6_int\n", + "\n", + "else:\n", + " differnece = num_6_int - num_5_int\n", + "\n", + "print(\"The difference is: \" + str(differnece))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The integer result is: 0\n" + ] + } + ], "source": [ "# [ ] Divide a larger number by a smaller number and print the integer part of the result\n", "# don't divide by zero! if a zero is input make the result zero\n", "# [ ] cast the answer to an integer to cut off the decimals and print the result\n", - "\n" + "\n", + "\n", + "num1_str = input(\"Enter the first number: \")\n", + "num2_str = input(\"Enter the second number: \")\n", + "\n", + "num1 = float(num1_str)\n", + "num2 = float(num2_str)\n", + "\n", + "if num1 == 0 or num2 == 0:\n", + " result = 0\n", + "elif num1 > num2:\n", + " division_result = num1 / num2\n", + " result = int(division_result)\n", + "else: \n", + " division_result = num2 / num1\n", + " result = int(division_result)\n", + "\n", + "\n", + "print(f\"The integer result is: {result}\")\n" ] }, { @@ -405,7 +672,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.1" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_3.2_Required_Code.ipynb b/P1 Python Absolute Beginner/Module_3.2_Required_Code.ipynb index be372666..17854570 100644 --- a/P1 Python Absolute Beginner/Module_3.2_Required_Code.ipynb +++ b/P1 Python Absolute Beginner/Module_3.2_Required_Code.ipynb @@ -48,13 +48,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "trusted": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50.0 costs $525.00\n" + ] + } + ], "source": [ - "# [ ] create fucntion, call and test \n" + "# [ ] create fucntion, call and test \n", + "def cheese_order(order_amount, max_order=100, min_order=1, price=10.50):\n", + "\n", + " \n", + " order_amount_num = float(order_amount)\n", + "\n", + "\n", + " if order_amount_num > max_order:\n", + " print(f\"{order_amount_num} is more than currently available stock\")\n", + " elif order_amount_num < min_order:\n", + " print(f\"{order_amount_num} is below minimum order amount\")\n", + " else:\n", + " cost = order_amount_num * price\n", + " print(f\"{order_amount_num} costs ${cost:.2f}\")\n", + "\n", + "order_weight = input(\"Ben Reed, enter cheese order weight (numeric value): \")\n", + "\n", + "\n", + "cheese_order(order_weight)" ] }, { @@ -81,7 +107,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_4.0_Tutorials_Nested_Conditionals.ipynb b/P1 Python Absolute Beginner/Module_4.0_Tutorials_Nested_Conditionals.ipynb index 45bb4e88..cdd65528 100644 --- a/P1 Python Absolute Beginner/Module_4.0_Tutorials_Nested_Conditionals.ipynb +++ b/P1 Python Absolute Beginner/Module_4.0_Tutorials_Nested_Conditionals.ipynb @@ -42,9 +42,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is your Manchego Cheese sandwich\n" + ] + } + ], "source": [ "# simplified example\n", "# [ ] review the code then run and following the flowchart paths\n", @@ -69,9 +77,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi, welcome to the sandwich shop. Please select a sandwich.\n", + "\n", + "Please select a cheese.\n", + "\n", + "Here is your Manchego Cheese sandwich. Thank you.\n", + "\n", + "Goodbye!\n" + ] + } + ], "source": [ "# full example: handling some invalid input and elif statement\n", "# [ ] review the code then run following the flowchart paths including **invalid responses** like \"xyz123\"\n", @@ -119,13 +141,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid input, please enter 'y' or 'n'.\n" + ] + } + ], "source": [ "# [ ] Say \"Hello\" with nested if\n", "# [ ] Challenge: handle input other than y/n\n", - "\n" + "\n", + "morning = input(\"Is it morning? (y/n): \")\n", + "if morning.lower() == \"y\":\n", + " print(\"Good morning!\")\n", + "elif morning == \"n\":\n", + " evening = input(\"Is it evening? (y/n): \")\n", + " if evening == \"y\":\n", + " print(\"Good evening!\")\n", + " elif evening == \"n\":\n", + " print(\"Hello!\")\n", + " else:\n", + " print(\"Invalid input, please enter 'y' or 'n'.\")\n", + "else:\n", + " print(\"Answer morning, please enter 'y' or 'n'.\")\n" ] }, { @@ -145,11 +188,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sorry, no more tries. The birds were: parrot, jay, robin\n" + ] + } + ], "source": [ - "# [ ] Create the \"Guess the bird\" program \n" + "# [ ] Create the \"Guess the bird\" program \n", + "birds = \"parrot, jay, robin\"\n", + "bird_guess = input(\"Guess a bird name: \")\n", + "if bird_guess.lower() in birds:\n", + " print(\"you found one on the first try!\")\n", + "else:\n", + " guess2 = input(\"sorry your bird was not found, try again: \")\n", + " if guess2.lower() in birds:\n", + " print(\"you found one on the second try!\")\n", + " else:\n", + " guess3 = input(\"Sorry your bird was not found. Last try: \")\n", + " if guess3.lower() in birds:\n", + " print(\"finally! You got one.\")\n", + " else:print(\"Sorry, no more tries. The birds were:\", birds)" ] }, { @@ -202,9 +266,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World!\n", + "I am formatting print \n" + ] + } + ], "source": [ "# review and run example using \\n (new line)\n", "print('Hello World!\\nI am formatting print ')" @@ -212,9 +285,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "STUDENT NAME\t\tAGE\n", + "Hiroto Yamaguchi \t17\n" + ] + } + ], "source": [ "# review and run code using \\t (tab)\n", "student_age = 17\n", @@ -225,9 +307,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"quotes in quotes\"\n", + "I've said \"save your notebook,\" so let's do it!\n", + "for a newline use \\n\n" + ] + } + ], "source": [ "# review and run code \n", "# using \\\" and \\' (escaped quotes)\n", @@ -249,35 +341,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"\\\\\\WARNING!///\"\n" + ] + } + ], "source": [ "# [ ] print \"\\\\\\WARNING!///\"\n", "\n", - "\n" + "print(\"\\\"\\\\\\\\\\\\WARNING!///\\\"\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"What's that?\" isn't a specific question.\n" + ] + } + ], "source": [ "# [ ] print output that is exactly (with quotes): \"What's that?\" isn't a specific question.\n", - "\n" + "print(\"\\\"What\\'s that?\\\" isn\\'t a specific question.\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "One\tTwo\tThree\n", + "Four\tFive\tSix\n" + ] + } + ], "source": [ "# [ ] from 1 print statement output the text commented below using no spaces\n", "# One Two Three\n", "# Four Five Six\n", - "\n" + "print(\"One\\tTwo\\tThree\\nFour\\tFive\\tSix\")\n" ] }, { @@ -301,20 +418,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "nice job\n" + ] + } + ], "source": [ "# [ ] create and test pre_word()\n", - "\n" + "def pre_word(test_word):\n", + " if test_word.startswith(\"pre\"):\n", + " if test_word.isalpha():\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " print(\"you need to input a valid \\\"pre\\\" word\")\n", + " return False\n", + "result = pre_word(input(\"Enter a word that starts with \\\"pre\\\": \"))\n", + "if result:\n", + " print(\"nice job\")\n", + "else:\n", + " print(\"try again\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pre\n" + ] + } + ], + "source": [ + "x = \"pregame\"\n", + "print(x[:3])" + ] }, { "cell_type": "markdown", @@ -327,12 +476,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello\n", + "World!\n" + ] + } + ], "source": [ "# [ ] review, run, fix\n", - "print(\"Hello/nWorld!)\n", + "print(\"Hello\\nWorld!\")\n", "\n" ] }, @@ -384,9 +542,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "write forever, unless there is a \"break\"\n" + ] + } + ], "source": [ "# Review and run code\n", "# this example never loops because the break has no conditions\n", @@ -397,9 +563,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 is incorrect\n", + "\n", + "2 is incorrect\n", + "\n", + "3 is incorrect\n", + "\n", + "4 is incorrect\n", + "\n", + "Yes 5 is correct!\n", + "\n" + ] + } + ], "source": [ "# [ ] review the NUMBER GUESS code then run - Q. what cause the break statement to run?\n", "number_guess = \"0\"\n", @@ -416,9 +599,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Sorry, not sure what to suggest for the\n", + "\n", + "\n", + "Sorry, not sure what to suggest for hot\n", + "\n", + "\n", + "\"quit\" detected, exiting\n" + ] + } + ], "source": [ "# [ ] review WHAT TO WEAR code then run testing different inputs\n", "while True:\n", @@ -458,12 +656,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Ben\n" + ] + } + ], "source": [ "# [ ] create Get Name program\n", - "\n" + "\n", + "familiar_name = \"\"\n", + "\n", + "while True:\n", + " familiar_name = input(\"Give me a familiar name: \")\n", + " if familiar_name != \"\":\n", + " break\n", + "print(\"Hello\", familiar_name)" ] }, { @@ -493,9 +706,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "4\n", + "6\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "votes = 3\n", @@ -510,9 +733,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-16\n", + "-17\n" + ] + } + ], "source": [ "print(votes)\n", "\n", @@ -522,9 +754,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "seat count: 0\n", + "seat count: 1\n", + "seat count: 2\n", + "seat count: 3\n", + "seat count: 4\n" + ] + } + ], "source": [ "# [ ] review the SEAT COUNT code then run \n", "\n", @@ -539,9 +783,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "invalid entry: counted as hard\n", + "\n", + "seats are full\n", + "4 Seats Total: 1 hard and 3 soft\n" + ] + } + ], "source": [ "# [ ] review the SEAT TYPE COUNT code then run entering: hard, soft, medium and exit\n", "\n", @@ -589,12 +844,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Shirts: 4\n", + "Small Total: 1\n", + "Medium total: 2\n", + "Large total: 1\n" + ] + } + ], "source": [ "# [ ] Create the Shirt Count program, run tests\n", - "\n" + "size_count = 0\n", + "small_shirt = 0\n", + "medium_shirt = 0\n", + "large_shirt = 0\n", + "num_shirt = 4\n", + "\n", + "# loops tallying seats using soft pads vs hard, until seats full or user \"exits\"\n", + "while size_count < num_shirt:\n", + " shirt_size = input('enter shirt size of \"S\", \"L\" or \"exit\" (to finish): ')\n", + " \n", + " if shirt_size.lower().startswith(\"s\"):\n", + " small_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower().startswith(\"m\"):\n", + " medium_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower().startswith(\"l\"):\n", + " large_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower() == \"exit\":\n", + " print(\"Exiting early.\")\n", + " break\n", + " else:\n", + " print(\"invalid entry\")\n", + "\n", + " \n", + "print(f\"Total Shirts: {size_count}\\nSmall Total: {small_shirt}\\nMedium total: {medium_shirt}\\nLarge total: {large_shirt}\")\n" ] }, { @@ -610,12 +902,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Small Total: 1\t\tSubTotal: 10.99\n", + "Medium total: 1\t\tSubTotal: 12.99\n", + "Large total: 2\t\tSubTotal: 29.98\n", + "Total Shirts: 4\t\t Total: 53.96\n" + ] + } + ], "source": [ "# [ ] Create the Shirt Register program, run tests\n", - "\n" + "\n", + "# [ ] Create the Shirt Count program, run tests\n", + "size_count = 0\n", + "small_shirt = 0\n", + "medium_shirt = 0\n", + "large_shirt = 0\n", + "num_shirt = 4\n", + "small_price = 10.99\n", + "medium_price = 12.99\n", + "large_price = 14.99\n", + "\n", + "# loops tallying seats using soft pads vs hard, until seats full or user \"exits\"\n", + "while size_count < num_shirt:\n", + " shirt_size = input('enter shirt size of \"S\", \"L\" or \"exit\" (to finish): ')\n", + " \n", + " if shirt_size.lower().startswith(\"s\"):\n", + " small_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower().startswith(\"m\"):\n", + " medium_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower().startswith(\"l\"):\n", + " large_shirt += 1\n", + " size_count += 1\n", + " elif shirt_size.lower() == \"exit\":\n", + " print(\"Exiting early.\")\n", + " break\n", + " else:\n", + " print(\"invalid entry\")\n", + "\n", + " \n", + "\n", + "print(f\"Small Total: {small_shirt}\\t\\tSubTotal: {small_shirt * small_price}\\nMedium total: {medium_shirt}\\t\\tSubTotal: {medium_shirt * medium_price}\\nLarge total: {large_shirt}\\t\\tSubTotal: {large_shirt * large_price}\")\n", + "print(f\"Total Shirts: {size_count}\\t\\t Total: {(small_shirt * small_price) + (medium_shirt * medium_price) + (large_shirt * large_price)}\")" ] }, { @@ -664,9 +1000,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8 !\n", + "7 !\n", + "6 !\n", + "5 !\n", + "4 !\n", + "3 !\n", + "2 !\n", + "\n", + "IGNITION!\n" + ] + } + ], "source": [ "# review and run GREET COUNT\n", "greet_count = 8\n", @@ -699,12 +1051,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " dog cat fish bird\n" + ] + } + ], "source": [ "# [ ] Create the Animal Names program, run tests\n", - "\n" + "num_animals = 0 \n", + "all_animals = \"\"\n", + "\n", + "while num_animals < 4:\n", + " all_animals += \" \" + input(\"Enter an animal name: \")\n", + " num_animals += 1\n", + " if \"exit\" in all_animals:\n", + " break\n", + "if \"exit\" in all_animals:\n", + " print(\"Exiting early\")\n", + "else:\n", + " print(all_animals)" ] }, { @@ -731,15 +1102,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Ben has been entered as first name.\n" + ] + } + ], "source": [ "# review and run example that loops until a valid first name format is entered\n", - "student_fname = \".\"\n", + "student_fname = \"\"\n", "while student_fname.isalpha()==False:\n", - " student_fname = input(\"enter student\\'s first (Letters only, No spaces): \")\n", - "print(\"\\n\" + student_fname.title(),\"has been entered as first name\")" + " student_fname = input(\"enter student\\'s first name (Letters only, No spaces): \")\n", + "print(\"\\n\" + student_fname.title(),\"has been entered as first name.\")" ] }, { @@ -766,11 +1146,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Your long number is: 102030\n" + ] + } + ], "source": [ - "# [ ] Create the program, run tests\n" + "# [ ] Create the program, run tests\n", + "int_num = input(\"Enter some digits (or a non string digit to quit): \")\n", + "\n", + "long_num = \"\"\n", + "\n", + "while int_num.isdigit():\n", + " long_num += int_num\n", + " int_num = input(\"Enter some digits (or a non string digit to quit): \")\n", + "\n", + "print(\"\\nYour long number is: \", long_num)\n" ] }, { @@ -786,15 +1184,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 x 1 = 1\n", + "2 x 2 = 4\n", + "3 x 3 = 9\n", + "4 x 4 = 16\n", + "5 x 5 = 25\n", + "6 x 6 = 36\n", + "7 x 7 = 49\n", + "8 x 8 = 64\n", + "9 x 9 = 81\n" + ] + } + ], "source": [ "# [ ] review the code, run, fix the Logic error\n", "count = 1\n", "\n", "# loop 5 times\n", - "while count > 5:\n", + "while count < 10:\n", " print(count, \"x\", count, \"=\", count*count)\n", " count +=1\n", " \n" @@ -825,7 +1239,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_4.1_Practice.ipynb b/P1 Python Absolute Beginner/Module_4.1_Practice.ipynb index 3ee967c6..9cccf237 100644 --- a/P1 Python Absolute Beginner/Module_4.1_Practice.ipynb +++ b/P1 Python Absolute Beginner/Module_4.1_Practice.ipynb @@ -21,36 +21,62 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The new line character is \\n\n" + ] + } + ], "source": [ "# [ ] print a string that outputs the following exactly: The new line character is \"\\n\"\n", - "\n" + "print(\"The new line character is \\\\n\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"That's how we escape!\"\n" + ] + } + ], "source": [ "# [ ] print output that is exactly (with quotes): \"That's how we escape!\"\n", - "\n" + "print(\"\\\"That's how we escape!\\\"\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\tone\n", + "22\ttwo\n", + "333\tthree\n" + ] + } + ], "source": [ "# [ ] with only 1 print statement and using No Space Characters, output the text commented below \n", "\n", "# 1 one\n", "# 22 two\n", "# 333 three\n", - "\n" + "print(\"1\\tone\\n22\\ttwo\\n333\\tthree\")\n" ] }, { @@ -68,13 +94,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Formatted string:\n", + "\"Hello\"\n" + ] + } + ], "source": [ "# [ ] create and test quote_me()\n", "\n", - "\n" + "def quote_me(text):\n", + "\n", + " if text.startswith('\"'):\n", + " return f\"'{text}'\"\n", + " else:\n", + " return f'\"{text}\"'\n", + "\n", + "user_input = input(\"enter a phrase or quote: \")\n", + "\n", + "formatted_string = quote_me(user_input)\n", + "\n", + "print(\"Formatted string:\")\n", + "print(formatted_string)" ] }, { @@ -97,11 +144,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Available\n", + "Your order for a Blue shirt in size M is confirmed.\n" + ] + } + ], "source": [ "# [ ] create shirt order using nested if \n", + "stock = {\n", + " \"white\": [\"l\", \"m\"],\n", + " \"blue\": [\"m\", \"s\"]\n", + "}\n", + "\n", + "color_input = input(\"What color shirt would you like?: White or Blue\")\n", + "size_input = input(\"What size would you like?: S, M, L\")\n", + "\n", + "color = color_input.lower()\n", + "size = size_input.lower()\n", + "\n", + "available = False\n", + "\n", + "if color in stock:\n", + " if size in stock [color]:\n", + " available = True\n", + "\n", + "if available:\n", + " print(\"Available\")\n", + " print(f\"Your order for a {color.capitalize()} shirt in size {size.upper()} is confirmed.\")\n", + "else:\n", + " print(\"Unavailable\")\n", + " print(\"The selected color and size combination is not in stock\")\n", + "\n", + "\n", + "\n", "\n" ] }, @@ -125,12 +207,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"bart\" is all alpha\n" + ] + } + ], "source": [ "# [ ] create and test str_analysis()\n", + "def str_analysis(user_string): \n", + " if user_string.isdigit():\n", + " number = int(user_string)\n", + " if number > 99:\n", + " print(f'\"{user_string}\" is a big number')\n", + " else: print(f'\"{user_string}\" is a small number')\n", + " elif user_string.isalpha():\n", + " print(f'\"{user_string}\" is all alpha')\n", + " else:\n", + " print(f'\"{user_string}\" is niether all alpha or all digits.')\n", "\n", + "user_input = input(\"Enter a word or a number: \")\n", + "\n", + "str_analysis(user_input)\n", + " \n", " " ] }, @@ -157,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -173,7 +277,7 @@ "True" ] }, - "execution_count": 9, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -189,7 +293,7 @@ " '''\n", " #TODO handle the situation in which user does not supply arguments; use input()\n", " if section == None:\n", - " section = input(\"Dominic Thomas Which section? (general or floor): \")\n", + " section = input(\"Ben Reed, Which section? (general or floor): \")\n", " \n", " if seats == None:\n", " seats = int(input(\"Seat number?: \"))\n", @@ -232,44 +336,124 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Existing loop\n", + "The total sum is: 15\n" + ] + } + ], "source": [ "# [ ] use a \"forever\" while loop to get user input of integers to add to sum, \n", "# until a non-digit is entered, then break the loop and print sum\n", "sum = 0\n", - "\n" + "\n", + "while True:\n", + " user_input = input(\"enter an integer to add (or a non_digit to quit):\")\n", + "\n", + " if user_input.isdigit():\n", + " number = int(user_input)\n", + " sum += number\n", + " if sum == 30:\n", + " break\n", + " else:\n", + " print(\"Exiting loop\")\n", + " break\n", + "print(f\"The total sum is: {sum}\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Try again\n", + "Try again\n", + "Winner winner, Chicken dinner\n" + ] + } + ], "source": [ "# [ ] use a while True loop (forever loop) to give 4 chances for input of a correct color in a rainbow\n", "# rainbow = \"red orange yellow green blue indigo violet\"\n", - "\n" + "\n", + "rainbow = \"red orange yellow green blue indigo violet\"\n", + "attempts = 1\n", + "\n", + "while True:\n", + " guess = input(f\"Attempt {attempts}: Guess a color of the rainbow: \")\n", + "\n", + " if guess.lower() in rainbow:\n", + " print(\"Winner winner, Chicken dinner\")\n", + " break\n", + " else:\n", + " print(\"Try again\")\n", + " attempts += 1\n", + "\n", + " if attempts >4:\n", + " print(\"\\nYou are out of guesses. Game over.\")\n", + " break\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "thanks for playing, title is in correct format\n" + ] + } + ], "source": [ "# [ ] Get input for a book title, keep looping while input is Not in title format (title is every word capitalized)\n", "title = \"\"\n", - "\n" + "\n", + "while True:\n", + " title = input(\"Enter a book title\")\n", + "\n", + " if title.istitle():\n", + " print(\"thanks for playing, title is in correct format\")\n", + " break\n", + " else:\n", + " print(\"Invalid format\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "👎 Wrong\n", + "✓ Correct.\n" + ] + } + ], "source": [ "# [ ] create a math quiz question and ask for the solution until the input is correct\n", - "\n" + "\n", + "while True:\n", + " answer = input(\"what is 10 + 5\")\n", + "\n", + " if answer == \"15\":\n", + " print(\"\\u2713 Correct.\")\n", + " break\n", + " else:\n", + " print(\"\\U0001F44E Wrong\")" ] }, { @@ -281,17 +465,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sorry, not a winner.\n", + "you win!\n", + "Game ended\n" + ] + } + ], "source": [ "# [ ] review the code, run, fix the error\n", - "tickets = input(\"enter tickets remaining (0 to quit): \")\n", + "tickets = int(input(\"enter tickets remaining (0 to quit): \"))\n", "\n", "while tickets > 0:\n", " # if tickets are multiple of 3 then \"winner\"\n", " if int(tickets/3) == tickets/3:\n", " print(\"you win!\")\n", + " break\n", " else:\n", " print(\"sorry, not a winner.\")\n", " tickets = int(input(\"enter tickets remaining (0 to quit): \"))\n", @@ -316,13 +511,40 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Incorrect. Try again. \n", + "\n", + "Correct\n", + "Correct\n", + "Quiz complete\n" + ] + } + ], "source": [ "# Create quiz_item() and 2 or more quiz questions that call quiz_item()\n", "\n", - "#quiz_item()has 2 parameter strings: question and solution\n" + "#quiz_item()has 2 parameter strings: question and solution\n", + "def quiz_item(question, solution):\n", + " while True:\n", + " answer = input(question)\n", + " if answer.strip().lower() == solution.strip().lower():\n", + " print(\"Correct\")\n", + " return True\n", + " else:\n", + " print(\"Incorrect. Try again. \\n\")\n", + "\n", + "quiz_item(\"What is the capital of Georgia?.\\nAnswer: \", \"Atlanta\")\n", + "\n", + "question_2 = \"What is the first color in the rainbow?\\nAnswer: \"\n", + "quiz_item(question_2, \"Red\")\n", + "\n", + "print(\"Quiz complete\") " ] }, { @@ -352,7 +574,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_4.2_Required_Code.ipynb b/P1 Python Absolute Beginner/Module_4.2_Required_Code.ipynb index fcd2e07e..72f924e4 100644 --- a/P1 Python Absolute Beginner/Module_4.2_Required_Code.ipynb +++ b/P1 Python Absolute Beginner/Module_4.2_Required_Code.ipynb @@ -83,15 +83,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "trusted": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 is a small number\n" + ] + } + ], "source": [ "# [ ] create, call and test the str_analysis() function \n", "\n", + "def str_analysis(text):\n", + " if text.isdigit():\n", + " number = int(text)\n", + " if number > 99:\n", + " return f'{number} is a big number'\n", + " else:\n", + " return f'{number} is a small number'\n", + " elif text.isalpha():\n", + " return f'{text} is all alpha'\n", + " else:\n", + " return f'{text} has mutiple character types'\n", "\n", + "while True:\n", + "\n", + " user_input = input(\"Benjamin Reed, enter word or integer: \")\n", + "\n", + " if user_input:\n", + " break\n", + "\n", + "analysis_message = str_analysis(user_input)\n", + "\n", + "print(analysis_message)\n", "\n", "\n" ] @@ -120,7 +149,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1 Python Absolute Beginner/Module_5_Required_FINAL_Project.ipynb b/P1 Python Absolute Beginner/Module_5_Required_FINAL_Project.ipynb index 7093cd29..e5ad40ac 100644 --- a/P1 Python Absolute Beginner/Module_5_Required_FINAL_Project.ipynb +++ b/P1 Python Absolute Beginner/Module_5_Required_FINAL_Project.ipynb @@ -89,13 +89,68 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "--- Running Report Type 'T' ---\n", + "Input an integer to add to the total or 'Q' to quit\n", + "\n", + "Total\n", + "35\n", + "Calculated by: Benjamin S. Reed\n" + ] + } + ], "source": [ - "# [ ] create, call and test the adding_report() function\n" + "# [ ] create, call and test the adding_report() function\n", + "def adding_report(report_type = \"T\"):\n", + " ##Takes integer input from the user until they quit, prints total.\n", + "\n", + " total = 0 ##resets the total sum for each time the function is called.\n", + " items = \"\" ##resets the string for each time the function is called for the A report.\n", + " print(\"Input an integer to add to the total or 'Q' to quit\")\n", + "\n", + " while True:\n", + " user_input = input('Enter an integer or \"Q\" to quit: ') # gets input from the user.\n", + "\n", + " if user_input.isdigit(): ##checks in input is a digit.\n", + " number = int(user_input) #if the number is a string, cast to integer.\n", + " total += number ##take the number and add it to the total\n", + "\n", + " if report_type == \"A\":\n", + " items += user_input + \"\\n\" ##if the report type is A, add the input to items list.\n", + " \n", + " elif user_input.lower().startswith(\"q\"): ##if input is not a digit, check if it is the quit command.\n", + "\n", + " if report_type == \"A\": ##If the report type is A, print all of the input integers and the total.\n", + " print(\"\\nItems\")\n", + " print(items)\n", + " print(\"Total\")\n", + " print(total)\n", + " else:\n", + " print(\"\\nTotal\") ##If the report type is T, or any other type, print only the total.\n", + " print(total)\n", + "\n", + " print(\"Calculated by: Benjamin S. Reed\")\n", + " break\n", + "\n", + " else:\n", + " print(f'\"{user_input}\" is invalid')\n", + "\n", + "##print(\"\\n--- Running Report Type 'A' ---\")\n", + "##adding_report(\"A\")\n", + "\n", + "print(\"\\n\\n--- Running Report Type 'T' ---\")\n", + "adding_report(\"T\")\n", + "\n" ] }, { @@ -122,7 +177,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P1M1BenReed.py.py b/P1M1BenReed.py.py new file mode 100644 index 00000000..7e780990 --- /dev/null +++ b/P1M1BenReed.py.py @@ -0,0 +1,18 @@ +# Create name check code + +# [ ] get input for input_test variable +input_test = input("Please enter a names of people met in the last 24 hours: ") +# [ ] print "True" message if "John" is in the input or False message if not +print("John".lower() in input_test.lower()) + +# [ ] print True message if your name is in the input or False if not +my_name = "Ben" +print(my_name.lower() in input_test.lower()) + +# [ ] Challenge: Check if another person's name is in the input - print message +other_name = "Rhonda" +print(other_name.lower() in input_test.lower()) + +# [ ] Challenge: Check if a fourth person's name is in the input - print message +fourth_name = "Apple" +print(fourth_name.lower() in input_test.lower()) diff --git a/P1M1_practice_code_screenshot.png b/P1M1_practice_code_screenshot.png new file mode 100644 index 00000000..2b9d4d49 Binary files /dev/null and b/P1M1_practice_code_screenshot.png differ diff --git a/P1M4BenReed.py b/P1M4BenReed.py new file mode 100644 index 00000000..8481d4cf --- /dev/null +++ b/P1M4BenReed.py @@ -0,0 +1,24 @@ +# [ ] create, call and test the str_analysis() function + +def str_analysis(text): + if text.isdigit(): + number = int(text) + if number > 99: + return f'{number} is a big number' + else: + return f'{number} is a small number' + elif text.isalpha(): + return f'{text} is all alpha' + else: + return f'{text} has mutiple character types' + +while True: + + user_input = input("Benjamin Reed, enter word or integer: ") + + if user_input: + break + +analysis_message = str_analysis(user_input) + +print(analysis_message) diff --git a/P1M5BenjaminReed.py b/P1M5BenjaminReed.py new file mode 100644 index 00000000..0ae1128d --- /dev/null +++ b/P1M5BenjaminReed.py @@ -0,0 +1,42 @@ +# [ ] create, call and test the adding_report() function +def adding_report(report_type = "T"): + ##Takes integer input from the user until they quit, prints total. + + total = 0 ##resets the total sum for each time the function is called. + items = "" ##resets the string for each time the function is called for the A report. + print("Input an integer to add to the total or 'Q' to quit") + + while True: + user_input = input('Enter an integer or "Q" to quit: ') # gets input from the user. + + if user_input.isdigit(): ##checks in input is a digit. + number = int(user_input) #if the number is a string, cast to integer. + total += number ##take the number and add it to the total + + if report_type == "A": + items += user_input + "\n" ##if the report type is A, add the input to items list. + + elif user_input.lower().startswith("q"): ##if input is not a digit, check if it is the quit command. + + if report_type == "A": ##If the report type is A, print all of the input integers and the total. + print("\nItems") + print(items) + print("Total") + print(total) + else: + print("\nTotal") ##If the report type is T, or any other type, print only the total. + print(total) + + print("Calculated by: Benjamin S. Reed") + break + + else: + print(f'"{user_input}" is invalid') + + +print("\n--- Running Report Type 'A' ---") +adding_report("A") + +##print("\n\n--- Running Report Type 'T' ---") +##adding_report("T") + diff --git a/P2 Python Fundamentals/Module_1.0_Tutorials_Indexes_String_Sequences_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_1.0_Tutorials_Indexes_String_Sequences_Python_Fundamentals.ipynb index b71e1641..5b4f355c 100644 --- a/P2 Python Fundamentals/Module_1.0_Tutorials_Indexes_String_Sequences_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_1.0_Tutorials_Indexes_String_Sequences_Python_Fundamentals.ipynb @@ -55,9 +55,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A <-- first character at index 0\n", + "l\n", + "t\n", + "o\n", + "n\n" + ] + } + ], "source": [ "# [ ] review and run example - note the first element is always index = 0\n", "student_name = \"Alton\"\n", @@ -70,9 +82,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Winner! Name starts with J: Jin\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Jin\"\n", @@ -86,9 +106,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "s\n", + "s\n" + ] + } + ], "source": [ "# [ ] review and run ERROR example\n", "# cannot index out of range\n", @@ -116,26 +145,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "H\n", + "m\n", + "o\n" + ] + } + ], "source": [ "# [ ] assign a string 5 or more letters long to the variable: street_name\n", "# [ ] print the 1st, 3rd and 5th characters\n", "\n", + "street_name = \"Hemlock\"\n", + "\n", + "print(street_name[0])\n", + "print(street_name[2])\n", + "print(street_name[4])\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Winner! Name starts with I: Right Team\n" + ] + } + ], "source": [ "# [ ] Create an input variable: team_name - ask that second letter = \"i\", \"o\", or \"u\"\n", "# [ ] Test if team_name 2nd character = \"i\", \"o\", or \"u\" and print a message\n", "# note: use if, elif and else\n", - "\n" + "team_name = input(\"Create a team name with a second letter of i, o, or u: \")\n", + "\n", + "if team_name[1].lower() == \"i\":\n", + " print('Winner! Name starts with I:', team_name)\n", + "\n", + "elif team_name[1].lower() == \"o\":\n", + " print('Winner! Name starts with O:', team_name)\n", + "\n", + "elif team_name[1].lower() == \"u\":\n", + " print('Winner! Name starts with U:', team_name)\n", + "\n", + "else:\n", + " print('Not a match, try again tomorrow:', team_name)\n" ] }, { @@ -176,9 +240,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Joana ends with 'a'\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Joana\"\n", @@ -190,9 +262,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Joana has 2nd to last letter of 'n'\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# get second to last letter\n", @@ -202,9 +282,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for Joana\n", + "index 3 = 'n'\n", + "index -2 = 'n'\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# you can get to the same letter with index counting + or -\n", @@ -225,25 +315,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i n g\n" + ] + } + ], "source": [ "# [ ] assign a string 5 or more letters long to the variable: street_name\n", "# [ ] print the last 3 characters of street_name\n", - "\n" + "street_name = \"string\"\n", + "\n", + "print(street_name[3],street_name[4],street_name[5])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "s\n", + "g\n" + ] + } + ], "source": [ "# [ ] create and assign string variable: first_name\n", "\n", "# [ ] print the first and last letters of name\n", - "\n" + "\n", + "first_name = \"string\"\n", + "\n", + "print(first_name[0])\n", + "print(first_name[-1])" ] }, { @@ -259,14 +372,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "s\n" + ] + } + ], "source": [ "# [ ] Review, Run, Fix the error using string index\n", "shoe = \"tennis\"\n", "# print the last letter\n", - "print(shoe(-1))\n", + "print(shoe[-1])\n", "\n" ] }, @@ -320,9 +441,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "slice student_name[2:5]: let\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# assign string to student_name\n", @@ -334,9 +463,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "index 2, 3 & 4 of student_name: let\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# assign string to student_name\n", @@ -348,9 +485,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "knowledge\n", + "knowledge is the 3rd char through the 11th char\n", + "knowledge is the index 2, \"k\", through index 10, \"e\"\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "long_word = 'Acknowledgement'\n", @@ -374,25 +521,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "act\n", + "tic\n" + ] + } + ], "source": [ "# [ ] slice long_word to print \"act\" and to print \"tic\"\n", "long_word = \"characteristics\"\n", "\n", + "print(long_word[4:7])\n", + "print(long_word[11:14])\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sequence\n" + ] + } + ], "source": [ "# [ ] slice long_word to print \"sequence\"\n", "long_word = \"Consequences\"\n", - "\n" + "\n", + "print(long_word[3:11])" ] }, { @@ -423,9 +590,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Col\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Colette\"\n", @@ -445,7 +620,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -510,9 +685,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'ette'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Colette\"\n", @@ -532,13 +718,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "uences\n" + ] + } + ], "source": [ "# [ ] print the second half of the long_word\n", "long_word = \"Consequences\"\n", - "\n" + "\n", + "print(long_word[6:])\n" ] }, { @@ -570,9 +765,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Colette\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Colette\"\n", @@ -582,9 +785,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Clte\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Colette\"\n", @@ -594,9 +805,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ot\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Colette\"\n", @@ -606,9 +825,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "osqe\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "long_word = \"Consequences\"\n", @@ -628,23 +855,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Anlge\n" + ] + } + ], "source": [ "# [ ] print the 1st and every 3rd letter of long_word\n", "long_word = \"Acknowledgement\"\n", - "\n" + "print(long_word[0::3])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "koldeet\n" + ] + } + ], "source": [ "# [ ] print every other character of long_word starting at the 3rd character\n", - "long_word = \"Acknowledgement\"\n" + "long_word = \"Acknowledgement\"\n", + "print(long_word[2::2])" ] }, { @@ -673,11 +917,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "scitsiretcarahc\n" + ] + } + ], "source": [ "# [ ] review and run example of stepping backwards using [::-1]\n", "long_word = \"characteristics\"\n", @@ -687,9 +939,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tcarahc\n" + ] + } + ], "source": [ "# [ ] review and run example of stepping backwards using [6::-1]\n", "long_word = \"characteristics\"\n", @@ -710,24 +970,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "desserts\n" + ] + } + ], "source": [ "# [ ] reverse long_word\n", "long_word = \"stressed\"\n", - "\n" + "\n", + "print(long_word[::-1])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "arahc\n" + ] + } + ], "source": [ "# [ ] print the first 5 letters of long_word in reverse\n", "long_word = \"characteristics\"\n", - "\n" + "print(long_word[4::-1])\n" ] }, { @@ -743,15 +1020,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "time\n", + "emit\n", + "enil\n", + "nile\n" + ] + } + ], "source": [ "# [ ] print the first 4 letters of long_word\n", "# [ ] print the first 4 letters of long_word in reverse\n", "# [ ] print the last 4 letters of long_word in reverse\n", "# [ ] print the letters spanning indexes 3 to 6 of long_word in Reverse\n", - "long_word = \"timeline\"\n" + "long_word = \"timeline\"\n", + "print(len(long_word))\n", + "print(long_word[0:4])\n", + "print(long_word[3::-1])\n", + "print(long_word[:-5:-1])\n", + "print(long_word[6:2:-1])" ] }, { @@ -804,22 +1098,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "c\n", + "e\n", + "l\n", + "l\n", + "o\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "word = \"cello\"\n", "\n", - "for x in word:\n", - " print(x)" + "for larry in word:\n", + " print(larry)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t\n", + "r\n", + "u\n", + "m\n", + "p\n", + "e\n", + "t\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# note: the variable 'letter' changed to 'item'\n", @@ -831,9 +1151,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "p\n", + "i\n", + "a\n", + "n\n", + "o\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# note: variable is now 'xyz' \n", @@ -846,9 +1178,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Skye to SkYe\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# creates a new string (new_name) adding a letter (ltr) each loop\n", @@ -879,15 +1219,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "B\n", + "e\n", + "n\n", + "j\n", + "a\n", + "m\n", + "i\n", + "n\n" + ] + } + ], "source": [ "# [ ] Get user input for first_name\n", "# [ ] iterate through letters in first_name \n", "# - print each letter on a new line\n", + "first_name = input(\"First Name?\")\n", "\n", - "\n", + "for x in first_name:\n", + " print(x)\n", "\n" ] }, @@ -909,12 +1266,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wesley stuart reed to wEslEy stUArt rEEd\n" + ] + } + ], "source": [ "# [ ] Create capitalize-io\n", - "\n" + "\n", + "old_name = input(\"Give me your youngest son's name: \")\n", + "new_name = \"\"\n", + "\n", + "for ltr in old_name:\n", + " if ltr.lower() in \"aeiou\":\n", + " new_name += ltr.upper()\n", + " else:\n", + " new_name += ltr\n", + "print(old_name,\"to\",new_name)" ] }, { @@ -946,22 +1320,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Y\n", + "K\n", + "S\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "student_name = \"Skye\"\n", "\n", "for letter in student_name[2::-1]:\n", - " print(letter.lower())" + " print(letter.upper())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "y\n", + "k\n", + "S\n" + ] + } + ], "source": [ "# Iterate BACKWARDS\n", "# [ ] review and run example\n", @@ -985,26 +1379,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "jxaoiin\n" + ] + } + ], "source": [ "# [ ] create & print a variable, other_word, made of every other letter in long_word\n", "long_word = \"juxtaposition\"\n", - "\n" + "other_word = \"\"\n", + "\n", + "for index in range(len(long_word)):\n", + " if index % 2 == 0:\n", + " other_word += long_word[index]\n", + "\n", + " \n", + "print(other_word)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "!sgwaD og ,deRRed, go Dawgs!\n" + ] + } + ], "source": [ "# Mirror Color\n", "# [ ] get user input, fav_color\n", "# [ ] print fav_color backwards + fav_color\n", "# example: \"Red\" prints \"deRRed\"\n", - "\n" + "\n", + "fav_color = input(\"Tell me your fav color: \")\n", + "\n", + "print(fav_color[::-1] + fav_color)" ] }, { @@ -1074,9 +1494,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of characters in string\n", + "14 \n", + "\n", + "letter \"e\" occurrences\n", + "2 \n", + "\n", + "find the index of the first space\n", + "4 \n", + "\n", + "find the index of \"u\" searching a slice work_tip[3:9] - e your\n", + "7 \n", + "\n", + "find the index of \"e\" searching a slice work_tip[4:] - your code\n", + "13\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "work_tip = \"save your code\"\n", @@ -1107,9 +1548,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sentence: \"good code is commented code\" has character length = 27\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "work_tip = \"good code is commented code\"\n", @@ -1119,9 +1568,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "good code is c\n", + "ommented code.\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# find the middle index\n", @@ -1145,9 +1603,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "good code is commented code.\n", + "how many w's? 0\n", + "how many o's? 5\n", + "uses 'code', how many times? 2\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "print(work_tip)\n", @@ -1158,9 +1627,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "good code is c\n", + "# o's in first half\n", + "3\n", + "\n", + "ommented code.\n", + "# o's in second half\n", + "2\n" + ] + } + ], "source": [ "# [ ] review and run example \n", "print(work_tip[:mid_pt])\n", @@ -1186,9 +1669,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "good code has meaningful variable names\n", + "5 = starting index for \"code\"\n" + ] + } + ], "source": [ "# [ ] review and run example \n", "work_tip = \"good code has meaningful variable names\"\n", @@ -1200,23 +1692,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "search for \"meaning\" in the sub-string: meaningful variable \n", + "\n", + "\"meaning\" found in work_tip[13:33] sub-string search at index 14\n", + "1\n" + ] + } + ], "source": [ "# [ ] review and run example \n", "# set start index = 13 and end index = 33\n", "print('search for \"meaning\" in the sub-string:', work_tip[13:33],\"\\n\")\n", - "meaning_here = work_tip.find(\"code\",13,33)\n", + "meaning_here = work_tip.find(\"meaning\",13,33)\n", "print('\"meaning\" found in work_tip[13:33] sub-string search at index', meaning_here)\n", - "print(work_tip[13:33].find(\"code\"))" + "print(work_tip[13:33].find(\"meaning\"))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "work_tip: good code has meaningful variable names\n", + "'o' at index = 1\n", + "'o' at index = 2\n", + "'o' at index = 6\n", + "no more o's\n" + ] + } + ], "source": [ "# [ ] review and run example \n", "# if .find(\"o\") has No Match, -1 is returned\n", @@ -1245,14 +1760,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wear a hat w\n", + "hen it rains\n" + ] + } + ], "source": [ "# [ ] use len() to find the midpoint of the string \n", "# [ ] print the halves on separate lines\n", "random_tip = \"wear a hat when it rains\"\n", - "\n", + "midpoint = len(random_tip) // 2\n", + "print(random_tip[:midpoint])\n", + "print(random_tip[midpoint:])\n", "\n" ] }, @@ -1268,16 +1794,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Count of 'e': 2\n", + "Count of 'a': 4\n", + "The letter 'a' is more frequent\n" + ] + } + ], "source": [ "# for letters: \"e\" and \"a\" in random_tip\n", "# [ ] print letter counts \n", "# [ ] BONUS: print which letter is most frequent\n", "random_tip = \"wear a hat when it rains\"\n", "\n", - "\n" + "e_count = random_tip.count(\"e\")\n", + "a_count = random_tip.count(\"a\")\n", + "\n", + "print(\"Count of 'e': \", e_count)\n", + "print(\"Count of 'a': \", a_count)\n", + "\n", + "if e_count > a_count:\n", + " print(\"The letter 'e' is more frequent\")\n", + "elif a_count > e_count:\n", + " print(\"The letter 'a' is more frequent\")\n", + "else:\n", + " print(\"The letters 'a' and 'e' appear the same amount of times\")\n" ] }, { @@ -1293,13 +1840,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "taposit\n" + ] + } + ], "source": [ "# [ ] print long_word from the location of the first and second \"t\"\n", "long_word = \"juxtaposition\"\n", - "\n" + "\n", + "first_t_index = long_word.find(\"t\") ##find the index of the first t\n", + "second_t_index = long_word.find(\"t\", first_t_index + 1)##find the t after the first t\n", + "\n", + "if first_t_index != -1 and second_t_index != +1:\n", + " print(long_word[first_t_index : second_t_index + 1])\n", + "\n", + "else: print(\"Could not find two 't's in the word.\")\n" ] }, { @@ -1330,12 +1892,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "they\n", + "stumble\n", + "who\n", + "run\n", + "fast\n" + ] + } + ], "source": [ "# [ ] Print each word in the quote on a new line \n", "quote = \"they stumble who run fast\"\n", + "\n", + "\n", + "while quote.find(\" \") != -1:\n", + " space_index = quote.find(\" \")\n", + "\n", + " print(quote[0:space_index])\n", + "\n", + " quote = quote[space_index + 1:]\n", + "\n", + "print(quote)\n", + "\n", + "\n", "\n" ] }, @@ -1364,7 +1950,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.1" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_1.1_Practice_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_1.1_Practice_Python_Fundamentals.ipynb index 2633d36b..2548ec2d 100644 --- a/P2 Python Fundamentals/Module_1.1_Practice_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_1.1_Practice_Python_Fundamentals.ipynb @@ -26,46 +26,84 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "u\n" + ] + } + ], "source": [ "# [ ] access and print the second character from planet_name: \"u\"\n", "planet_name = \"Jupiter\"\n", - "\n" + "print(planet_name[1])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "J\n" + ] + } + ], "source": [ "# [ ] access and print the first character from planet_name: \"J\"\n", "planet_name = \"Jupiter\"\n", - "\n" + "\n", + "print(planet_name[0])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First character: J\n", + "Last character: r\n" + ] + } + ], "source": [ "# [ ] access and print the first and last characters from planet_name\n", "planet_name = \"Jupiter\"\n", - "\n" + "\n", + "print(\"First character:\", planet_name[0])\n", + "\n", + "print(\"Last character:\", planet_name[-1])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "J\n" + ] + } + ], "source": [ "# [ ] using a negative index access and print the first character from planet_name: \"J\"\n", "planet_name = \"Jupiter\"\n", - "\n" + "\n", + "print(planet_name[-7])" ] }, { @@ -81,35 +119,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Nep\n", + "tune\n" + ] + } + ], "source": [ "# [ ] print planet_name sliced into the first 3 characters and remaining characters\n", "planet_name = \"Neptune\"\n", - "\n" + "\n", + "print(planet_name[0:3])\n", + "print(planet_name[3::])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python\n" + ] + } + ], "source": [ "# [ ] print 1st char and then every 3rd char of wise_words\n", "# use string slice with a step\n", "wise_words = 'Play it who opens'\n", - "\n" + "\n", + "print(wise_words[0::3])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enutpeN\n" + ] + } + ], "source": [ "# [ ] print planet_name in reverse\n", - "\n" + "\n", + "print(planet_name[::-1])" ] }, { @@ -127,15 +194,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "P\n", + "i\n", + "z\n", + "z\n", + "a\n" + ] + } + ], "source": [ "# [ ] Get user input for 1 fav_food\n", "# [ ] iterate through letters in fav_food \n", "# - print each letter on a new line\n", "\n", + "fav_food = input(\"What is your favoriote food?: \")\n", "\n", + "for letter in fav_food:\n", + " print(letter)\n", "\n" ] }, @@ -143,36 +225,72 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Good-code-is-commented-code\n" + ] + } + ], "source": [ "# [ ] iterate work_tip string concatenate each letter to variable: new_string \n", - "# [ ] concatenate the letter or a \"-\" instead of a space \" \"\n", + "# [ ] concatenate the letter to a \"-\" instead of a space \" \"\n", "# tip: concatenate string example: word = word + \"a\"\n", "work_tip = \"Good code is commented code\"\n", "\n", + "new_string = \"\"\n", + "\n", + "for letter in work_tip:\n", + " if letter == \" \":\n", + " new_string += \"-\"\n", + "\n", + " else:\n", + " new_string += letter\n", + "\n", + "print(new_string)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hiro\n" + ] + } + ], "source": [ "# [ ] Print the first 4 letters of name on new line\n", "name = \"Hiroto\"\n", - "\n" + "\n", + "print(name[0:4])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ioo\n" + ] + } + ], "source": [ "# [ ] Print every other letter from 2nd to last letter of name \n", "name = \"Hiroto\"\n", - "\n" + "\n", + "print(name[1::2])" ] }, { @@ -195,12 +313,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d??R ?r?u?S nim?jn?B\n" + ] + } + ], "source": [ "# [ ] Create Mystery Name\n", - "\n" + "\n", + "first_name = input(\"What is the name\")\n", + "\n", + "new_name = \"\"\n", + "\n", + "for letter in first_name[::-1]:\n", + " if letter.lower() == \"e\":\n", + " new_name += \"?\"\n", + " elif letter.lower() == \"t\":\n", + " new_name += \"?\"\n", + " elif letter.lower() == \"a\":\n", + " new_name += \"?\"\n", + " else:\n", + " new_name += letter\n", + "\n", + "print(new_name)" ] }, { @@ -224,50 +365,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + } + ], "source": [ "# [ ] find and display the length of the string: topic\n", "topic = \"len() returns the length of a string\"\n", - "\n" + "\n", + "print(len(topic))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The middle index is: 28\n" + ] + } + ], "source": [ "# [ ] use len() to find and display the mid_pt (middle) index (+/- 1) of the string: topic\n", "# note: index values are whole numbers\n", "topic = \"len() can take a sequence, like a string, as an argument\"\n", - "\n" + "\n", + "string_length = len(topic)\n", + "\n", + "mid_pt = string_length //2\n", + "print(\"The middle index is: \", mid_pt)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ "# [ ] print index where first instance of the word \"code\" starts using .find()\n", "work_tip = \"Good code is commented code\"\n", - "\n" + "\n", + "print(work_tip.find(\"code\"))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\"code\" found at index 23\n" + ] + } + ], "source": [ "# [ ] search for \"code\" in code_tip using .find() \n", "# [ ] search substring with substring index start= 13,end = last char \n", "# [ ] save result in variable: code_index\n", "# [ ] display index of where \"code\" is found, or print \"not found\" if code_index == -1\n", "work_tip = \"Good code is commented code\"\n", - "\n" + "\n", + "code_index = work_tip.find(\"code\", 13)\n", + "\n", + "if code_index == -1:\n", + " print(\"not found\")\n", + "\n", + "else:\n", + " print(f'\"code\" found at index {code_index}')\n" ] }, { @@ -282,14 +468,17 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Ws = 0 Os= 5 Codes= 2 Number of letters: 27\n" + "Ws = 0 \n", + "Os = 5 \n", + "Codes = 2 \n", + "Number of letters: 27\n" ] } ], @@ -311,22 +500,56 @@ " codes += 1\n", " i += 1\n", "\n", - "print(\"Ws = \",ws,\" Os= \", os, \"Codes= \", codes, \"Number of letters: \", i)\n", - "print(work_tip[27])" + "print(\"Ws = \",ws, \"\\nOs = \", os, \"\\nCodes = \", codes, \"\\nNumber of letters: \", i)\n", + "##print(work_tip[27])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "code_tip: code a conditional decision like you would say it\n", + "\n", + "The letter 'i' appears 6 times.\n", + "\n", + "Fiunding all occurances of the letter 'i': \n", + "Found 'i' at index: 11\n", + "Found 'i' at index: 13\n", + "Found 'i' at index: 22\n", + "Found 'i' at index: 24\n", + "Found 'i' at index: 29\n", + "Found 'i' at index: 47\n" + ] + } + ], "source": [ "# [ ] count times letter \"i\" appears in code_tip string\n", "# [ ] find and display the index of all the letter i's in code_tip\n", "# Remember: if .find(\"i\") has No Match, -1 is returned\n", "code_tip = \"code a conditional decision like you would say it\"\n", "print (\"code_tip:\" , code_tip)\n", - "\n" + "\n", + "i_count = code_tip.count('i')\n", + "print(f\"\\nThe letter 'i' appears {i_count} times.\")\n", + "\n", + "print(\"\\nFiunding all occurances of the letter 'i': \")\n", + "\n", + "search_start = 0\n", + "\n", + "while True:\n", + " i_index = code_tip.find('i', search_start)\n", + "\n", + " if i_index == -1:\n", + " break\n", + " else:\n", + " print(\"Found 'i' at index: \", i_index)\n", + "\n", + " search_start = i_index +1" ] }, { @@ -370,12 +593,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WHERESOEVER\n", + "YOU\n", + "WITH\n", + "YOUR\n", + "HEART\n" + ] + } + ], "source": [ "# [] create words after \"G\"\n", "# sample quote \"Wheresoever you go, go with all your heart\" ~ Confucius (551 BC - 479 BC)\n", + "\n", + "quote = input(\"enter a 1 sentence quote, non-alpha septerate words: \")\n", + "\n", + "word = \"\"\n", + "\n", + "for character in quote:\n", + " if character.isalpha():\n", + " word += character\n", + " else:\n", + " if word:\n", + " if word[0].lower() > \"g\":\n", + " print(word.upper())\n", + " \n", + " word = \"\"\n", + "\n", + "if word:\n", + " if word[0].lower() > \"g\":\n", + " print(word.upper())\n", "\n" ] }, @@ -406,7 +659,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_1.2_Required_Code_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_1.2_Required_Code_Python_Fundamentals.ipynb index 5f3b08e5..38d1ff02 100644 --- a/P2 Python Fundamentals/Module_1.2_Required_Code_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_1.2_Required_Code_Python_Fundamentals.ipynb @@ -54,15 +54,54 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WHETHER\n", + "YOU\n", + "THINK\n", + "YOU\n", + "OR\n", + "YOU\n", + "THINK\n", + "YOU\n", + "T\n", + "YOU\n", + "RE\n", + "RIGHT\n" + ] + } + ], "source": [ - "# [] create words after \"G\" following the Assignment requirements use of functions, menhods and kwyowrds\n", + "# [] create words after \"G\" following the Assignment requirements use of functions, methods and keywords\n", "# Sample quote: \"Wheresoever you go, go with all your heart\" ~ Confucius (551 BC - 479 BC)\n", "\n", + "def word_after_g():\n", + "\n", + " quote = input(\"Welcome, Ben Reed. Enter a 1 sentence quote, non_alpha seperate words: \")\n", + " word = \"\"\n", + "\n", + " for character in quote:\n", + " if character.isalpha():\n", + " word += character\n", + " else:\n", + " if word:\n", + " if word[0].lower() > \"g\":\n", + " print(word.upper())\n", + " word = \"\"\n", + "\n", + " if word:\n", + " if word[0].lower() >\"g\":\n", + " print(word.upper())\n", + "\n", + "word_after_g()\n", + "\n", "\n", "\n" ] @@ -92,7 +131,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_2.0_Tutorials_Sequence_Lists_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_2.0_Tutorials_Sequence_Lists_Python_Fundamentals.ipynb index 676a32ab..c9d6ded4 100644 --- a/P2 Python Fundamentals/Module_2.0_Tutorials_Sequence_Lists_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_2.0_Tutorials_Sequence_Lists_Python_Fundamentals.ipynb @@ -52,9 +52,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ft_bones: \n", + "['calcaneus', 'talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# define list of strings\n", @@ -69,9 +78,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "age_survey: \n", + "[12, 14, 12, 29, 12, 14, 12, 12, 13, 12, 14, 13, 13, 46, 13, 12, 12, 13, 13, 12, 12]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# define list of integers\n", @@ -86,9 +104,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mixed_list: \n", + "[1, 34, 0.999, 'dog', 'cat', ['calcaneus', 'talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform'], [12, 14, 12, 29, 12, 14, 12, 12, 13, 12, 14, 13, 13, 46, 13, 12, 12, 13, 13, 12, 12]]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# define list of mixed data type\n", @@ -115,26 +142,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['footballs', 'baseballs', 'soccers']\n" + ] + } + ], "source": [ "# [ ] create team_names list and populate with 3-5 team name strings\n", - "\n", + "team_names = [\"footballs\", \"baseballs\", 'soccers']\n", "# [ ] print the list\n", - "\n" + "\n", + "print(team_names)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['footballs', 'baseballs', 'soccers', 5, 10, 20]\n" + ] + } + ], "source": [ "# [ ] Create a list mix_list with numbers and strings with 4-6 items\n", - "\n", + "mixed_list = [\"footballs\", \"baseballs\", 'soccers', 5, 10, 20]\n", "# [ ] print the list\n", - "\n" + "\n", + "print(mixed_list)" ] }, { @@ -170,9 +215,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "calcaneus is the 1st bone on the list\n", + "cuboid is the 3rd bone on the list\n", + "medial cuneiform is the last bone on the list\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "print(ft_bones[0], \"is the 1st bone on the list\")\n", @@ -182,9 +237,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "talus is connected to the navicular\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "print(ft_bones[1], \"is connected to the\",ft_bones[3])" @@ -192,9 +255,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The first three ages total 38\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "three_ages_sum = age_survey[0] + age_survey[1] + age_survey[2]\n", @@ -213,26 +284,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "there is no parking on hemlock or Main\n" + ] + } + ], "source": [ "# [ ] Create a list, streets, that lists the name of 5 street name strings\n", - "\n", + "streets = ['hemlock', 'habersham', 'Brick Mill', 'Forest Creek', 'Main']\n", "# [ ] print a message that there is \"No Parking\" on index 0 or index 4 streets\n", - "\n" + "print(\"there is no parking on\", streets[0], 'or', streets[4])\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25\n" + ] + } + ], "source": [ "# [ ] Create a list, num_2_add, made of 5 different numbers between 0 - 25\n", - "\n", + "num_2_add = [1,3,5,7,9]\n", "# [ ] print the sum of the numbers\n", - "\n" + "print(sum(num_2_add))\n" ] }, { @@ -248,9 +335,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Total of checks 3 & 4 = $ 16\n" + ] + } + ], "source": [ "# [ ] Review & Run, but ***Do Not Edit*** this code cell\n", "# [ ] Fix the error by only editing and running the block below\n", @@ -260,12 +355,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "# [ ] Fix the error above by creating and running code in this cell\n", - "\n" + "pay_checks = [3,5,7,9]\n" ] }, { @@ -313,9 +408,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sample_list before: [1, 1, 2]\n", + "sample_list after: [1, 1, 2, 3]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# the list before append\n", @@ -329,9 +433,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sample_list start: [1, 1, 2, 3, 3, 8, 5]\n", + "sample_list added: [1, 1, 2, 3, 3, 8, 5, 3]\n", + "sample_list added: [1, 1, 2, 3, 3, 8, 5, 3, 8]\n", + "sample_list added: [1, 1, 2, 3, 3, 8, 5, 3, 8, 5]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# append number to sample_list\n", @@ -353,9 +468,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mixed_types list: [1, 'cat', 3]\n", + "mixed_types list: [1, 'cat', 3, 'turtle']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "mixed_types = [1, \"cat\"]\n", @@ -382,35 +506,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1.0, 1.25, 0.25, 0.01, 0.05]\n", + "[1.0, 1.25, 0.25, 0.01, 0.05, 0.55]\n" + ] + } + ], "source": [ "# Currency Values\n", "# [ ] create a list of 3 or more currency denomination values, cur_values\n", "# cur_values, contains values of coins and paper bills (.01, .05, etc.)\n", - "\n", + "cur_values = [1.00, 1.25, .25, .01, .05]\n", "# [ ] print the list\n", - "\n", + "print(cur_values)\n", "\n", "# [ ] append an item to the list and print the list\n", - " \n" + "cur_values.append(.55)\n", + "print(cur_values)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['dollar', 'penny', 'quarter', 'nickel']\n", + "['dollar', 'penny', 'quarter', 'nickel', 'Big Bill']\n" + ] + } + ], "source": [ "# Currency Names\n", "# [ ] create a list of 3 or more currency denomination NAMES, cur_names\n", "# cur_names contains the NAMES of coins and paper bills (penny, etc.)\n", - "\n", + "cur_names = ['dollar', 'penny', 'quarter', 'nickel']\n", "# [ ] print the list\n", - "\n", + "print(cur_names)\n", "# [ ] append an item to the list and print the list\n", - " \n" + "cur_names.append('Big Bill')\n", + "print(cur_names)" ] }, { @@ -426,14 +570,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['dollar', 'penny', 'quarter', 'nickel', 'Big Bill', 'bigger bill', 'bigger bill', 'small bill']\n" + ] + } + ], "source": [ "# [ ] append additional values to the Currency Names list using input()\n", - "\n", + "cur_names.append(input('give me a currency name'))\n", "# [ ] print the appended list\n", - "\n" + "\n", + "print(cur_names)" ] }, { @@ -453,11 +606,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['1', '3', '4', '5', '78', 'q']\n" + ] + } + ], "source": [ - "# [ ] complete the Birthday Survey task above\n" + "# [ ] complete the Birthday Survey task above\n", + "bday_survey = []\n", + "bday = \"\"\n", + "while bday.startswith(\"q\") == False:\n", + " bday = input(\"Tell me the day of the month you were born (1-31) or \\\"q\\\" to finish\")\n", + " bday_survey.append(bday)\n", + "\n", + "print(bday_survey)\n" ] }, { @@ -471,12 +639,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "an item in the list is: 3\n" + ] + } + ], "source": [ "# [ ] Fix the Error\n", - "three_numbers = [1, 1, 2]\n", + "three_numbers = [1, 1, 2,3]\n", "print(\"an item in the list is: \", three_numbers[3])\n", "\n" ] @@ -528,9 +704,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "party_list before: ['Joana', 'Alton', 'Tobias']\n", + "party_list after: ['Joana', 'Colette', 'Tobias']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# the list before Insert\n", @@ -544,9 +729,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "before: ['Joana', 'Alton', 'Tobias']\n", + "\n", + "after: ['Joana', 'Alton Derosa', 'Tobias']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "party_list = [\"Joana\", \"Alton\", \"Tobias\"]\n", @@ -567,9 +762,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "IndexError", + "evalue": "list assignment index out of range", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mIndexError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[52]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# IndexError Example\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;66;03m# [ ] review and run example which results in an IndexError\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;66;03m# if result is NameError run cell above before running this cell\u001b[39;00m\n\u001b[32m 4\u001b[39m \n\u001b[32m 5\u001b[39m \u001b[38;5;66;03m# IndexError trying to append to end of list\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[43mparty_list\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m3\u001b[39;49m\u001b[43m]\u001b[49m = \u001b[33m\"\u001b[39m\u001b[33mAlton\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 7\u001b[39m \u001b[38;5;28mprint\u001b[39m(party_list)\n", + "\u001b[31mIndexError\u001b[39m: list assignment index out of range" + ] + } + ], "source": [ "# IndexError Example\n", "# [ ] review and run example which results in an IndexError\n", @@ -582,9 +789,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "single_digits: ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']\n", + "single_digits[3]: three \n", + "\n", + "single_digits: ['zero', 'one', 'two', 3, 'four', 'five', 'six', 'seven', 'eight', 'nine']\n", + "single_digits[3]: 3 \n" + ] + } + ], "source": [ "# [ ] review and run example changes the data type of an element\n", "# replace a string with a number (int)\n", @@ -618,13 +837,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 2, 3]\n", + "['large', 2, 3]\n" + ] + } + ], "source": [ "# [ ] complete \"replace items in a list\" task\n", + "three_num = [10,2,3]\n", "\n", - " \n" + "print(three_num)\n", + "if three_num[0] < 5:\n", + " three_num[0] = 'small' \n", + "\n", + "else:\n", + " three_num[0] = \"large\"\n", + "\n", + "print(three_num)\n" ] }, { @@ -643,11 +879,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original List: [10, 2, 8, 4]\n", + "After Index 0: ['large', 2, 8, 4]\n" + ] + } + ], "source": [ - "# [ ] create challenge function\n" + "# [ ] create challenge function\n", + "def str_replace(int_list, index):\n", + "\n", + " value_to_check = int_list[index]\n", + "\n", + " if value_to_check < 5:\n", + " int_list[index] = 'small'\n", + " else:\n", + " int_list[index] = 'large'\n", + "\n", + " return int_list\n", + "\n", + "my_list = [10, 2, 8, 4]\n", + "\n", + "print(\"Original List:\", my_list)\n", + "modified_list_1 = str_replace(my_list, 0)\n", + "print(\"After Index 0:\", modified_list_1)\n" ] }, { @@ -669,11 +930,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Alpha', 'Beta', 'Gamma']\n", + "['ALPHA', 'Beta', 'Gamma']\n", + "['ALPHA', 'Beta', 'gAMMA']\n" + ] + } + ], "source": [ "# [ ] complete coding task described above\n", + "three_words = ['Alpha', 'Beta', 'Gamma']\n", + "\n", + "print(three_words)\n", + "\n", + "three_words[0] = three_words[0].upper()\n", + "\n", + "print(three_words)\n", + "\n", + "three_words[2] = three_words[2].swapcase()\n", + "\n", + "print(three_words)\n", + "\n", "\n", " \n" ] @@ -704,9 +987,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "party_list before: ['Joana', 'Alton', 'Tobias']\n", + "index 1 is Alton \n", + "index 2 is Tobias \n", + "\n", + "party_list after: ['Joana', 'Colette', 'Alton', 'Tobias']\n", + "index 1 is Colette \n", + "index 2 is Alton \n", + "index 3 is Tobias\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# the list before Insert\n", @@ -733,15 +1031,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Joana', 'Alton', 'Tobias']\n", + "['Joana', 'Alton', 'Benjamin', 'Tobias']\n" + ] + } + ], "source": [ "# [ ] insert a name from user input into the party_list in the second position (index 1)\n", "party_list = [\"Joana\", \"Alton\", \"Tobias\"]\n", "\n", + "print(party_list)\n", + "\n", + "party_list.insert(2, \"Benjamin\")\n", "# [ ] print the updated list\n", - "\n" + "\n", + "print(party_list)" ] }, { @@ -755,12 +1066,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tree_list before = ['oak']\n", + "tree_list after = ['oak', 'pine']\n" + ] + } + ], "source": [ "# [ ] Fix the Error\n", - "tree_list = \"oak\"\n", + "tree_list = [\"oak\"]\n", "print(\"tree_list before =\", tree_list)\n", "tree_list.insert(1,\"pine\")\n", "print(\"tree_list after =\", tree_list)\n", @@ -812,9 +1132,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sample_list before: [11, 21, 13, 14, 51, 161, 117, 181]\n", + "sample_list after: [11, 13, 14, 51, 161, 117, 181]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# the list before delete\n", @@ -828,9 +1157,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sample_list before: [11, 13, 14, 51, 161, 117, 181]\n", + "sample_list after: [13, 14, 51, 161, 117, 181]\n" + ] + } + ], "source": [ "# [ ] review and run example Multiple Times\n", "# [ ] consider how to reset the list values?\n", @@ -841,9 +1179,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mixed_types list: [1, 'cat', 3]\n", + "mixed_types list: [1, 'cat', 3, 'turtle']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "mixed_types = [1, \"cat\"]\n", @@ -870,9 +1217,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['calcaneus', 'talus', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']\n" + ] + } + ], "source": [ "# [ ] print ft_bones list\n", "# [ ] delete \"cuboid\" from ft_bones\n", @@ -880,7 +1235,9 @@ "ft_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \n", " \"intermediate cuneiform\", \"medial cuneiform\"]\n", "\n", - "\n" + "del ft_bones[2]\n", + "\n", + "print(ft_bones)\n" ] }, { @@ -894,9 +1251,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['calcaneus', 'talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']\n", + "['calcaneus', 'talus', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform']\n" + ] + } + ], "source": [ "# [ ] print ft_bones list\n", "# [ ] delete \"cuboid\" from ft_bones\n", @@ -906,6 +1272,12 @@ "ft_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \n", " \"intermediate cuneiform\", \"medial cuneiform\"]\n", "\n", + "print(ft_bones)\n", + "\n", + "del ft_bones[2:4]\n", + "\n", + "print(ft_bones)\n", + "\n", "\n" ] }, @@ -933,9 +1305,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Joana', 'Alton', 'Tobias']\n", + "Hello, Tobias\n", + "\n", + " ['Joana', 'Alton']\n", + "Hello, Alton\n", + "\n", + " ['Joana']\n", + "Hello, Joana\n", + "\n", + " []\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# pop() gets the last item by default\n", @@ -954,9 +1343,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "before: [11, 21, 13, 14, 51, 161, 117, 181]\n", + "after : [11, 21, 13, 51, 161, 117, 181]\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# can pop specific index like pop(3)\n", @@ -968,9 +1366,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list before: [11, 21, 13, 14, 51, 161, 117, 181]\n", + "list after : [11, 21, 13, 14, 51, 161]\n", + "add the popped values: 181 + 117 = 298\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# set a variable to a poped value\n", @@ -995,16 +1403,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['talus', 'cuboid', 'navicular', 'lateral cuneiform', 'intermediate cuneiform']\n" + ] + } + ], "source": [ "# [ ] pop() and print the first and last items from the ft_bones list\n", "ft_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \n", " \"intermediate cuneiform\", \"medial cuneiform\"]\n", "\n", + "ft_bones.pop(0)\n", + "ft_bones.pop(-1)\n", "# [ ] print the remaining list\n", - "\n" + "\n", + "print(ft_bones)" ] }, { @@ -1031,9 +1450,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Poodle\n", + "Pug\n", + "Lab\n" + ] + } + ], "source": [ "dog_types = [\"Lab\", \"Pug\", \"Poodle\"]\n", "\n", @@ -1058,12 +1487,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['11.99', '12.99', '13.99', 'done']\n" + ] + } + ], "source": [ "#[ ] complete the Register Input task above\n", - "\n" + "purchase_amount = []\n", + "\n", + "while True:\n", + " item_input = input(\"Enter item price or type 'done' to finish:\" )\n", + " purchase_amount.append(item_input)\n", + " if item_input.lower() == 'done':\n", + " break\n", + "\n", + "print(purchase_amount)\n" ] }, { @@ -1085,12 +1530,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Purchase list (as strings): ['12']\n", + "\n", + "Purchase list (as strings): ['12', '13']\n", + "\n", + "Purchase list (as strings): ['12', '13', '14']\n", + "\n", + "Purchase list (as strings): ['12', '13', '14', '15']\n", + "-----------------------------------\n", + "Final Subtotal: 54.00\n" + ] + } + ], "source": [ "# [ ] complete the Register Total task above\n", - "\n" + "subtotal = 0\n", + "\n", + "purchase_amount = []\n", + "\n", + "while True:\n", + " item_input = input(\"Enter item price or type 'done' to finish: \")\n", + "\n", + " if item_input.lower() == 'done':\n", + " break\n", + "\n", + " purchase_amount.append(item_input)\n", + "\n", + " print(\"\\nPurchase list (as strings):\", purchase_amount)\n", + "\n", + "while purchase_amount:\n", + "\n", + " item_price = float(purchase_amount.pop())\n", + "\n", + " subtotal += item_price\n", + "\n", + "print(\"-----------------------------------\")\n", + "print(f\"Final Subtotal: {subtotal:.2f}\")\n" ] }, { @@ -1118,9 +1601,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Lab', 'Poodle']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "dog_types = [\"Lab\", \"Pug\", \"Poodle\"]\n", @@ -1134,14 +1625,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Lab', 'Collie', 'Pug', 'Poodle', 'Poodle', 'Pug', 'Poodle']\n", + "['Lab', 'Collie', 'Pug', 'Poodle', 'Pug', 'Poodle']\n", + "['Lab', 'Collie', 'Pug', 'Pug', 'Poodle']\n", + "['Lab', 'Collie', 'Pug', 'Pug']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", - "dogs = [\"Lab\", \"Pug\", \"Poodle\", \"Poodle\", \"Pug\", \"Poodle\"]\n", + "dogs = [\"Lab\", \"Collie\", \"Pug\", \"Poodle\", \"Poodle\", \"Pug\", \"Poodle\"]\n", "\n", "print(dogs)\n", "while \"Poodle\" in dogs:\n", @@ -1158,9 +1660,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Lab', 'Pug', 'Pug']\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# Change to \"Lab\", etc... to fix error\n", @@ -1181,14 +1691,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 108, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Lab', 'Pug', 'Poodle', 'Poodle', 'Pug', 'Poodle']\n", + "['Lab', 'Pug', 'Poodle', 'Pug', 'Poodle']\n" + ] + } + ], "source": [ "# [ ] remove one \"Poodle\" from the list: dogs , or print \"no Poodle found\"\n", "# [ ] print list before and after\n", "dogs = [\"Lab\", \"Pug\", \"Poodle\", \"Poodle\", \"Pug\", \"Poodle\"]\n", - "\n" + "print(dogs)\n", + "\n", + "if \"Poodle\" in dogs:\n", + " dogs.remove(\"Poodle\")\n", + "else:\n", + " print(\"no Poodle found\")\n", + "\n", + "print(dogs)" ] }, { @@ -1205,7 +1731,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 109, "metadata": {}, "outputs": [ { @@ -1247,7 +1773,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_2.1_Practice_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_2.1_Practice_Python_Fundamentals.ipynb index 2e35c8db..5bc52e5a 100644 --- a/P2 Python Fundamentals/Module_2.1_Practice_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_2.1_Practice_Python_Fundamentals.ipynb @@ -23,43 +23,47 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n" + ] + } + ], "source": [ "# [ ] create and populate list called days_of_week then print it\n", "\n", - "days_of_week = [\"Monday\",\"Tuesday\",\"Wednesday\"]\n", + "days_of_week = [\"Monday\",\"Tuesday\",\"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n", "\n", - "\n" + "print(days_of_week)\n" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 ['Monday', 'Tuesday', 'Wednesday', 'Thursday']\n", - "2 ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']\n" + "['Tuesday', 'Thursday', 'Saturday']\n", + "['Monday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday', 'Sunday']\n" ] } ], "source": [ "# [ ] after days_of_week is run above, print the days in the list at odd indexes 1,3,5\n", - "days_of_week.remove(\"Friday\")\n", - "print(\"1\",days_of_week)\n", + "print(days_of_week[1:6:2])\n", "\n", "#del days_of_week[3]\n", - "if \"Friday\" in days_of_week:\n", - " pass\n", - "else:\n", - " days_of_week.append(\"Friday\")\n", + "del days_of_week[3]\n", "\n", - "print(\"2\",days_of_week)\n" + "print(days_of_week)\n" ] }, { @@ -79,12 +83,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['', '', 'ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ']\n" + ] + } + ], "source": [ "# [ ] create and populate list called phone_letters then print it\n", - "phone_letters = [\"\",\"\",\"ABC\",\"DEF\",\"GHI\"]\n", + "phone_letters = [\"\",\"\",\"ABC\",\"DEF\",\"GHI\", \"JKL\", \"MNO\", \"PQRS\", \"TUV\", \"WXYZ\"]\n", " \n", "print(phone_letters)" ] @@ -103,27 +115,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tuesday\n" + ] + } + ], "source": [ "# [ ] create a variable: day, assign day to \"Tuesday\" using days_of_week[]\n", "# [ ] print day variable\n", "\n", + "day = days_of_week[1]\n", "\n", + "print(day)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sunday\n" + ] + } + ], "source": [ "# PART 2\n", "# [ ] assign day to days_of_week index = 5\n", + "day = days_of_week[5]\n", "# [ ] print day\n", - "\n", + "print(day)\n", "\n" ] }, @@ -141,14 +172,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday', 'Sunday', 'Bensday', 'Bensday']\n" + ] + } + ], "source": [ "# [ ] Make up a new day! - append an 8th day of the week to days_of_week \n", "# [ ] print days_of_week\n", "\n", - "\n" + "days_of_week.append('Bensday')\n", + "\n", + "print(days_of_week)\n" ] }, { @@ -162,26 +203,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Whynotsday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n" + ] + } + ], "source": [ "# [ ] Make up another new day - insert a new day into the middle of days_of_week between Wed - Thurs\n", "# [ ] print days_of_week\n", + "days_of_week = [\"Monday\",\"Tuesday\",\"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n", + "days_of_week.insert(3,\"Whynotsday\")\n", "\n", - "\n" + "print(days_of_week)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Whynotsday', 'Thursday', 'Friday', 'Longday', 'Saturday', 'Sunday']\n" + ] + } + ], "source": [ "# [ ] Extend the weekend - insert a day between Fri & Sat in the days_of_week list\n", "# [ ] print days_of_week\n", "\n", - "\n" + "days_of_week.insert(-2, 'Longday')\n", + "print(days_of_week)\n" ] }, { @@ -195,40 +255,77 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Whynotsday', 'Thursday', 'Friday', 'Longday', 'Saturday', 'Sunday']\n", + "['Monday', 'Tuesday', 'Wednesday', 'Whynotsday', 'Thursday', 'Friday', 'Longday', 'Saturday']\n" + ] + } + ], "source": [ "# [ ] print days_of_week \n", + "print(days_of_week)\n", "# [ ] modified week is too long - pop() the last index of days_of_week & print .pop() value\n", + "days_of_week.pop(-1)\n", "# [ ] print days_of_week\n", + "print(days_of_week)\n", "\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Whynotsday', 'Thursday', 'Friday', 'Longday', 'Saturday']\n", + "['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Longday', 'Saturday']\n" + ] + } + ], "source": [ "# [ ] print days_of_week \n", - "# [ ] delete (del) the new day added to the middle of the week \n", + "print(days_of_week)\n", + "# [ ] delete (del) the new day added to the middle of the week\n", + "del days_of_week[3] \n", "# [ ] print days_of_week\n", + "print(days_of_week)\n", "\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Longday', 'Saturday']\n", + "The day I popped was: Longday\n", + "['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n" + ] + } + ], "source": [ "# [ ] print days_of_week \n", + "print(days_of_week)\n", "# [ ] programmers choice - pop() any day in days_of week & print .pop() value\n", + "popped_day = days_of_week.pop(-2)\n", + "print(f\"The day I popped was: {popped_day}\")\n", "# [ ] print days_of_week\n", - "\n" + "print(days_of_week)\n" ] }, { @@ -280,21 +377,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Input: ' ' \t\tOutput: Not Found\n", + "Input: 'j' \t\tOutput: 5\n", + "Input: 'Y' \t\tOutput: 9\n", + "Input: '7' \t\tOutput: Not Found\n" + ] + } + ], "source": [ "# [ ] create let_to_num()\n", - "\n" + "def let_to_num(letter):\n", + " if letter == \"\":\n", + " return 1 ##returns 1 it it finds an empty string.\n", + " \n", + " search_letter = letter.upper()\n", + "\n", + " key = 0\n", + "\n", + " while key < 10:\n", + " if search_letter in phone_letters[key]:\n", + " return key\n", + " \n", + " else:\n", + " key = key + 1\n", + "\n", + " return \"Not Found\"\n", + "\n", + "print(\"Input: ' ' \\t\\tOutput:\", let_to_num(\" \"))\n", + "print(\"Input: 'j' \\t\\tOutput:\", let_to_num(\"j\"))\n", + "print(\"Input: 'Y' \\t\\tOutput:\", let_to_num(\"Y\"))\n", + "print(\"Input: '7' \\t\\tOutput:\", let_to_num(\"7\"))" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -310,23 +431,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original List: ['Dog', 'Cat', 'Bird', 'Lion']\n", + "--------------------------------------------------\n", + "Final Reversed List: ['Lion', 'Bird', 'Cat', 'Dog']\n" + ] + } + ], "source": [ "# [ ] Challenge: write the code for \"reverse a string\"\n", + "my_list = ['Dog', 'Cat', 'Bird', 'Lion']\n", + "reversed_list = []\n", + "\n", + "print(f\"Original List: {my_list}\")\n", + "print(\"-\" * 50)\n", + "\n", + "while my_list:\n", + " last_word = my_list.pop()\n", + " reversed_list.append(last_word)\n", + "\n", + "print(f\"Final Reversed List: {reversed_list}\")\n", "\n", " \n", " " ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -352,7 +487,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_2.2_Required_Code_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_2.2_Required_Code_Python_Fundamentals.ipynb index 7d295e8a..7660f559 100644 --- a/P2 Python Fundamentals/Module_2.2_Required_Code_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_2.2_Required_Code_Python_Fundamentals.ipynb @@ -65,18 +65,96 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'magenta']\n", + "1 instance of blue removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['red', 'orange', 'yellow', 'green', 'indigo', 'violet', 'magenta']\n", + "1 instance of orange removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['red', 'yellow', 'green', 'indigo', 'violet', 'magenta']\n", + "1 instance of green removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['red', 'yellow', 'indigo', 'violet', 'magenta']\n", + "1 instance of red removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['yellow', 'indigo', 'violet', 'magenta']\n", + "1 instance of yellow removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['indigo', 'violet', 'magenta']\n", + "1 instance of red appended to list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['indigo', 'violet', 'magenta', 'red']\n", + "1 instance of indigo removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['violet', 'magenta', 'red']\n", + "1 instance of violet removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['magenta', 'red']\n", + "1 instance of magenta removed from list.\n", + "\n", + "Welcome, Benjamin Reed. Look at all the colors ['red']\n", + "1 instance of red removed from list.\n", + "Goodbye\n" + ] + } + ], "source": [ "# [] create list-o-matic as a function and call it\n", "# [] be sure to include your spelled-out name in the welcome prompt\n", "# [] you are welcome to use any list you like for list-o-matic, does not have to be animals \n", "\n", "\n", - "\n" + "def list_o_matic(item_list, item_string):\n", + "\n", + " if item_string == \"\":\n", + "\n", + " if item_list:\n", + " popped_item = item_list.pop()\n", + " return f\"{popped_item} popped from list\"\n", + " else:\n", + " return \"List is already empty.\"\n", + " \n", + " elif item_string in item_list:\n", + "\n", + " item_list.remove(item_string)\n", + " return f\"1 instance of {item_string} removed from list.\"\n", + " \n", + " else:\n", + "\n", + " item_list.append(item_string)\n", + " return f\"1 instance of {item_string} appended to list.\"\n", + "\n", + "colors_list = ['red','orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'magenta']\n", + "program_name = \"colors\"\n", + "my_name = \"Benjamin Reed\"\n", + "\n", + "while True:\n", + "\n", + " if not colors_list:\n", + " print(\"Goodbye\")\n", + " break\n", + "\n", + " print(f\"\\nWelcome, {my_name}. Look at all the {program_name} {colors_list}\")\n", + "\n", + " color_input = input(f\"Enter a color: \")\n", + "\n", + " if color_input == \"quit\":\n", + " print(\"Goodbye!\")\n", + " break\n", + "\n", + " message = list_o_matic(colors_list, color_input)\n", + "\n", + " print(message)" ] }, { @@ -104,7 +182,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_3.0_List_Iteration_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_3.0_List_Iteration_Python_Fundamentals.ipynb index 011cab1c..79b09517 100644 --- a/P2 Python Fundamentals/Module_3.0_List_Iteration_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_3.0_List_Iteration_Python_Fundamentals.ipynb @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -60,10 +60,10 @@ "text": [ "New York\n", "Shanghai\n", - "MUNICH\n", + "Munich\n", "Tokyo\n", "Dubai\n", - "MEXICO CITY\n", + "Mexico City\n", "São Paulo\n", "Hyderabad\n" ] @@ -79,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -147,35 +147,81 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hawk\n", + "turkey\n", + "pigeon\n", + "penguin\n", + "vulture\n" + ] + } + ], "source": [ "# [ ] create a list of 4 to 6 strings: birds\n", "# print each bird in the list\n", - "\n" + "birds = ['hawk', 'turkey', 'pigeon', 'penguin', 'vulture']\n", + "\n", + "for bird in birds:\n", + " print(bird)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "6\n", + "8\n", + "10\n", + "12\n", + "14\n" + ] + } + ], "source": [ "# [ ] create a list of 7 integers: player_points\n", "# [ ] print double the points for each point value\n", - "\n" + "player_points = ['1', '2', '3', '4', '5', '6', '7']\n", + "\n", + "for numb_2 in player_points:\n", + " print(int(numb_2) * 2)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list all the birds: hawk, turkey, pigeon, penguin, vulture, \n" + ] + } + ], "source": [ "# [ ] create long_string by concatenating the items in the \"birds\" list previously created\n", "# print long_string - make sure to put a space betweeen the bird names\n", - "\n" + "birds = ['hawk', 'turkey', 'pigeon', 'penguin', 'vulture']\n", + "long_string = \"\"\n", + "\n", + "for bird in birds:\n", + " long_string += bird + \", \"\n", + "\n", + "print('list all the birds: ', long_string)" ] }, { @@ -198,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -218,7 +264,7 @@ } ], "source": [ - "# [ ] review and run example of sorting into strings to display\n", + "## [ ] review and run example of sorting into strings to display\n", "foot_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \n", " \"intermediate cuneiform\", \"medial cuneiform\"]\n", "longer_names = \"\"\n", @@ -236,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -279,24 +325,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Munich\n", + "Mexico City\n" + ] + } + ], "source": [ "# [ ] Using cities from the example above iterate throught the list using \"for\"/\"in\"\n", "# [ ] Print only cities starting with \"m\"\n", - "\n" + "cities = [\"New York\", \"Shanghai\", \"Munich\", \"Tokyo\", \"Dubai\", \"Mexico City\", \"São Paulo\", \"Hyderabad\"]\n", + "\n", + "for city in cities:\n", + " if city.lower().startswith('m'):\n", + " print(city)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cities with 'a': ['Shanghai', 'Dubai', 'São Paulo', 'Hyderabad']\n", + "Cities with 'a': ['New York', 'Munich', 'Tokyo', 'Mexico City']\n" + ] + } + ], "source": [ "# [ ] Using cities from the example above iterate throught the list using \"for\"/\"in\"\n", "# cities = [\"New York\", \"Shanghai\", \"Munich\", \"Tokyo\", \"Dubai\", \"Mexico City\", \"São Paulo\", \"Hyderabad\"]\n", "# [ ] sort into lists with \"A\" in the city name and without \"A\" in the name: a_city & no_a_city\n", + "cities = [\"New York\", \"Shanghai\", \"Munich\", \"Tokyo\", \"Dubai\", \"Mexico City\", \"São Paulo\", \"Hyderabad\"]\n", + "\n", + "a_city = []\n", + "no_a_city = []\n", + "\n", + "for city in cities:\n", + " if 'a' in city.lower():\n", + " a_city.append(city)\n", + "\n", + " else:\n", + " no_a_city.append(city)\n", + "print(\"Cities with 'a':\", a_city)\n", + "print(\"Cities with 'a':\", no_a_city)\n", "\n" ] }, @@ -325,14 +406,14 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "The total # of \"e\" found in the list is 3\n" + "The total # of \"a\" found in the list is 6\n" ] } ], @@ -359,16 +440,15 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "enter a city visited: new york\n", - "new york in default cities is True\n", - "new york in visitied_cites list is True\n" + "tokyo in default cities is True\n", + "tokyo in visited_cites list is True\n" ] } ], @@ -412,11 +492,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Red found\n" + ] + } + ], "source": [ "# [ ] complete paint stock\n", + "paint_colors = ['blue', 'red', 'green', 'purple', 'orange', 'black', 'white']\n", + "\n", + "color_request = input('What color would you like to search for?')\n", + "\n", + "found = False\n", + "\n", + "for color in paint_colors:\n", + " if color.lower() == color_request.lower():\n", + " found = True\n", + " break\n", + "\n", + "if found: \n", + " print(color_request.capitalize(), 'found')\n", + "\n", + "else:\n", + " print(color_request.capitalize(), 'not found')\n", + "\n", "\n" ] }, @@ -445,14 +550,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "welcome to the bone list quiz\n", + "Correct! 'talus' identified.\n", + "Incorrect. 'naicular' is not in the remaining list.\n", + "\n", + "Total # of foot_bones identified: 1\n" + ] + } + ], "source": [ "# [ ] Complete Foot Bones Quiz\n", - "# foot_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\",\n", - "# \"intermediate cuneiform\", \"medial cuneiform\"]\n", - "\n" + "foot_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \"intermediate cuneiform\", \"medial cuneiform\"]\n", + "\n", + "identified_count = 0\n", + "\n", + "def quiz_foot_bone(bone_name, bone_list):\n", + " global identified_count\n", + "\n", + " for i in range(len(bone_list)):\n", + " if bone_list[i].lower() == bone_name.lower():\n", + " identified_count += 1\n", + "\n", + " correct_bone = bone_list[i]\n", + "\n", + " bone_list.pop(i)\n", + "\n", + " return f\"Correct! '{correct_bone}' identified.\"\n", + " \n", + " return f\"Incorrect. '{bone_name}' is not in the remaining list.\"\n", + "\n", + "print(\"welcome to the bone list quiz\")\n", + "\n", + "answer_1 = input(\"Attempt 1: Name a foot bone.\")\n", + "feedback_1 = quiz_foot_bone(answer_1, foot_bones)\n", + "print(feedback_1)\n", + "\n", + "if len(foot_bones) > 0:\n", + " answer_2 = input(\"\\nAttempt 2: Name another foot bone: \")\n", + " feedback_2 = quiz_foot_bone(answer_2, foot_bones)\n", + " print(feedback_2)\n", + "else:\n", + " print(\"\\nAttempt 2 skipped: All foot bones have been identified!\")\n", + "\n", + "print(f\"\\nTotal # of foot_bones identified: {identified_count}\")" ] }, { @@ -519,7 +666,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -547,7 +694,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -580,7 +727,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -612,7 +759,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -673,7 +820,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -693,7 +840,16 @@ ], "source": [ "# [ ] using range(x) multiply the numbers 1 through 7\n", - "# 1x2x3x4x5x6x7 = 5040\n" + "# 1x2x3x4x5x6x7 = 5040\n", + "result = 1\n", + "\n", + "for num in range(1,8):\n", + " ##result = num * result\n", + " print(num, \"x\", result, end =\" \")\n", + " result = num * result\n", + " print(\"=\", result)\n", + "\n", + "print(result)\n" ] }, { @@ -849,37 +1005,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n" + ] + } + ], "source": [ "# [ ] using range(start,stop), .append() the numbers 5 to 15 to the list: five_fifteen\n", "# [ ] print list five_fifteen\n", - "\n" + "five_fifteen = []\n", + "\n", + "for number in range(5,16):\n", + " five_fifteen.append(number)\n", + "\n", + "print(five_fifteen)\n", + " \n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "February\n", + "November\n", + "Annual\n" + ] + } + ], "source": [ "# [ ] using range(start,stop) - print the 3rd, 4th and 5th words in spell_list\n", "# output should include \"February\", \"November\", \"Annual\"\n", "spell_list = [\"Tuesday\", \"Wednesday\", \"February\", \"November\", \"Annual\", \"Calendar\", \"Solstice\"]\n", - "\n" + "\n", + "for month in range(2,5):\n", + "\n", + " print (spell_list[month])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The index of Annual is: 4\n", + "Annual\n", + "Calendar\n", + "Solstice\n" + ] + } + ], "source": [ "# [ ] using code find the index of \"Annual\" in spell_list\n", "# [ ] using range, print the spell_list including \"Annual\" to end of list\n", "spell_list = [\"Tuesday\", \"Wednesday\", \"February\", \"November\", \"Annual\", \"Calendar\", \"Solstice\"]\n", - "\n" + "\n", + "annual_index = spell_list.index(\"Annual\")\n", + "print(\"The index of Annual is:\", annual_index)\n", + "\n", + "for index in range(annual_index, len(spell_list)):\n", + " print(spell_list[index])" ] }, { @@ -911,7 +1110,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -933,7 +1132,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -962,7 +1161,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -986,7 +1185,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1016,35 +1215,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 12, 14, 16, 18, 20]\n" + ] + } + ], "source": [ "# [ ] print numbers 10 to 20 by 2's using range\n", + "even_list = list(range(10,22,2))\n", "\n", + "print(even_list)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]\n" + ] + } + ], "source": [ "# [ ] print numbers 20 to 10 using range (need to countdown)\n", "# Hint: start at 20\n", - "\n" + "\n", + "backwards = list(range(20,9,-1))\n", + "\n", + "print(backwards)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tuesday\n", + "November\n", + "Solstice\n" + ] + } + ], "source": [ "# [ ] print first and every third word in spell_list\n", "spell_list = [\"Tuesday\", \"Wednesday\", \"February\", \"November\", \"Annual\", \"Calendar\", \"Solstice\"]\n", - "\n" + "\n", + "for index in range(0, len(spell_list), 3):\n", + " print(spell_list[index])" ] }, { @@ -1068,11 +1300,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Word length; 8\n", + "odd_indexed letter: ['b', 'l', 'y', 'o']\n", + "Even_indexewd letter: ['i', 'l', 'b', 'b']\n" + ] + } + ], "source": [ "# [ ] complete List of letters program- test with the word \"complexity\"\n", + "\n", + "word = input(\"input a word\")\n", + "\n", + "word_length = len(word)\n", + "print(\"Word length;\", word_length)\n", + "\n", + "odd_letters = []\n", + "even_letters = []\n", + "\n", + "for index in range(0, word_length, 2):\n", + " odd_letters.append(word[index])\n", + "\n", + "for index in range(1, word_length, 2):\n", + " even_letters.append(word[index])\n", + "\n", + "print(\"odd_indexed letter:\", odd_letters)\n", + "print(\"Even_indexewd letter:\", even_letters)\n", "\n" ] }, @@ -1086,24 +1345,24 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 60, "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "'type' object is not subscriptable", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# [ ] fix the error printing odd numbers 1 - 9\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mnum\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: 'type' object is not subscriptable" + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "3\n", + "5\n", + "7\n", + "9\n" ] } ], "source": [ "# [ ] fix the error printing odd numbers 1 - 9\n", - "for num in range[1,10,2]:\n", + "for num in range(1,10,2):\n", " print(num)\n", "\n", "\n" @@ -1162,7 +1421,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 61, "metadata": {}, "outputs": [ { @@ -1186,7 +1445,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 62, "metadata": {}, "outputs": [ { @@ -1224,7 +1483,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -1250,14 +1509,14 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Team_a extended [0, 2, 2, 2, 4, 4, 4, 5, 6, 6, 6, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8]\n" + "Team_a extended [0, 2, 2, 2, 4, 4, 4, 5, 6, 6, 6, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8, 0, 0, 0, 1, 1, 2, 3, 3, 3, 6, 8]\n" ] } ], @@ -1284,24 +1543,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['chicken', 'blue jay', 'crow', 'pigeon', 'hawk', 'penguin', 'eagle']\n" + ] + } + ], "source": [ "# [ ] extend the list common_birds with list birds_seen which you must create\n", "common_birds = [\"chicken\", \"blue jay\", \"crow\", \"pigeon\"]\n", + "birds_seen = [\"hawk\", \"penguin\", 'eagle']\n", + "\n", + "common_birds.extend(birds_seen)\n", + "print(common_birds)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n" + ] + } + ], "source": [ "# [ ] Create 2 lists zero_nine and ten_onehundred that contain 1-9, and 10 - 100 by 10's.\n", "# [ ] use list addition to concatenate the lists into all_num and print\n", - "\n" + "\n", + "zero_nine = []\n", + "ten_onehundred = []\n", + "\n", + "for num in range(1,10):\n", + " zero_nine.append(num)\n", + "\n", + "for num in range(10,101,10):\n", + " ten_onehundred.append(num)\n", + "\n", + "all_num = zero_nine + ten_onehundred\n", + "print(all_num)\n" ] }, { @@ -1330,7 +1620,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 82, "metadata": {}, "outputs": [ { @@ -1353,7 +1643,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 79, "metadata": {}, "outputs": [ { @@ -1394,7 +1684,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 83, "metadata": {}, "outputs": [ { @@ -1431,24 +1721,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]\n", + "[100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]\n" + ] + } + ], "source": [ "# [ ] create and print a list of multiples of 5 from 5 to 100\n", "# { ] reverse the list and print\n", - "\n" + "\n", + "list_1 = list(range(5,101,5))\n", + "print(list_1)\n", + "\n", + "list_1.reverse()\n", + "\n", + "print(list_1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44]\n" + ] + } + ], "source": [ "# [ ] Create two lists: fours & more_fours containing multiples of four from 4 to 44\n", "# [ ] combine and print so that the output is mirrored [44, 40,...8, 4, 4, 8, ...40, 44]\n", - "\n" + "\n", + "fours = list(range(4,45,4))\n", + "four_more = list(range(4,45,4))\n", + "fours.reverse()\n", + "print(fours + four_more)" ] }, { @@ -1486,25 +1803,30 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 95, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "quiz_scores: [15, 18, 18, 18, 19, 19, 20, 20, 20, 20, 20]\n" + "[20, 19, 20, 15, 20, 20, 20, 18, 18, 18, 19]\n", + "quiz_scores: [15, 18, 18, 18, 19, 19, 20, 20, 20, 20, 20]\n", + "[15, 18, 18, 18, 19, 19, 20, 20, 20, 20, 20]\n" ] } ], "source": [ "# [ ] review and run example\n", "quiz_scores = [20, 19, 20, 15, 20, 20, 20, 18, 18, 18, 19]\n", - "\n", + "print(quiz_scores)\n", "# use .sort()\n", "quiz_scores.sort()\n", "\n", - "print(\"quiz_scores:\", quiz_scores)" + "print(\"quiz_scores:\", quiz_scores)\n", + "\n", + "sorted(quiz_scores)\n", + "print(quiz_scores)" ] }, { @@ -1534,7 +1856,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 96, "metadata": {}, "outputs": [ { @@ -1568,27 +1890,72 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sort List: ['Dubai', 'Hyderabad', 'Mexico City', 'Munich', 'New York', 'Shanghai', 'São Paulo', 'Toyko']\n", + "\n", + "Cities starting with Q or earlier:\n", + "Dubai\n", + "Hyderabad\n", + "Mexico City\n", + "Munich\n", + "New York\n" + ] + } + ], "source": [ "# [ ] print cites from visited_cities list in alphbetical order using .sort()\n", "# [ ] only print cities that names start \"Q\" or earlier\n", "visited_cities = [\"New York\", \"Shanghai\", \"Munich\", \"Toyko\", \"Dubai\", \"Mexico City\", \"São Paulo\", \"Hyderabad\"]\n", - "\n" + "\n", + "visited_cities.sort()\n", + "print(\"Sort List: \", visited_cities)\n", + "\n", + "print('\\nCities starting with Q or earlier:')\n", + "\n", + "for city in visited_cities:\n", + " first_letters = city[0]\n", + "\n", + " if first_letters.upper() <= 'Q':\n", + " print(city)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['New York', 'Shanghai', 'Munich', 'Toyko', 'Dubai', 'Mexico City', 'São Paulo', 'Hyderabad']\n", + "['Dubai', 'Hyderabad', 'Mexico City', 'Munich', 'New York', 'Shanghai', 'São Paulo', 'Toyko']\n", + "Original vistited_cities (unchanged): ['New York', 'Shanghai', 'Munich', 'Toyko', 'Dubai', 'Mexico City', 'São Paulo', 'Hyderabad']\n", + "Filtered sorted_cities (> 5 chars): ['Hyderabad', 'Mexico City', 'Munich', 'New York', 'Shanghai', 'São Paulo']\n" + ] + } + ], "source": [ "# [ ] make a sorted copy (sorted_cities) of visited_cities list\n", "# [ ] remove city names 5 characters or less from sorted_cities \n", "# [ ] print visitied cites and sorted cities\n", "visited_cities = [\"New York\", \"Shanghai\", \"Munich\", \"Toyko\", \"Dubai\", \"Mexico City\", \"São Paulo\", \"Hyderabad\"]\n", - "\n" + "print(visited_cities)\n", + "sorted_cities = sorted(visited_cities)\n", + "print(sorted_cities)\n", + "\n", + "filtered_cities = [city for city in sorted_cities if len(city) > 5]\n", + "\n", + "sorted_cities = filtered_cities\n", + "\n", + "print(\"Original vistited_cities (unchanged):\", visited_cities)\n", + "print(\"Filtered sorted_cities (> 5 chars):\", sorted_cities)" ] }, { @@ -1616,24 +1983,29 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 108, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Give me an animal to add or blank to stop: jay\n", - "Give me an animal to add or blank to stop: cat\n", - "Give me an animal to add or blank to stop: dog\n", - "Give me an animal to add or blank to stop: lio\n", - "Give me an animal to add or blank to stop: \n" + "['bird']\n" ] } ], "source": [ "# [ ] build a list (add_animals) using a while loop, stop adding when an empty string is entered\n", - "add_animals = []\n" + "add_animals = []\n", + "\n", + "while True:\n", + " next_animal = input(\"Give me an animal\")\n", + " if next_animal == \"\":\n", + " break\n", + " else:\n", + " add_animals.append(next_animal)\n", + "\n", + "print(add_animals)\n" ] }, { @@ -1646,20 +2018,27 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 109, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['jay', 'cat', 'dog', 'lio']\n" + "\n", + "Combined and Sorted Animals: ['Armadillo', 'Chimpanzee', 'Panther', 'Wolf', 'bird']\n" ] } ], "source": [ "# [ ] extend the lists into animals, then sort \n", - "animals = [\"Chimpanzee\", \"Panther\", \"Wolf\", \"Armadillo\"]" + "animals = [\"Chimpanzee\", \"Panther\", \"Wolf\", \"Armadillo\"]\n", + "\n", + "animals.extend(add_animals)\n", + "\n", + "animals.sort()\n", + "\n", + "print(\"\\nCombined and Sorted Animals:\", animals)" ] }, { @@ -1672,23 +2051,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 112, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Animals (Alphabetical Order): ['Armadillo', 'Chimpanzee', 'Panther', 'Wolf', 'bird']\n" + ] + } + ], "source": [ "# [ ] get input if list should be viewed alpha or reverse alpha and display list\n", - "\n" + "\n", + "animals = ['Armadillo', 'Chimpanzee', 'Panther', 'Wolf', 'bird']\n", + "\n", + "sort_preference = input(\"How would you like to view the animal list? Enter 'A' for alphabetical or 'R' for reverse-alphabetical: \")\n", + "\n", + "if sort_preference.lower() == 'a':\n", + " animals.sort()\n", + " print(\"\\nAnimals (Alphabetical Order):\", animals)\n", + "elif sort_preference.lower() == 'r':\n", + " animals.sort(reverse = True)\n", + " print('\\nAnimals (Reverse_Alphabetical Order):', animals)\n", + "else:\n", + "\n", + " print(\"\\nInvalid input. Displaying list in its current order:\", animals)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -1739,7 +2131,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -1772,7 +2164,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -1813,25 +2205,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Jack', 'and', 'Jill', 'went', 'up', 'the', 'hill', 'To', 'fetch', 'a', 'pail', 'of', 'water']\n" + ] + } + ], "source": [ "# [ ] split the string(rhyme) into a list of words (rhyme_words)\n", "# [ ] print each word on it's own line\n", "rhyme = 'Jack and Jill went up the hill To fetch a pail of water' \n", - "\n" + "\n", + "rhyme_words = rhyme.split()\n", + "\n", + "print(rhyme_words)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python\n", + "spaces\n", + "indentation\n" + ] + } + ], "source": [ "# [ ] split code_tip into a list and print the first and every other word\n", "code_tip = \"Python uses spaces for indentation\"\n", - "\n" + "code_list = code_tip.split()\n", + "\n", + "word_count = len(code_list)\n", + "\n", + "for index in range(0, word_count, 2):\n", + " print(code_list[index])\n" ] }, { @@ -1859,7 +2277,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -1880,7 +2298,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -1904,7 +2322,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -1951,13 +2369,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Write code frequently', 'Save code frequently', 'Comment code frequently', 'Study code frequently', '']\n", + "Write Code Frequently\n", + "Save Code Frequently\n", + "Comment Code Frequently\n", + "Study Code Frequently\n" + ] + } + ], "source": [ "# [ ] split poem into a list of phrases by splitting on \"*\" a\n", "# [ ] print each phrase on a new line in title case\n", - "poem = \"Write code frequently*Save code frequently*Comment code frequently*Study code frequently*\"\n" + "poem = \"Write code frequently*Save code frequently*Comment code frequently*Study code frequently*\"\n", + "poem_split = poem.split('*')\n", + "\n", + "print(poem_split)\n", + "\n", + "for this in poem_split:\n", + " if this:\n", + " print(this.title())" ] }, { @@ -1988,7 +2425,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -2009,7 +2446,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -2029,7 +2466,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -2068,13 +2505,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Asterisk\n" + ] + } + ], "source": [ "# [ ] .join() letters list objects with an Asterisk: \"*\"\n", "letters = [\"A\", \"s\", \"t\", \"e\", \"r\", \"i\", \"s\", \"k\"]\n", - "\n" + "\n", + "print(''.join(letters))" ] }, { @@ -2092,13 +2538,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Jack5and5Jill5went5up5the5hill5To5fetch5a5pail5of5water\n" + ] + } + ], "source": [ "# [ ] complete Choose the separator\n", "phrase_words = ['Jack', 'and', 'Jill', 'went', 'up', 'the', 'hill', 'To', 'fetch', 'a', 'pail', 'of', 'water']\n", - "\n" + "\n", + "seperator = input('How would you like to join this? ')\n", + "\n", + "print(seperator.join(phrase_words))" ] }, { @@ -2130,7 +2587,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -2149,7 +2606,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -2172,7 +2629,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -2191,7 +2648,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -2212,7 +2669,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -2242,13 +2699,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Write code frequently_ Save code frequently_ Comment code frequently\n" + ] + } + ], "source": [ "# [ ] use 3 print() statements to output text to one line \n", "# [ ] separate the lines by using \"- \" (dash space)\n", - "\n" + "print('Write code frequently', end=\"_ \")\n", + "print(\"Save code frequently\", end=\"_ \")\n", + "print(\"Comment code frequently\") \n" ] }, { @@ -2263,13 +2730,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The list of characters is: ['P', 'y', 't', 'h', 'o', 'n', ' ', 'i', 's', ' ', 'f', 'u', 'n', ' ', 'a', 'n', 'd', ' ', 'e', 'a', 's', 'y', ' ', 't', 'o', ' ', 'l', 'e', 'a', 'r', 'n']\n", + "\n", + "--- Output ---\n", + "Python\n", + "is\n", + "fun\n", + "and\n", + "easy\n", + "to\n", + "learn\n", + "--- End Output ---\n" + ] + } + ], "source": [ "# [ ] create a string (fact) of 20 or more characters and cast to a list (fact_letters)\n", "# [ ] iterate fact, printing each char on one line, except for spaces print a new line\n", - "\n" + "\n", + "fact = \"Python is fun and easy to learn\"\n", + "\n", + "facto_letters = list(fact)\n", + "print(\"The list of characters is:\", facto_letters)\n", + "\n", + "print(\"\\n--- Output ---\")\n", + "\n", + "for char in fact:\n", + " if char == \" \":\n", + " print()\n", + " else:\n", + " print(char, end=\"\")\n", + "\n", + "print(\"\\n--- End Output ---\")" ] }, { @@ -2290,12 +2789,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The equation is:\n", + "1+2+3+4+5+6+7+8+9+1+0+1+1+1+2+1+3+1+4+1+5+1+6+1+7+1+8+1+9+2+0 = 102\n" + ] + } + ], "source": [ "# [ ] create add the digits\n", "\n", + "digit_string = \"1234567891011121314151617181920\"\n", + "\n", + "digit_list = list(digit_string)\n", + "\n", + "total_sum = sum(int(d) for d in digit_list)\n", + "\n", + "equation = \"+\".join(digit_list)\n", + "\n", + "print(\"The equation is:\")\n", + "print(equation, \"=\", total_sum)\n", "\n" ] }, @@ -2326,7 +2844,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_3.1_Practice_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_3.1_Practice_Python_Fundamentals.ipynb index 572b1d9a..4ed3e58f 100644 --- a/P2 Python Fundamentals/Module_3.1_Practice_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_3.1_Practice_Python_Fundamentals.ipynb @@ -27,37 +27,105 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Solid - is state of matter #1\n", + "Liquid - is state of matter #2\n", + "Gas - is state of matter #3\n", + "Plasma - is state of matter #4\n" + ] + } + ], "source": [ "# [ ] print out the \"physical states of matter\" (matter_states) in 4 sentences using list iteration\n", "# each sentence should be of the format: \"Solid - is state of matter #1\" \n", "matter_states = ['solid', 'liquid', 'gas', 'plasma']\n", - "\n" + "\n", + "for i, state in enumerate(matter_states):\n", + " print(f\"{state.title()} - is state of matter #{i + 1}\")" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OG birds list: ['turkey', 'hawk', 'chicken', 'dove', 'crow']\n", + "Birds list after removal: ['turkey', 'hawk', 'dove']\n" + ] + } + ], "source": [ "# [ ] iterate the list (birds) to see any bird names start with \"c\" and remove that item from the list\n", "# print the birds list before and after removals\n", "birds = [\"turkey\", \"hawk\", \"chicken\", \"dove\", \"crow\"]\n", + "\n", + "birds_to_keep = []\n", + "\n", + "print(\"OG birds list:\", birds)\n", + "\n", + "for bird in birds:\n", + " if not bird.lower().startswith(\"c\"):\n", + " birds_to_keep.append(bird)\n", + "\n", + "birds = birds_to_keep\n", + "\n", + "print(\"Birds list after removal:\", birds)\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Basket Occurrences:\n", + "1pt Baskets: 4\n", + "2pt Baskets: 8\n", + "3pt Baskets: 3\n", + "\n", + "Total Points: 29\n" + ] + } + ], "source": [ "# the team makes 1pt, 2pt or 3pt baskets\n", "# [ ] print the occurace of each type of basket(1pt, 2pt, 3pt) & total points using the list baskets\n", "baskets = [2,2,2,1,2,1,3,3,1,2,2,2,2,1,3]\n", + "\n", + "one_point_baskets = 0\n", + "two_point_baskets = 0\n", + "three_point_baskets = 0\n", + "total_points = 0\n", + "\n", + "for basket in baskets:\n", + " total_points += basket\n", + "\n", + " if basket == 1:\n", + " one_point_baskets += 1\n", + " elif basket ==2:\n", + " two_point_baskets +=1\n", + " elif basket == 3:\n", + " three_point_baskets += 1\n", + "\n", + "print(\"Basket Occurrences:\")\n", + "print(\"1pt Baskets:\", one_point_baskets)\n", + "print(\"2pt Baskets:\", two_point_baskets)\n", + "print(\"3pt Baskets:\", three_point_baskets)\n", + "print(\"\\nTotal Points:\", total_points)\n", "\n" ] }, @@ -72,64 +140,158 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello\n", + "hello\n", + "hello\n", + "hello\n" + ] + } + ], "source": [ "# [ ] using range() print \"hello\" 4 times\n", "\n", - "\n" + "for i in range(4):\n", + " print(\"hello\")\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "List Length: 7\n", + "------------------------------\n", + "FIRST HALF:\n", + "Tuesday\n", + "Wednesday\n", + "February\n", + "------------------------------\n", + "SECOND HALF:\n", + "November\n", + "Annual\n", + "Calendar\n", + "Solstice\n" + ] + } + ], "source": [ "# [ ] find spell_list length\n", "# [ ] use range() to iterate each half of spell_list \n", "# [ ] label & print the first and second halves\n", "spell_list = [\"Tuesday\", \"Wednesday\", \"February\", \"November\", \"Annual\", \"Calendar\", \"Solstice\"]\n", - "\n" + "\n", + "list_length = len(spell_list)\n", + "\n", + "midpoint = list_length // 2\n", + "\n", + "print(\"List Length:\", list_length)\n", + "print(\"-\" * 30)\n", + "\n", + "print(\"FIRST HALF:\")\n", + "\n", + "for index in range(0, midpoint):\n", + " print(spell_list[index])\n", + "\n", + "print(\"-\" * 30)\n", + "\n", + "print(\"SECOND HALF:\")\n", + "\n", + "for index in range(midpoint, list_length):\n", + " print(spell_list[index])\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n" + ] + } + ], "source": [ "# [ ] build a list of numbers from 20 to 29: twenties \n", "# append each number to twenties list using range(start,stop) iteration\n", "# [ ] print twenties\n", "twenties = []\n", - "\n" + "\n", + "for num in range(20, 30):\n", + "\n", + " twenties.append(num)\n", + "\n", + "print(twenties)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total: 245\n" + ] + } + ], "source": [ "# [ ] iterate through the numbers populated in the list twenties and add each number to a variable: total\n", "# [ ] print total\n", "total = 0\n", - "\n" + "\n", + "twenties = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n", + "\n", + "total = 0\n", + "\n", + "for num in twenties:\n", + "\n", + " total += num\n", + "\n", + "\n", + "print(\"Total:\", total)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total calculated using range(): 245\n" + ] + } + ], "source": [ "# check your answer above using range(start,stop)\n", "# [ ] iterate each number from 20 to 29 using range()\n", "# [ ] add each number to a variable (total) to calculate the sum\n", "# should match earlier task \n", "total = 0\n", + "\n", + "for num in range(20, 30):\n", + "\n", + " total += num\n", + "\n", + "print(\"Total calculated using range():\", total)\n", "\n" ] }, @@ -144,47 +306,127 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]\n" + ] + } + ], "source": [ "# [ ] create a list of odd numbers (odd_nums) from 1 to 25 using range(start,stop,skip)\n", "# [ ] print odd_nums\n", "# hint: odd numbers are 2 digits apart\n", - "\n" + "\n", + "odd_nums = list(range(1, 26, 2))\n", + "\n", + "print(odd_nums)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]\n" + ] + } + ], "source": [ "# [ ] create a Decending list of odd numbers (odd_nums) from 25 to 1 using range(start,stop,skip)\n", "# [ ] print odd_nums, output should resemble [25, 23, ...]\n", "\n", - "\n" + "odd_nums = list(range(25, 0, -2))\n", + "\n", + "print(odd_nums)\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2 - Helium\n", + "4 - Beryllium\n", + "6 - Carbon\n", + "8 - Oxygen\n", + "10 - Neon\n", + "12 - Magnesium\n", + "14 - Silicon\n", + "16 - Sulfur\n", + "18 - Argon\n", + "20 - Calcium\n" + ] + } + ], "source": [ "# the list, elements, contains the names of the first 20 elements in atomic number order\n", "# [ ] print the even number elements \"2 - Helium, 4 - Beryllium,..\" in the list with the atomic number\n", "elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \\\n", " 'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \\\n", " 'Potassium', 'Calcium']\n", - "\n" + "\n", + "for i, element in enumerate(elements[1::2]):\n", + "\n", + " atomic_num = (i * 2) + 2\n", + "\n", + " print(f\"{atomic_num} - {element}\")" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 - Hydrogen\n", + "3 - Lithium\n", + "5 - Boron\n", + "7 - Nitrogen\n", + "9 - Fluorine\n", + "11 - Sodium\n", + "13 - Aluminum\n", + "15 - Phosphorus\n", + "17 - Chlorine\n", + "19 - Potassium\n", + "21 - Hydrogen\n", + "23 - Lithium\n", + "25 - Boron\n", + "27 - Nitrogen\n", + "29 - Fluorine\n", + "31 - Sodium\n", + "33 - Aluminum\n", + "35 - Phosphorus\n", + "37 - Chlorine\n", + "39 - Potassium\n", + "41 - Scandium\n", + "43 - Vanadium\n", + "45 - Manganese\n", + "47 - Cobalt\n", + "49 - Copper\n", + "51 - Gallium\n", + "53 - Arsenic\n", + "55 - Bromine\n", + "57 - Rubidium\n", + "59 - Yttrium\n" + ] + } + ], "source": [ "# [ ] # the list, elements_60, contains the names of the first 60 elements in atomic number order\n", "# [ ] print the odd number elements \"1 - Hydrogen, 3 - Lithium,..\" in the list with the atomic number elements_60\n", @@ -196,16 +438,14 @@ " 'Argon', 'Potassium', 'Calcium', 'Scandium', 'Titanium', 'Vanadium', 'Chromium', 'Manganese', \\\n", " 'Iron', 'Cobalt', 'Nickel', 'Copper', 'Zinc', 'Gallium', 'Germanium', 'Arsenic', 'Selenium', \\\n", " 'Bromine', 'Krypton', 'Rubidium', 'Strontium', 'Yttrium', 'Zirconium']\n", - "\n" + "\n", + "for i, element in enumerate(elements_60[0::2]):\n", + "\n", + " atomic_num = (i * 2) + 1\n", + "\n", + " print(f\"{atomic_num} - {element}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -217,9 +457,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "numbers_1: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n", + "numbers_2 [30, 32, 34, 36, 38, 40, 42, 44, 46, 48]\n", + "\n", + "Combined List (+ Operator): [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]\n" + ] + } + ], "source": [ "# [ ] print the combined lists (numbers_1 & numbers_2) using \"+\" operator\n", "numbers_1 = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n", @@ -229,14 +480,27 @@ "\n", "print(\"numbers_1:\",numbers_1)\n", "print(\"numbers_2\",numbers_2)\n", - "\n" + "\n", + "combined_list = numbers_1 + numbers_2\n", + "print(\"\\nCombined List (+ Operator):\", combined_list)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1st Row: ['Hydrogen', 'Helium']\n", + "2nd Row: ['Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']\n", + "\n", + "Combined List (.extend() Operator): ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']\n" + ] + } + ], "source": [ "# [ ] print the combined element lists (first_row & second_row) using \".extend()\" method\n", "first_row = ['Hydrogen', 'Helium']\n", @@ -244,7 +508,10 @@ "\n", "print(\"1st Row:\", first_row)\n", "print(\"2nd Row:\", second_row)\n", - "\n" + "\n", + "first_row.extend(second_row)\n", + "\n", + "print(\"\\nCombined List (.extend() Operator):\", first_row)" ] }, { @@ -302,27 +569,63 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Calcium', 'Potassium', 'Argon', 'Chlorine', 'Sulfur', 'Phosphorus', 'Silicon', 'Aluminum', 'Magnesium', 'Sodium', 'Neon', 'Fluorine', 'Oxygen', 'Nitrogen', 'Carbon', 'Boron', 'Beryllium', 'Lithium', 'Helium', 'Hydrogen']\n" + ] + } + ], "source": [ "# [ ] use .reverse() to print elements starting with \"Calcium\", \"Chlorine\",... in reverse order\n", "elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \\\n", " 'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \\\n", " 'Potassium', 'Calcium']\n", - "\n" + "\n", + "elements.reverse()\n", + "\n", + "print(elements)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original List: ['Tuesday', 'Wednesday', 'February', 'November', 'Annual', 'Calendar', 'Solstice']\n", + "Reversed List: ['Solstice', 'Calendar', 'Annual', 'November', 'February', 'Wednesday', 'Tuesday']\n", + "\n", + "Words 8 characters or longer:\n", + "Solstice\n", + "Calendar\n", + "November\n", + "February\n", + "Wednesday\n" + ] + } + ], "source": [ "# [ ] reverse order of the list... Then print only words that are 8 characters or longer from the now reversed order\n", "spell_list = [\"Tuesday\", \"Wednesday\", \"February\", \"November\", \"Annual\", \"Calendar\", \"Solstice\"]\n", "\n", - "\n" + "print(\"Original List:\", spell_list)\n", + "\n", + "spell_list.reverse()\n", + "\n", + "print(\"Reversed List:\", spell_list)\n", + "\n", + "print(\"\\nWords 8 characters or longer:\")\n", + "for word in spell_list:\n", + " if len(word) >= 8:\n", + " print(word)\n" ] }, { @@ -336,26 +639,49 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Aluminum', 'Argon', 'Beryllium', 'Boron', 'Calcium', 'Carbon', 'Chlorine', 'Fluorine', 'Helium', 'Hydrogen', 'Lithium', 'Magnesium', 'Neon', 'Nitrogen', 'Oxygen', 'Phosphorus', 'Potassium', 'Silicon', 'Sodium', 'Sulfur']\n" + ] + } + ], "source": [ "# [ ] sort the list element, so names are in alphabetical order and print elements\n", "elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \\\n", " 'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \\\n", " 'Potassium', 'Calcium']\n", - "\n" + "\n", + "elements.sort()\n", + "\n", + "print(elements)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sorted List: [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]\n", + "Original List: [2, 2, 2, 1, 2, 1, 3, 3, 1, 2, 2, 2, 2, 1, 3]\n" + ] + } + ], "source": [ "# [ ] print the list, numbers, sorted and then below print the original numbers list \n", "numbers = [2,2,2,1,2,1,3,3,1,2,2,2,2,1,3]\n", - "\n" + "\n", + "print(\"Sorted List:\", sorted(numbers))\n", + "\n", + "print(\"Original List:\", numbers)" ] }, { @@ -369,37 +695,87 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DID\n", + "YOU\n", + "KNOW\n", + "THAT\n", + "THERE\n", + "ARE\n", + "1.4\n", + "BILLION\n", + "STUDENTS\n", + "IN\n", + "THE\n", + "WORLD?\n" + ] + } + ], "source": [ "# [ ] split the string, daily_fact, into a list of word strings: fact_words\n", "# [ ] print each string in fact_words in upper case on it's own line\n", "daily_fact = \"Did you know that there are 1.4 billion students in the world?\"\n", - "\n" + "\n", + "fact_words = daily_fact.split()\n", + "\n", + "for word in fact_words:\n", + " print(word.upper())" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Pyth', 'n is fun and easy t', ' learn']\n" + ] + } + ], "source": [ "# [ ] convert the string, code_tip, into a list made from splitting on the letter \"o\"\n", "\n", - "\n" + "code_tip = \"Python is fun and easy to learn\"\n", + "\n", + "code_list = code_tip.split('o')\n", + "\n", + "print(code_list)\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The \n", + "right \n", + "rain, has \n", + "ran!\n" + ] + } + ], "source": [ "# [ ] split poem on \"b\" to create a list: poem_words\n", "# [ ] print poem_words by iterating the list\n", "poem = \"The bright brain, has bran!\"\n", - "\n" + "\n", + "poem_words = poem.split('b')\n", + "\n", + "for word in poem_words:\n", + " print(word)" ] }, { @@ -414,26 +790,53 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chlorine, Florine, Bromine, Iodine\n" + ] + } + ], "source": [ "# [ ] print a comma separated string output from the list of Halogen elements using \".join()\"\n", "halogens = ['Chlorine', 'Florine', 'Bromine', 'Iodine']\n", - "\n" + "\n", + "halogen_string = \", \".join(halogens)\n", + "\n", + "print(halogen_string)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ReadCodeAloudOrExplainTheCodeStepByStepToAPeer\n" + ] + } + ], "source": [ "# [ ] split the sentence, code_tip, into a words list\n", "# [ ] print the joined words in the list with no spaces in-between\n", "# [ ] Bonus: capitalize each word in the list before .join()\n", "code_tip =\"Read code aloud or explain the code step by step to a peer\"\n", - "\n" + "\n", + "code_list = code_tip.split()\n", + "\n", + "capitalized_list = []\n", + "for word in code_list:\n", + " capitalized_list.append(word.capitalize())\n", + "\n", + "no_space_string = \"\".join(capitalized_list)\n", + "print(no_space_string)" ] }, { @@ -450,33 +853,73 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list of letters: ['d', 'e', 'c', 'e', 'l', 'e', 'r', 'a', 't', 'i', 'n', 'g']\n", + "\n", + "Individual letters on one line:\n", + "d e c e l e r a t i n g " + ] + } + ], "source": [ "# [ ] cast the long_word into individual letters list \n", "# [ ] print each letter on a line\n", "long_word = 'decelerating'\n", - "\n" + "\n", + "letter_list = list(long_word)\n", + "print(\"list of letters:\", letter_list)\n", + "\n", + "print(\"\\nIndividual letters on one line:\")\n", + "\n", + "for letter in letter_list:\n", + " print(letter, end=' ')\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What's the closest planet to the Sun?\n", + "How deep do Dolphins swim?\n", + "What time is it?\n" + ] + } + ], "source": [ "# [ ] use use end= in print to output each string in questions with a \"?\" and on new lines\n", "questions = [\"What's the closest planet to the Sun\", \"How deep do Dolphins swim\", \"What time is it\"]\n", "\n", - "\n" + "for question in questions:\n", + "\n", + " print(question, end='?')\n", + "\n", + " print()\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Calcaneus, Talus, Cuboid, Navicular, Lateral Cuneiform, Intermediate Cuneiform, Medial Cuneiform" + ] + } + ], "source": [ "# [ ] print each item in foot bones \n", "# - capitalized, both words if two word name\n", @@ -484,6 +927,14 @@ "# - and keeping on a single print line\n", "foot_bones = [\"calcaneus\", \"talus\", \"cuboid\", \"navicular\", \"lateral cuneiform\", \n", " \"intermediate cuneiform\", \"medial cuneiform\"]\n", + "\n", + "list_length = len(foot_bones)\n", + "\n", + "for i in range(list_length):\n", + " print(foot_bones[i].title(), end='')\n", + "\n", + " if i < list_length - 1:\n", + " print(\", \", end='')\n", "\n" ] }, @@ -512,7 +963,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_3.2_Required_Code_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_3.2_Required_Code_Python_Fundamentals.ipynb index b6a3e871..f9d321d6 100644 --- a/P2 Python Fundamentals/Module_3.2_Required_Code_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_3.2_Required_Code_Python_Fundamentals.ipynb @@ -68,15 +68,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tiger DECIDED ~ that FROSTED would some MACARONI was of OBSCURE was it PASSION the for REASON, tasty flakes There powers be Tony named\n" + ] + } + ], "source": [ "# [] create poem mixer function, call the function with the provided test string\n", "# [] test string: `Little fly, Thy summer’s play My thoughtless hand Has brushed away. Am not I A fly like thee? Or art not thou A man like me?` \n", "\n", + "def word_mixer(original_list):\n", + " original_list.sort()\n", + "\n", + " new_words = []\n", + "\n", + " while len(original_list) > 5:\n", + " new_words.append(original_list.pop(-5))\n", + "\n", + " new_words.append(original_list.pop(0))\n", + "\n", + " new_words.append(original_list.pop(-1))\n", + "\n", + " return new_words\n", + "\n", + "poem_input = input(\"Welcome Ben Reed, enter a saying or peom: \")\n", + "\n", + "word_list = poem_input.split()\n", + "\n", + "list_length = len(word_list)\n", + "\n", + "for word_string in range(list_length):\n", + " word = word_list[word_string]\n", + " word_length = len(word)\n", + "\n", + " if word_length <= 3:\n", + " word_list[word_string] = word.lower()\n", + "\n", + " elif word_length >= 7:\n", + " word_list[word_string] = word.upper()\n", + "\n", + "\n", + "mixed_words_list = word_mixer(word_list)\n", + "\n", + "print(\" \".join(mixed_words_list))\n", "\n", "\n" ] @@ -106,7 +148,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_4.0_Tutorials_Files_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_4.0_Tutorials_Files_Python_Fundamentals.ipynb index e4fcbefd..8bfc6189 100644 --- a/P2 Python Fundamentals/Module_4.0_Tutorials_Files_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_4.0_Tutorials_Files_Python_Fundamentals.ipynb @@ -64,9 +64,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 85 0 --:--:-- --:--:-- --:--:-- 85\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem1.txt -o poem1.txt\n" @@ -103,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -113,9 +126,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "<_io.TextIOWrapper name='poem1.txt' mode='r' encoding='cp1252'>" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] run and review code to test if open worked \n", "# should display name='poem1.txt' and no errors\n", @@ -141,9 +165,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 346 0 --:--:-- --:--:-- --:--:-- 350\n" + ] + } + ], "source": [ "# [ ] import cities.txt\n", "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities -o cities.txt\n" @@ -151,13 +187,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='cities.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ "# [ ] open cities.txt as cities_file\n", "# [ ] test cities.txt was opened \n", - "cities_file = open('cities.txt','r')\n", + "cities_file = open('cities.txt', 'r')\n", "print(cities_file)\n" ] }, @@ -188,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -198,9 +242,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Loops I repeat\\nloops\\nloops\\nloops\\nI repeat\\nuntil I\\nbreak\\n'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example\n", "# shows the file as a string with formatting characters such as \"\\n\", output should be non-blank\n", @@ -209,9 +264,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "loops\n", + "loops\n", + "loops\n", + "I repeat\n", + "until I\n", + "break\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "# since .read() loaded the file as a string it can be printed\n", @@ -238,24 +308,75 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='cities.txt' mode='r' encoding='cp1252'>\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 298 0 --:--:-- --:--:-- --:--:-- 301\n" + ] + }, + { + "data": { + "text/plain": [ + "'Beijing\\nCairo\\nLondon\\nNairobi\\nNew York City\\nSydney\\nTokyo\\n'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] after import and open of cities.txt in task 1\n", "# [ ] read cities_file as cities\n", "# [ ] display the string: cities\n", - "\n" + "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities -o cities.txt\n", + "cities_file = open('cities.txt', 'r')\n", + "print(cities_file)\n", + "\n", + "cities = cities_file.read()\n", + "\n", + "cities" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beijing\n", + "Cairo\n", + "London\n", + "Nairobi\n", + "New York City\n", + "Sydney\n", + "Tokyo\n", + "\n" + ] + } + ], "source": [ "# [ ] print the string: cities\n", - "\n" + "\n", + "print(cities)" ] }, { @@ -286,9 +407,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I re\n" + ] + }, + { + "data": { + "text/plain": [ + "'Loops I re'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example to read poem1.txt 10 characters at a time\n", "poem_file = open('poem1.txt', 'r')\n", @@ -299,9 +438,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'peat\\nloops'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example, + 10 more characters\n", "# reads and displays without storing in a variable\n", @@ -310,9 +460,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "loops\n", + "loo\n" + ] + } + ], "source": [ "# [ ] review and run example, + 10 more characters\n", "# reads and stores in variable poem_parts\n", @@ -322,9 +482,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "loops\n", + "loops\n", + "I repeat\n", + "until I\n", + "break\n", + "\n" + ] + } + ], "source": [ "# [ ] REPEATEDLY RUN this cell, + 5 more characters each time run are appended using string addition\n", "# [ ] consider why no additional text displays after multiple runs\n", @@ -354,39 +528,79 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 303 100 303 0 0 1837 0 --:--:-- --:--:-- --:--:-- 1847\n" + ] + } + ], "source": [ "# [ ] digits of pi\n", "# 1. import digits_of_pi.txt\n", - "\n" + "\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi -o digits_of_pi.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.14\n" + ] + } + ], "source": [ "# [ ] digits of pi\n", "# 2. open as digits_of_pi_text \n", "# 3. read() 4 char of digits_of_pi_text to pi_digits variable \n", "# 4. print pi_digits \n", - "\n" + "dop = open(\"digits_of_pi.txt\", 'r')\n", + "pi_digits = dop.read(4)\n", + "\n", + "print(pi_digits)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.141592\n" + ] + } + ], "source": [ "# [ ] digits of pi\n", "# 5. add to pi_digits string with string addition \n", "# a. add next 4 characters from digits_of_pi obtained from read() \n", "# b. run the cell multiple times to get more digits of *pi*\n", - "\n" + "\n", + "dop = open('digits_of_pi.txt', 'r')\n", + "\n", + "pi_digits = dop.read(4)\n", + "\n", + "pi_digits = pi_digits + dop.read(4)\n", + "\n", + "print(pi_digits)" ] }, { @@ -421,9 +635,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "LOOPS I REPEAT\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "poem_file = open('poem1.txt', 'r')\n", @@ -433,9 +656,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "poem_part = poem_file.read(6).title()\n", @@ -444,9 +676,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "loops\n", + "\n", + "False isalpha() because of `\\n`\n" + ] + }, + { + "data": { + "text/plain": [ + "'loops\\n'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example\n", "poem_part = poem_file.read(6)\n", @@ -457,9 +709,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "repeat\n", + "loops\n", + "loops\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "poem_file = open('poem1.txt', 'r')\n", @@ -486,20 +748,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + " 0 56 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 313 0 --:--:-- --:--:-- --:--:-- 314\n" + ] + } + ], "source": [ "# [ ] compelete the task\n", - "\n" + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities -o cities.txt\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beijing\n", + "Cairo\n", + "London\n", + "Nairobi\n", + "New York City\n", + "Sydney\n", + "Tokyo\n", + "\n", + "BCLNNYCST\n" + ] + } + ], + "source": [ + "cities_file = open('cities.txt', 'r')\n", + "\n", + "cities = cities_file.read()\n", + "print(cities)\n", + "\n", + "cities_file.close()\n", + "\n", + "initials = \"\"\n", + "\n", + "for char in cities:\n", + " if char.isupper():\n", + " initials += char\n", + "\n", + " elif char == \"]\\n\":\n", + " initials += char\n", + "\n", + "print(initials)\n", + "\n" + ] }, { "cell_type": "markdown", @@ -556,11 +866,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": { "scrolled": false }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 214 0 --:--:-- --:--:-- --:--:-- 215\n" + ] + } + ], "source": [ "# [ ] Run to download file to notebook\n", "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem1.txt -o poem1.txt" @@ -568,9 +890,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Loops I repeat\\n',\n", + " 'loops\\n',\n", + " 'loops\\n',\n", + " 'loops\\n',\n", + " 'I repeat\\n',\n", + " 'until I\\n',\n", + " 'break\\n']" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example\n", "# open address to file\n", @@ -583,9 +922,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "\n", + "loops\n", + "\n", + "loops\n", + "\n", + "loops\n", + "\n", + "I repeat\n", + "\n", + "until I\n", + "\n", + "break\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example\n", "for line in poem_lines:\n", @@ -613,32 +973,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 210 0 --:--:-- --:--:-- --:--:-- 211\n" + ] + } + ], "source": [ "# [ ] import cities\n", - "\n" + "! Curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities -o cities.txt\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "# [ ] open cities.txt as cities_file and read the file as a list: cities_lines\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "cities_file = open(\"cities.txt\", 'r')\n", + "cities_lines = cities_file.readlines()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beijing\n", + "\n", + "Cairo\n", + "\n", + "London\n", + "\n", + "Nairobi\n", + "\n", + "New York City\n", + "\n", + "Sydney\n", + "\n", + "Tokyo\n", + "\n" + ] + } + ], "source": [ "# [ ] use list iteration to print each city in cities_lines list\n", - "\n" + "\n", + "for city in cities_lines:\n", + " print(city)" ] }, { @@ -677,9 +1073,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Loops I repeat\\n', 'loops\\n', 'loops\\n', 'loops\\n', 'I repeat\\n', 'until I\\n', 'break\\n']\n" + ] + } + ], "source": [ "# [ ] review and run examples\n", "# [ ] re-open file and read file as a list of strings\n", @@ -690,20 +1094,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "loops\n", + "loops\n", + "loops\n", + "I repeat\n", + "until I\n", + "break\n" + ] + } + ], "source": [ "# [ ] print each list item \n", "for line in poem_lines:\n", - " print(line)" + " print(line, end=\"\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Loops I repeat', 'loops', 'loops', 'loops', 'I repeat', 'until I', 'break']\n" + ] + } + ], "source": [ "# [ ] remove the last character of each list item, which is \"\\n\"\n", "count = 0\n", @@ -717,9 +1143,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "loops\n", + "loops\n", + "loops\n", + "I repeat\n", + "until I\n", + "break\n" + ] + } + ], "source": [ "# [ ] print each list item \n", "for line in poem_lines:\n", @@ -742,32 +1182,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, "outputs": [], "source": [ "# [ ] re-open file and read file as a list of strings \n", "# [ ] open cities.txt as cities_file and read the file as a list: cities_lines\n", - "\n" + "\n", + "cities_file = open(\"cities.txt\", 'r')\n", + "cities_lines = cities_file.readlines()\n", + "cities_file.close()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": {}, "outputs": [], "source": [ "# [ ] remove the last character, \"\\n\", of each cities_lines list item \n", - "\n" + "\n", + "cities_stripped = []\n", + "for city in cities_lines:\n", + " # Use .strip() to remove the newline character (and any other whitespace)\n", + " cities_stripped.append(city.strip())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beijing\n", + "Cairo\n", + "London\n", + "Nairobi\n", + "New York City\n", + "Sydney\n", + "Tokyo\n" + ] + } + ], "source": [ - "# [ ] print each list item in cities_lines\n" + "# [ ] print each list item in cities_lines\n", + "for city in cities_stripped:\n", + " print(city)" ] }, { @@ -797,9 +1260,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example: open and readlines of poem1.txt\n", "poem1 = open('poem1.txt', 'r')\n", @@ -808,9 +1282,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Loops I repeat\\n', 'loops\\n', 'loops\\n', 'loops\\n', 'I repeat\\n', 'until I\\n', 'break\\n']\n" + ] + } + ], "source": [ "# [ ] review and run example: readlines breaks if file is no longer open\n", "\n", @@ -820,9 +1302,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example: Close poem1\n", "poem1.close()\n", @@ -848,51 +1341,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='cities.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ "# [ ] open cities.txt as cities_file\n", - "\n" + "cities_file = open('cities.txt', 'r')\n", + "print(cities_file)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Beijing\\n', 'Cairo\\n', 'London\\n', 'Nairobi\\n', 'New York City\\n', 'Sydney\\n', 'Tokyo\\n']\n" + ] + } + ], "source": [ "# [ ] read the lines as cities_lines\n", - "\n" + "cities_lines = cities_file.readlines()\n", + "print(cities_lines)\n", + "\n", + "cities_file.close()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "London\n", + "Nairobi\n", + "New York City\n", + "Sydney\n", + "Tokyo\n" + ] + } + ], "source": [ "# [ ] print the cities that start with the letter \"D\" or greater\n", - "\n" + "for city in cities_lines:\n", + " city_name = city.strip()\n", + "\n", + " if city_name:\n", + " if city_name[0] >= 'D':\n", + " print(city_name)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "File closed status: True\n", + "The file is successfully closed.\n" + ] + } + ], "source": [ "# [ ] test that file is closed\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# [ ] close cities_file\n", + "is_closed = cities_file.closed\n", + "print(f'File closed status: {is_closed}')\n", + " \n", + "if is_closed:\n", + " print('The file is successfully closed.')\n", + " \n", + "else:\n", + " print('The file is still open.')\n", "\n" ] }, @@ -915,52 +1452,116 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 57 100 57 0 0 355 0 --:--:-- --:--:-- --:--:-- 360\n" + ] + } + ], "source": [ "# [ ] import https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem2.txt as poem2.txt\n", - "\n" + "\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem2.txt -o poem2.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='poem2.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ "# [ ] open poem2.txt as poem2_text in read mode\n", - "\n" + "poem2_text = open(\"poem2.txt\", \"r\")\n", + "print(poem2_text)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['while True\\n', 'I loop\\n', 'True\\n', 'loop\\n', 'True\\n', 'loop\\n', 'not True\\n', 'False\\n', 'end\\n']\n" + ] + } + ], "source": [ "# [ ] create a list of strings, called poem2_lines, from each line of poem2_text\n", + "poem2_lines = poem2_text.readlines()\n", + "print(poem2_lines)\n", + "\n", + "poem2_text.close()\n", + "\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['while True', 'I loop', 'True', 'loop', 'True', 'loop', 'not True', 'False', 'end']\n" + ] + } + ], "source": [ "# [ ] remove the newline character for each list item in poem2_lines\n", - "\n" + "\n", + "poem2_lines = [line.strip() for line in poem2_lines]\n", + "\n", + "print(poem2_lines)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "end\n", + "False\n", + "not True\n", + "loop\n", + "True\n", + "loop\n", + "True\n", + "I loop\n", + "while True\n" + ] + } + ], "source": [ "# [ ] print the poem2 lines in reverse order\n", - "\n" + "\n", + "for line in poem2_lines[::-1]:\n", + " print(line)" ] }, { @@ -1020,9 +1621,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 56 100 56 0 0 290 0 --:--:-- --:--:-- --:--:-- 293\n" + ] + } + ], "source": [ "# [ ]Run to download file poem1.txt\n", "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem1.txt -o poem1.txt " @@ -1030,7 +1643,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -1041,7 +1654,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -1054,9 +1667,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "loops\n", + "loops\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example: print the first 3 .readline() values\n", "print(poem_line1 + poem_line2 + poem_line3)" @@ -1064,9 +1688,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# [ ] review and run example printing return value & re-run several times\n", "print(poem1.readline())" @@ -1074,7 +1706,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -1102,49 +1734,88 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + " 0 43 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 43 100 43 0 0 154 0 --:--:-- --:--:-- --:--:-- 154\n" + ] + } + ], "source": [ "# [ ] import https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow as rainbow.txt\n", - "\n" + "\n", + "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow -o rainbow.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='rainbow.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ - "# [ ] open rainbow.txt as rainbow_text\n" + "# [ ] open rainbow.txt as rainbow_text\n", + "rainbow_text = open(\"rainbow.txt\", \"r\")\n", + "print(rainbow_text)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ - "# [ ] read the first 3 lines into variables: color1, color2, color3\n" + "# [ ] read the first 3 lines into variables: color1, color2, color3\n", + "color1 = rainbow_text.readline()\n", + "color2 = rainbow_text.readline()\n", + "color3 = rainbow_text.readline()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ - "# [ ] close rainbow.txt\n" + "# [ ] close rainbow.txt\n", + "rainbow_text.close()\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "red\n", + "orange\n", + "yellow\n", + "\n" + ] + } + ], "source": [ "# [ ] print the first 3 colors\n", - "\n" + "print(color1 + color2 + color3)\n" ] }, { @@ -1177,7 +1848,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ @@ -1188,9 +1859,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "loops i repeat\n", + "loops\n", + "loops\n", + "loops\n", + "i repeat\n", + "until i\n", + "break\n" + ] + } + ], "source": [ "# [ ] review and run example - use a while loop to read each line of a file \n", "# remove last character ('\\n') and print as upper case\n", @@ -1203,7 +1888,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -1230,33 +1915,62 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='rainbow.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ "# [ ] open rainbow.txt as rainbow_text as read-only\n", - "\n" + "rainbow_file = open('rainbow.txt', 'r')\n", + "print(rainbow_file)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Red\n", + "Orange\n", + "Yellow\n", + "Green\n", + "Blue\n", + "Indigo\n", + "Violet\n" + ] + } + ], "source": [ "# [ ] read the color from lines of rainbow_text in a while loop\n", "# [ ] print each color capitalized as the loop runs\n", - "\n" + "color = rainbow_file.readline()\n", + "\n", + "while color:\n", + " print(color.strip().capitalize())\n", + "\n", + " color = rainbow_file.readline()\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "# [ ] close rainbow_text \n", - "\n" + "\n", + "rainbow_file.close()" ] }, { @@ -1284,7 +1998,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ @@ -1295,9 +2009,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "\n", + "loops\n", + "\n", + "loops\n", + "\n", + "loops\n", + "\n", + "I repeat\n", + "\n", + "until I\n", + "\n", + "break\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - readline while loop without removing '\\n'\n", "poem_line = poem1.readline()\n", @@ -1318,9 +2053,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loops I repeat\n", + "loops\n", + "loops\n", + "loops\n", + "I repeat\n", + "until I\n", + "break\n" + ] + } + ], "source": [ "# [ ] review and run example - readline with .strip() to remove '\\n'\n", "poem1 = open('poem1.txt', 'r')\n", @@ -1352,24 +2101,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "# [ ] open rainbow.txt as rainbow_text as read-only \n", + "rainbow_file = open(\"rainbow.txt\", \"r\")\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "RED\n", + "ORANGE\n", + "YELLOW\n", + "GREEN\n", + "BLUE\n", + "INDIGO\n", + "VIOLET\n" + ] + } + ], "source": [ "# [ ] read a color from each line of rainbow_text in a while loop \n", "# use .strip to remove the whitespace '\\n' character \n", "# print each color upper case \n", - "\n" + "color = rainbow_file.readline()\n", + "\n", + "while color:\n", + " print(color.strip().upper())\n", + " color = rainbow_file.readline()\n", + "\n", + "rainbow_file.close()\n" ] }, { @@ -1399,9 +2169,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 71 100 71 0 0 292 0 --:--:-- --:--:-- --:--:-- 295\n" + ] + } + ], "source": [ "# [ ] review and run example: import rainbow_messy.txt\n", "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow_messy -o rainbow_messy.txt" @@ -1409,7 +2191,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, "outputs": [], "source": [ @@ -1419,9 +2201,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "**red**\n", + "\n", + "**orange**\n", + "\n", + "**yellow**\n", + "\n", + "**green**\n", + "\n", + "**blue**\n", + "\n", + "**indigo**\n", + "\n", + "**violet**\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example: .readline() without .strip()\n", "\n", @@ -1434,9 +2237,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "red\n", + "orange\n", + "yellow\n", + "green\n", + "blue\n", + "indigo\n", + "violet\n" + ] + } + ], "source": [ "# [ ] review and run example: strip \"*\" and newline ('\\n')\n", "rainbow_messy = open('rainbow_messy.txt', 'r')\n", @@ -1467,29 +2284,78 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 105, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 77 100 77 0 0 689 0 --:--:-- --:--:-- --:--:-- 700\n" + ] + } + ], "source": [ - "# [ ] import the file\n" + "# [ ] import the file\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities_messy -o cities_messy.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='cities_messy.txt' mode='r' encoding='cp1252'>\n", + " Beijing:\n", + "\n" + ] + } + ], "source": [ - "# [ ] run to read the file into memory\n" + "# [ ] run to read the file into memory\n", + "cities_messy_file = open(\"cities_messy.txt\", \"r\")\n", + "print(cities_messy_file)\n", + "\n", + "line = cities_messy_file.readline()\n", + "print(line)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 107, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Beijing\n", + "Cairo\n", + "London\n", + "Nairobi\n", + "New York City\n", + "Sydney\n", + "Tokyo\n" + ] + } + ], "source": [ - "# [ ] edit the code to remove leading or trailing colon, newline and space characters\n" + "# [ ] edit the code to remove leading or trailing colon, newline and space characters\n", + "while line:\n", + "\n", + " cleaned_city = line.strip(\":\\n \")\n", + " print(cleaned_city)\n", + " line = cities_messy_file.readline()\n", + "\n", + "cities_messy_file.close()" ] }, { @@ -1508,34 +2374,82 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 75 100 75 0 0 577 0 --:--:-- --:--:-- --:--:-- 590\n" + ] + } + ], "source": [ "# [ ] import https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem2_messy as poem2_messy.txt \n", - "\n" + "\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem2_messy -o poem2_messy.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 112, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='poem2_messy.txt' mode='r' encoding='cp1252'>\n" + ] + } + ], "source": [ "# [ ] open poem2_messy.txt as poem2_messy in read mode\n", - "\n" + "poem2_messy_file = open(\"poem2_messy.txt\", \"r\")\n", + "print(poem2_messy)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 113, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "while True\n", + "I loop\n", + "True\n", + "loop\n", + "True\n", + "loop\n", + "not True\n", + "False\n", + "end\n" + ] + } + ], "source": [ "# [ ] edit while loop to strip the leading and trailing parentheses, and newlines\n", "# [ ] print the poem \n", "\n", + "line = poem2_messy_file.readline()\n", + "\n", + "while line:\n", + " cleaned_line = line.strip(\"()\\n \")\n", + "\n", + " if cleaned_line:\n", + " print(cleaned_line)\n", + " \n", + " line = poem2_messy_file.readline()\n", "\n", + "poem2_messy_file.close()\n", "\n" ] }, @@ -1596,7 +2510,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 114, "metadata": {}, "outputs": [], "source": [ @@ -1607,9 +2521,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 115, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "77" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example to write some text to the file\n", "new_file.write(\"This is line #1 with 'w'\\nThis is line #2 with 'w'\\nThis is line #3 withn 'w'!\\n\")" @@ -1617,7 +2542,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 116, "metadata": {}, "outputs": [], "source": [ @@ -1630,11 +2555,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 117, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is line #1 with 'w'\n", + "This is line #2 with 'w'\n", + "This is line #3 withn 'w'!\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example to see what was written to the file\n", "new_text = new_file.read()\n", @@ -1672,52 +2608,86 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 122, "metadata": {}, "outputs": [], "source": [ "# [ ] open planets.txt in write mode\n", - "\n" + "\n", + "planets_file = open(\"inner_planets.txt\", 'w')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 123, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] write Mercury, Venus, Earth, Mars on separate lines\n", - "\n" + "\n", + "planets_file.write(\"Mercury\\n\")\n", + "planets_file.write(\"Venus\\n\")\n", + "planets_file.write(\"Earth\\n\")\n", + "planets_file.write(\"Mars\\n\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 124, "metadata": {}, "outputs": [], "source": [ "# [ ] close the file and re-open in read mode\n", - "\n" + "planets_file.close()\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 125, "metadata": {}, "outputs": [], "source": [ "# [ ] use .read() to read the entire file contents\n", - "\n" + "\n", + "planets_file = open(\"inner_planets.txt\", 'r')\n", + "\n", + "file_contents = planets_file.read()\n", + "\n", + "planets_file.close()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 126, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mercury\n", + "Venus\n", + "Earth\n", + "Mars\n", + "\n" + ] + } + ], "source": [ "# [ ] print the entire file contents and close the file\n", - "\n" + "\n", + "print(file_contents)" ] }, { @@ -1748,7 +2718,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 127, "metadata": {}, "outputs": [], "source": [ @@ -1768,9 +2738,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 128, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# [ ] review and run example to see what was written to the file \n", "# - 'w+' overwrites, we can read, but the file is ***BLANK***\n", @@ -1780,9 +2758,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 129, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "52" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run - write to the blank file\n", "new_file.write(\"This is line #1 with 'w+'\\nThis is line #2 with 'w+'\\n\")" @@ -1790,9 +2779,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 130, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# [ ] review and run example - read and print (Note: the pointer is at the end of the file - result = empty string)\n", "new_text = new_file.read()\n", @@ -1818,9 +2815,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example - sets pointer to beginning of file\n", "new_file.seek(0)" @@ -1828,9 +2836,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 132, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is line #1 with 'w+'\n", + "This is line #2 with 'w+'\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - now read starts from beginning of file\n", "new_text = new_file.read()\n", @@ -1839,7 +2857,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 133, "metadata": {}, "outputs": [], "source": [ @@ -1867,43 +2885,77 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 134, "metadata": {}, "outputs": [], "source": [ "# [ ] open outer_planets.txt in write mode 'w+' \n", - "\n" + "\n", + "outer_planets_file = open(\"outer_planets.txt\", 'w+')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 135, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] write four outer planets in earth's solar system (Jupiter, Saturn, Uranus, Neptune) on separate lines\n", - "\n" + "\n", + "outer_planets_file.write(\"Jupiter\\n\")\n", + "outer_planets_file.write(\"Saturn\\n\")\n", + "outer_planets_file.write(\"Uranus\\n\")\n", + "outer_planets_file.write(\"Neptune\\n\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 136, "metadata": {}, "outputs": [], "source": [ "# [ ] use .seek() to move the pointer to the start of the file\n", "# [ ] use .read() to read the entire file contents\n", - "\n" + "\n", + "outer_planets_file.seek(0)\n", + "\n", + "file_contents = outer_planets_file.read()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 137, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Jupiter\n", + "Saturn\n", + "Uranus\n", + "Neptune\n", + "\n" + ] + } + ], "source": [ "# [ ] print the entire file contents and close the file\n", - "\n" + "\n", + "print(file_contents)\n", + "\n", + "outer_planets_file.close()" ] }, { @@ -1960,9 +3012,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 138, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-use simple function and variable names\n", + "-comment code\n", + "-organize code into functions\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run - create, write, read and print a file\n", "tips_file = open('code_tips.txt', 'w+')\n", @@ -1974,9 +3037,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 139, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "unction and variable names\n", + "-comment code\n", + "-organize code into functions\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - setting a specific seek() index \n", "tips_file.seek(13)\n", @@ -1987,9 +3061,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 140, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "unction and variable names\n", + "-comment code\n", + "-organize code into functions\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - string slicing on a read of an entire file\n", "# read from the start\n", @@ -2011,9 +3096,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 141, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-use simple function and variable names\n", + "-comment code\n", + "-organize code into functions\n", + "-use seek(0,2) to set read/write at end of file\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - setting pointer to end of file with whence value = 2\n", "tips_file.seek(0,2)\n", @@ -2027,9 +3124,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 142, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "40" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] review and run example - point to file beginning and overwrite 1st line\n", "tips_file.seek(0)\n", @@ -2038,9 +3146,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 143, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-USE SIMPLE FUNCTION AND VARIABLE NAMES\n", + "-comment code\n", + "-organize code into functions\n", + "-use seek(0,2) to set read/write at end of file\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - show new file contents\n", "tips_file.seek(0,0)\n", @@ -2068,49 +3188,129 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 149, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] open a new file days.txt in write plus read mode 'w+' \n", "# [ ] write week days (Monday - Friday) on separate lines to the file\n", - "\n" + "\n", + "days_file = open(\"days.txt\", 'w+')\n", + "\n", + "days_file.write(\"Monday\\n\")\n", + "days_file.write(\"Tuesday\\n\")\n", + "days_file.write(\"Wednesday\\n\")\n", + "days_file.write(\"Thursday\\n\")\n", + "days_file.write(\"Friday\\n\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 150, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-----Weekdays Only-----\n", + "Monday\n", + "Tuesday\n", + "Wednesday\n", + "Thursday\n", + "Friday\n", + "\n" + ] + } + ], "source": [ "# [ ] use .seek() to move the pointer to the start of the file\n", "# [ ] use .read() to read the entire file contents\n", "# [ ] print the entire file contents and close the file\n", - "\n" + "\n", + "days_file.seek(0)\n", + "\n", + "weekdays_contents = days_file.read()\n", + "\n", + "print(\"-----Weekdays Only-----\")\n", + "print(weekdays_contents)\n", + "\n", + "##days_file.close()\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 151, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# [ ] use .seek() to move the pointer to the end of the file\n", "# [ ] write the weekend days (Saturday & Sunday)\n", + "\n", + "days_file.seek(0,2)\n", + "\n", + "days_file.write(\"saturday\\n\")\n", + "days_file.write(\"sunday\\n\")\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 153, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-----Full Week-----\n", + "Monday\n", + "Tuesday\n", + "Wednesday\n", + "Thursday\n", + "Friday\n", + "saturday\n", + "sunday\n", + "\n" + ] + } + ], "source": [ "# [ ] use .seek() to move the pointer to the start of the file\n", "# [ ] use .read() to read the entire file contents\n", "# [ ] print the entire file contents and close the file\n", "\n", - "\n" + "days_file.seek(0)\n", + "\n", + "full_week_contents = days_file.read()\n", + "\n", + "print(\"-----Full Week-----\")\n", + "\n", + "print(full_week_contents)\n", + "\n", + "days_file.close()\n" ] }, { @@ -2176,7 +3376,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 154, "metadata": {}, "outputs": [], "source": [ @@ -2197,7 +3397,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 155, "metadata": {}, "outputs": [], "source": [ @@ -2209,7 +3409,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 156, "metadata": {}, "outputs": [], "source": [ @@ -2221,9 +3421,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "1: opened file\n", + "2: looked at file\n", + "3: closed file\n", + "\n" + ] + } + ], "source": [ "# [ ] review and run example - calls the above logger() function\n", "# what happens running the cell above (a+) again before running this cell again? \n", @@ -2250,9 +3462,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 158, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Count is: 0\n" + ] + } + ], "source": [ "# [ ] review and run example - create a file with initial count of 0\n", "count_file = open(\"count_file.txt\", \"w+\")\n", @@ -2266,9 +3486,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 160, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "BEFORE\n", + "Count is: 1\n", + "\n", + "AFTER\n", + "Count is: 2\n" + ] + } + ], "source": [ "# [ ] review and run example - can rerun this cell\n", "count_file = open(\"count_file.txt\", \"r+\")\n", @@ -2292,7 +3524,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 162, "metadata": {}, "outputs": [], "source": [ @@ -2309,9 +3541,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 163, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "BEFORE\n", + "Count is: 2\n", + "\n", + "AFTER inc_count() call 1 \n", + "Count is: 3\n", + "\n", + "AFTER inc_count() call 2 \n", + "Count is: 4\n", + "\n", + "AFTER inc_count() call 3 \n", + "Count is: 5\n", + "\n", + "AFTER inc_count() call 4 \n", + "Count is: 6\n", + "\n", + "AFTER inc_count() call 5 \n", + "Count is: 7\n" + ] + } + ], "source": [ "# [ ] review and run example with call to function: inc_count() - **Run cell multiple times**\n", "# opens file/prints initial value\n", @@ -2350,16 +3606,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 165, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Line1\n", + "Line2\n", + "Line3\n", + "append #0\n", + "append #1\n", + "append #2\n", + "append #3\n", + "append #4\n", + "\n" + ] + } + ], "source": [ "# [ ] complete the task\n", "# Provided Code creates and populates task4_file.txt\n", "task4_file = open('task4_file.txt', 'w+')\n", "task4_file.write(\"Line1\\nLine2\\nLine3\\n\")\n", "task4_file.close()\n", - "# [ ] code here\n" + "# [ ] code here\n", + "task4_file = open('task4_file.txt', 'a+')\n", + "\n", + "for item in range(5):\n", + " task4_file.write(\"append #\" + str(item) + \"\\n\")\n", + " task4_file.seek(0)\n", + "\n", + "print(task4_file.read())\n", + "\n", + "task4_file.close()\n" ] }, { @@ -2385,9 +3666,41 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Before:\n", + "Line---1\n", + "Line---2\n", + "Line---3\n", + "Line---4\n", + "Line---5\n", + "Line---6\n", + "Line---7\n", + "Line---8\n", + "Line---9\n", + "Line--10\n", + "\n", + "\n", + "After:\n", + "Line---1\n", + "Line---2append#1\n", + "\n", + "Line--append#2\n", + "-5\n", + "Lineappend#3\n", + "---7\n", + "Liappend#4\n", + "ne---9\n", + "Line--10\n", + "\n" + ] + } + ], "source": [ "# [ ] complete the task\n", "# Provided Code creates and populates task5_file.txt\n", @@ -2399,7 +3712,19 @@ "\n", "# [ ] code here\n", "\n", + "task5_file = open('task5_file.txt', 'r+')\n", + "\n", + "for item in range(1, 5):\n", + "\n", + " task5_file.seek(item * 18)\n", "\n", + " task5_file.write(\"append#\" + str(item) + \"\\n\")\n", + "\n", + "task5_file.seek(0)\n", + "\n", + "print(\"After:\\n\" + task5_file.read())\n", + "\n", + "task5_file.close()\n", "\n" ] }, @@ -2437,7 +3762,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_4.1_Practice_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_4.1_Practice_Python_Fundamentals.ipynb index d47d3f48..3831e68d 100644 --- a/P2 Python Fundamentals/Module_4.1_Practice_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_4.1_Practice_Python_Fundamentals.ipynb @@ -41,12 +41,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 43 100 43 0 0 294 0 --:--:-- --:--:-- --:--:-- 298\n" + ] + } + ], "source": [ "# [ ] import https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow as rainbow.txt\n", - "\n" + "\n", + "!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/rainbow -o rainbow.txt" ] }, { @@ -59,13 +72,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# [ ] Open rainbow.txt in read mode & read as list with .readlines()\n", "\n", - "\n" + "rainbow_file = open(\"rainbow.txt\", 'r')\n", + "rainbow_colors = rainbow_file.readlines()\n", + "rainbow_file.close()\n", + "\n", + "rainbow_colors = [color.strip() for color in rainbow_colors]\n" ] }, { @@ -80,12 +97,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "blue\n", + "green\n", + "indigo\n", + "orange\n", + "red\n", + "violet\n", + "yellow\n" + ] + } + ], "source": [ "# [ ] sort rainbow_colors list, iterate the list to print each color\n", - "\n" + "\n", + "rainbow_colors.sort()\n", + "\n", + "\n", + "for color in rainbow_colors:\n", + " print(color)" ] }, { @@ -107,12 +143,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 222 100 222 0 0 1519 0 --:--:-- --:--:-- --:--:-- 1541\n" + ] + } + ], "source": [ "# [ ] The Weather: import world_mean_team.csv as mean_temp.txt\n", - "\n" + "\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt" ] }, { @@ -126,12 +175,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original Heading Line: city,country,month ave: highest high,month ave: lowest low\n", + "Headings List: ['city', 'country', 'month ave: highest high', 'month ave: lowest low']\n" + ] + } + ], "source": [ "# [ ] The Weather: open file, read/print first line, convert line to list (splitting on comma)\n", - "\n" + "\n", + "mean_temps_file = open(\"mean_temp.txt\", 'r')\n", + "\n", + "headings = mean_temps_file.readline()\n", + "print(f\"Original Heading Line: {headings.strip()}\")\n", + "\n", + "headings_list = headings.strip().split(',')\n", + "print(f\"Headings List: {headings_list}\")" ] }, { @@ -152,12 +217,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The highest monthly average high in Beijing is -8.4 Celsius.\n", + "The highest monthly average high in Cairo is 1.2 Celsius.\n", + "The highest monthly average high in London is 2.1 Celsius.\n", + "The highest monthly average high in Nairobi is 10.5 Celsius.\n", + "The highest monthly average high in New York City is -2.8 Celsius.\n", + "The highest monthly average high in Sydney is 8.7 Celsius.\n", + "The highest monthly average high in Tokyo is 0.9 Celsius.\n" + ] + } + ], "source": [ "# [ ] The Weather: use while loop to print city and highest monthly average temp in celsius\n", - "\n" + "\n", + "city_temp_line = mean_temps_file.readline()\n", + "\n", + "while city_temp_line:\n", + "\n", + " city_temp_list = city_temp_line.strip().split(',')\n", + " \n", + "\n", + " if len(city_temp_list) > 3:\n", + "\n", + " city_name = city_temp_list[0]\n", + " highest_avg_temp = city_temp_list[3]\n", + " print(f\"The highest monthly average high in {city_name} is {highest_avg_temp} Celsius.\")\n", + " \n", + " city_temp_line = mean_temps_file.readline()\n", + "\n", + "\n", + "mean_temps_file.close()" ] }, { @@ -178,12 +274,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 303 100 303 0 0 3738 0 --:--:-- --:--:-- --:--:-- 3787\n" + ] + } + ], "source": [ "# [ ] use curl to download https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi as pi.txt\n", - "\n" + "\n", + "! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/digits_of_pi -o pi.txt" ] }, { @@ -202,12 +311,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi, Ben!\n" + ] + } + ], "source": [ "# [ ] Set up the project files and initial values\n", - "\n" + "\n", + "\n", + "pi_file = open(\"pi.txt\", 'r')\n", + "\n", + "name = input(\"Enter your name: \")\n", + "print(f\"Hi, {name}!\")\n", + "\n", + "seed = len(name)\n", + "\n", + "pi_file.seek(seed)\n", + "\n", + "digit = pi_file.read(1)\n", + "\n", + "guess = input('Enter a single digit guess or \"q\" to quit: ')\n", + "\n", + "correct = 0\n", + "wrong = 0" ] }, { @@ -229,11 +362,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "incorrect\n", + "correct\n", + "\n", + "Game Over! You got 1 correct and 1 incorrect guesses.\n" + ] + } + ], "source": [ - "\n" + "\n", + "\n", + "\n", + "while guess.isdigit():\n", + " \n", + " if digit == '.':\n", + " digit = pi_file.read(1)\n", + " continue\n", + " \n", + "\n", + " elif digit == '\\n':\n", + " seed += 1\n", + "\n", + " pi_file.seek(seed) \n", + " digit = pi_file.read(1)\n", + " continue\n", + " \n", + " else:\n", + " if guess == digit:\n", + " print(\"correct\")\n", + " correct += 1\n", + " else:\n", + " print(\"incorrect\")\n", + " wrong += 1\n", + " \n", + " digit = pi_file.read(1)\n", + " guess = input('Enter a single digit guess or \"q\" to quit: ')\n", + "\n", + "print(f\"\\nGame Over! You got {correct} correct and {wrong} incorrect guesses.\")\n", + "\n", + "pi_file.close()" ] }, { @@ -272,7 +446,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_4.2_Required_Code_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_4.2_Required_Code_Python_Fundamentals.ipynb index 35ee8efb..4d31928f 100644 --- a/P2 Python Fundamentals/Module_4.2_Required_Code_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_4.2_Required_Code_Python_Fundamentals.ipynb @@ -91,16 +91,61 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ben Reed\n", + "City of Beijing month ave: Highest high is -8.4 Celsius\n", + "City of Cairo month ave: Highest high is 1.2 Celsius\n", + "City of London month ave: Highest high is 2.1 Celsius\n", + "City of Nairobi month ave: Highest high is 10.5 Celsius\n", + "City of New York City month ave: Highest high is -2.8 Celsius\n", + "City of Sydney month ave: Highest high is 8.7 Celsius\n", + "City of Tokyo month ave: Highest high is 0.9 Celsius\n", + "City of RIO de Janeiro month ave: Highest high is 18.0 Celsius\n", + "City of RIO de Janeiro month ave: Highest high is 18.0 Celsius\n" + ] + } + ], "source": [ "# [] create The Weather\n", "\n", + "##! curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt\n", "\n", - "\n" + "mean_temps_file = open('mean_temp.txt', 'a+')\n", + "mean_temps_file.write(\"RIO de Janeiro, Brazil, 30.0,18.0\\n\")\n", + "\n", + "mean_temps_file.seek(0)\n", + "\n", + "headings = mean_temps_file.readline()\n", + "\n", + "headings_list = headings.strip().split(',')\n", + "\n", + "##print(headings_list)\n", + "\n", + "my_name = \"Ben Reed\"\n", + "\n", + "print(my_name)\n", + "\n", + "city_temp_line = mean_temps_file.readline()\n", + "\n", + "while city_temp_line:\n", + " city_temp_list = city_temp_line.strip().split(',')\n", + "\n", + " if len(city_temp_list) > 3:\n", + " city_name = city_temp_list[0]\n", + " highest_avg_temp = city_temp_list[3]\n", + "\n", + " print(f\"City of {city_name} month ave: Highest high is {highest_avg_temp} Celsius\")\n", + " city_temp_line = mean_temps_file.readline()\n", + "\n", + "mean_temps_file.close()\n" ] }, { @@ -128,7 +173,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2 Python Fundamentals/Module_5.0_Required_FINAL_Project_Python_Fundamentals.ipynb b/P2 Python Fundamentals/Module_5.0_Required_FINAL_Project_Python_Fundamentals.ipynb index 42d507e6..3147ac31 100644 --- a/P2 Python Fundamentals/Module_5.0_Required_FINAL_Project_Python_Fundamentals.ipynb +++ b/P2 Python Fundamentals/Module_5.0_Required_FINAL_Project_Python_Fundamentals.ipynb @@ -83,14 +83,104 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": { "collapsed": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome Ben Reed, list any 5 of the first 20 elements in the Periodic Table: \n", + "\n", + "><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><\n", + "60 % correct\n", + "Found: Helium, Sodium, Silicon\n", + "Not Found: Zenon, Hyrdrogen\n", + "><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><\n" + ] + } + ], "source": [ "# [] create Element_Quiz\n", "\n", + "##Download the data file for elements1_20.txt\n", + "!curl -s -O https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/elements1_20.txt\n", + "\n", + "def get_names(): ## creates a function that gets the person's name, and gets input for the name of the element.\n", + " ## If the input is empty, it says space not allowed.\n", + " ## if it is a duplicate, it says no duplicates.\n", + " ## If it is a new input, it appemd it to the input_names list.\n", + "\n", + " input_names = []\n", + "\n", + " while len(input_names) < 5:\n", + " name = input(\"Enter the name of an element: \").lower().strip()\n", + "\n", + " if name == \"\":\n", + " print(\"Empty Space Not Allowed\")\n", + "\n", + " elif name in input_names:\n", + "\n", + " print(f\"{name} was already entered <--- no duplicates allowed\")\n", + "\n", + " else:\n", + " input_names.append(name)\n", + "\n", + " return input_names\n", + "\n", + "## The program welcomes the user and asks for 5 elements.\n", + "your_name = input(\"Please enter your full name: \")\n", + "print(f\"Welcome {your_name}, list any 5 of the first 20 elements in the Periodic Table: \")\n", + "\n", + "first_20_elements = []\n", + "\n", + "try: ## The program opens elements1_20.txt and reads one line at a time.\n", + " ## The program also removes any whitespace, makes it lowercase, and appends to the first_20_elements list.\n", + "\n", + " elements_file = open('elements1_20.txt', 'r')\n", + "\n", + " for line in elements_file:\n", + "\n", + " first_20_elements.append(line.strip().lower())\n", + "\n", + " elements_file.close()\n", + "\n", + "except FileNotFoundError: ## The code will exit the program and notify of the elements1_20.txt file was not found.\n", + " print(\"Error: The file 'elements1_20.txt' was not found.\")\n", + " exit()\n", + "\n", + "quiz_reponses = get_names() ## Call the get_names function.\n", + "correct_responses = [] ## Makes a list of correct responses.\n", + "incorrect_responses = [] ## Makes a list of incorrect repsonses.\n", + "\n", + "for response in quiz_reponses: ## Now we iterate through the 5 reponses from the user input.\n", + " ## It comparess each response to the list of 20 elements.\n", + " if response in first_20_elements:\n", + " ## If correct, the input is appended to the correct_response list.\n", + " correct_responses.append(response)\n", + "\n", + " else: ## if the input is incorrect, it appends it to the incorrect_response list.\n", + " incorrect_responses.append(response)\n", + "\n", + "percent_correct = len(correct_responses) * 20 ## the list of correct_reponse times 20 gives the percent correct.\n", + "percent_correct = int(percent_correct) ##turns percent correct into an int.\n", + "\n", + "print(\"\\n\" + \"><\"*30)\n", + "print(f\"{percent_correct} % correct\")\n", + "\n", + "found_list = [name.title() for name in correct_responses] ## turns correct responses into Title form for printing.\n", + "\n", + "print(\"Found: \", end=\"\")\n", + "print(', '.join(found_list)) ## Joins the found_list into a single string with spaces betweem.\n", + "\n", + "not_found_list = [name.title() for name in incorrect_responses]## turns incorrect responses into Title form for printing.\n", + "print(\"Not Found: \", end=\"\")\n", + "print(\", \".join(not_found_list)) ## Joins the found_list into a single string with spaces betweem.\n", + "\n", + "print(\"><\"*30)\n", + "\n", "\n", "\n" ] @@ -120,7 +210,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.13.7" } }, "nbformat": 4, diff --git a/P2M1BenjaminReed.py b/P2M1BenjaminReed.py new file mode 100644 index 00000000..b46f692b --- /dev/null +++ b/P2M1BenjaminReed.py @@ -0,0 +1,22 @@ +# [] create words after "G" following the Assignment requirements use of functions, methods and keywords +# Sample quote: "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC) + +def word_after_g(): + + quote = input("Welcome, Ben Reed. Enter a 1 sentence quote, non_alpha seperate words: ") + word = "" + + for character in quote: + if character.isalpha(): + word += character + else: + if word: + if word[0].lower() > "g": + print(word.upper()) + word = "" + + if word: + if word[0].lower() >"g": + print(word.upper()) + +word_after_g() \ No newline at end of file diff --git a/P2M2BenjaminReed.py b/P2M2BenjaminReed.py new file mode 100644 index 00000000..6ca768e5 --- /dev/null +++ b/P2M2BenjaminReed.py @@ -0,0 +1,45 @@ + + + + +def list_o_matic(item_list, item_string): + + if item_string == "": + + if item_list: + popped_item = item_list.pop() + return f"{popped_item} popped from list" + else: + return "List is already empty." + + elif item_string in item_list: + + item_list.remove(item_string) + return f"1 instance of {item_string} removed from list." + + else: + + item_list.append(item_string) + return f"1 instance of {item_string} appended to list." + +colors_list = ['red','orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'magenta'] +program_name = "colors" +my_name = "Benjamin Reed" + +while True: + + if not colors_list: + print("Goodbye") + break + + print(f"\nWelcome, {my_name}. Look at all the {program_name} {colors_list}") + + color_input = input(f"Enter a color: ") + + if color_input == "quit": + print("Goodbye!") + break + + message = list_o_matic(colors_list, color_input) + + print(message) \ No newline at end of file diff --git a/P2M3BenjaminReed.py b/P2M3BenjaminReed.py new file mode 100644 index 00000000..116331ad --- /dev/null +++ b/P2M3BenjaminReed.py @@ -0,0 +1,41 @@ + + +# [] create poem mixer function, call the function with the provided test string +# [] test string: `Little fly, Thy summer’s play My thoughtless hand Has brushed away. Am not I A fly like thee? Or art not thou A man like me?` + +def word_mixer(original_list): + original_list.sort() + + new_words = [] + + while len(original_list) > 5: + new_words.append(original_list.pop(-5)) + + new_words.append(original_list.pop(0)) + + new_words.append(original_list.pop(-1)) + + return new_words + +poem_input = input("Welcome Ben Reed, enter a saying or peom: ") + +word_list = poem_input.split() + +list_length = len(word_list) + +for word_string in range(list_length): + word = word_list[word_string] + word_length = len(word) + + if word_length <= 3: + word_list[word_string] = word.lower() + + elif word_length >= 7: + word_list[word_string] = word.upper() + + +mixed_words_list = word_mixer(word_list) + +print(" ".join(mixed_words_list)) + + diff --git a/P2M4BenjaminReed.py b/P2M4BenjaminReed.py new file mode 100644 index 00000000..60dc359f --- /dev/null +++ b/P2M4BenjaminReed.py @@ -0,0 +1,34 @@ +# [] create The Weather + +import os + +os.system("curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt") + +mean_temps_file = open('mean_temp.txt', 'a+') +mean_temps_file.write("RIO de Janeiro, Brazil, 30.0,18.0\n") + +mean_temps_file.seek(0) + +headings = mean_temps_file.readline() + +headings_list = headings.strip().split(',') + +##print(headings_list) + +my_name = "Ben Reed" + +print(my_name) + +city_temp_line = mean_temps_file.readline() + +while city_temp_line: + city_temp_list = city_temp_line.strip().split(',') + + if len(city_temp_list) > 3: + city_name = city_temp_list[0] + highest_avg_temp = city_temp_list[3] + + print(f"City of {city_name} month ave: Highest high is {highest_avg_temp} Celsius") + city_temp_line = mean_temps_file.readline() + +mean_temps_file.close() diff --git a/P2M5BenjaminReed.py b/P2M5BenjaminReed.py new file mode 100644 index 00000000..d3a402b9 --- /dev/null +++ b/P2M5BenjaminReed.py @@ -0,0 +1,92 @@ +# [] create Element_Quiz + +##Download the data file for elements1_20.txt +import os + +os.system ("curl -s -O https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/elements1_20.txt") + +def get_names(): ## creates a function that gets the person's name, and gets input for the name of the element. + ## If the input is empty, it says space not allowed. + ## if it is a duplicate, it says no duplicates. + ## If it is a new input, it appemd it to the input_names list. + + input_names = [] + + while len(input_names) < 5: + name = input("Enter the name of an element: ").lower().strip() + + if name == "": + print("Empty Space Not Allowed") + + elif name in input_names: + + print(f"{name} was already entered <--- no duplicates allowed") + + else: + input_names.append(name) + + return input_names + +## The program welcomes the user and asks for 5 elements. +your_name = input("Please enter your full name: ") +print(f"Welcome {your_name}, list any 5 of the first 20 elements in the Periodic Table: ") + +first_20_elements = [] + +try: ## The program opens elements1_20.txt and reads one line at a time. + ## The program also removes any whitespace, makes it lowercase, and appends to the first_20_elements list. + + elements_file = open('elements1_20.txt', 'r') + + for line in elements_file: + + first_20_elements.append(line.strip().lower()) + + elements_file.close() + +except FileNotFoundError: ## The code will exit the program and notify of the elements1_20.txt file was not found. + print("Error: The file 'elements1_20.txt' was not found.") + exit() + +quiz_reponses = get_names() ## Call the get_names function. +correct_responses = [] ## Makes a list of correct responses. +incorrect_responses = [] ## Makes a list of incorrect repsonses. + +for response in quiz_reponses: ## Now we iterate through the 5 reponses from the user input. + ## It comparess each response to the list of 20 elements. + if response in first_20_elements: + ## If correct, the input is appended to the correct_response list. + correct_responses.append(response) + + else: ## if the input is incorrect, it appends it to the incorrect_response list. + incorrect_responses.append(response) + +percent_correct = len(correct_responses) * 20 ## the list of correct_reponse times 20 gives the percent correct. +percent_correct = int(percent_correct) ##turns percent correct into an int. + +BOLD = '\033[1m' ## makes text bold +RED = '\033[91m' ## Specifies the color red. +ENDC = '\033[0m' ## Specifies the normal color. +B_GREEN = '\033[42m' + +if percent_correct < 70: ##If the user scores less than 70%, the putput is red. + COLOR = RED + +else: + COLOR = ENDC + +print("\n" + "<>"*30) +print() +print(f"{COLOR}{BOLD}{percent_correct} % correct{ENDC}") + +found_list = [f"{B_GREEN}{BOLD}{name.title()}{ENDC}" for name in correct_responses] ## turns correct responses into Title form for printing. + +print("Found: ", end="") +print(', '.join(found_list)) ## Joins the found_list into a single string with spaces betweem. + +not_found_list = [name.title() for name in incorrect_responses]## turns incorrect responses into Title form for printing. +print("Not Found: ", end="") +print(", ".join(not_found_list)) ## Joins the found_list into a single string with spaces betweem. + +print() +print("<>"*30) \ No newline at end of file diff --git a/Python Intro to Pandas.ipynb b/Python Intro to Pandas.ipynb new file mode 100644 index 00000000..d19c2ced --- /dev/null +++ b/Python Intro to Pandas.ipynb @@ -0,0 +1,2932 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "57d270e7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: pandas in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (2.3.3)\n", + "Requirement already satisfied: numpy>=1.26.0 in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from pandas) (2.3.4)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\benjamin.reed\\appdata\\roaming\\python\\python313\\site-packages (from pandas) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from pandas) (2025.2)\n", + "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from pandas) (2025.2)\n", + "Requirement already satisfied: six>=1.5 in c:\\users\\benjamin.reed\\appdata\\roaming\\python\\python313\\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3d285a9b", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "import pandas as pd #import the pandas package\n", + "import os " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "38874ba8", + "metadata": {}, + "outputs": [], + "source": [ + "fileName='Baby_Names.csv'\n", + "filePath=r'C:\\Users\\benjamin.reed\\Downloads'\n", + "file=os.path.join(filePath,fileName) #create a file reference for the file you want to import" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "81085702", + "metadata": {}, + "outputs": [], + "source": [ + "df=pd.read_csv(file) #read the csv file into a pandas dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "9054d31e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['state', 'gender', 'year', 'name', 'number'], dtype='object')" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns #display the columns" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4817e8bc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1032683, 5)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.shape #display the shape, rows and columns" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "bc2bbf13", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
0AKF2010Sophia62
1AKF2010Emma51
2AKF2010Isabella51
3AKF2010Olivia44
4AKF2010Ava33
\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "0 AK F 2010 Sophia 62\n", + "1 AK F 2010 Emma 51\n", + "2 AK F 2010 Isabella 51\n", + "3 AK F 2010 Olivia 44\n", + "4 AK F 2010 Ava 33" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head(5) #show first 5 records" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f03f51c0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
41729CAF2012Sophia3644
37735CAF2011Sophia3569
45830CAF2013Sophia3468
33638CAF2010Isabella3370
33639CAF2010Sophia3361
\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "41729 CA F 2012 Sophia 3644\n", + "37735 CA F 2011 Sophia 3569\n", + "45830 CA F 2013 Sophia 3468\n", + "33638 CA F 2010 Isabella 3370\n", + "33639 CA F 2010 Sophia 3361" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.nlargest(5,'number') #show largest 5 records for column 'number'" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "229e30bc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
175AKF2010Alayna5
176AKF2010Alicia5
177AKF2010Aliyah5
178AKF2010Amber5
179AKF2010Andrea5
\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "175 AK F 2010 Alayna 5\n", + "176 AK F 2010 Alicia 5\n", + "177 AK F 2010 Aliyah 5\n", + "178 AK F 2010 Amber 5\n", + "179 AK F 2010 Andrea 5" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.nsmallest(5,'number') #show smallest 5 records for column 'number'" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "d3eda148", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1032683, 5)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.shape #rows,columns" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "cb6bf3ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['state', 'gender', 'year', 'name', 'number'], dtype='object')" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns #list the column names" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "70192f41", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "state object\n", + "gender object\n", + "year int64\n", + "name object\n", + "number int64\n", + "dtype: object" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.dtypes #list the datatypes" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "792ad3f7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
yearnumber
count1.032683e+061.032683e+06
mean2.015006e+033.231653e+01
std3.151887e+008.475111e+01
min2.010000e+035.000000e+00
25%2.012000e+037.000000e+00
50%2.015000e+031.100000e+01
75%2.018000e+032.500000e+01
max2.020000e+033.644000e+03
\n", + "
" + ], + "text/plain": [ + " year number\n", + "count 1.032683e+06 1.032683e+06\n", + "mean 2.015006e+03 3.231653e+01\n", + "std 3.151887e+00 8.475111e+01\n", + "min 2.010000e+03 5.000000e+00\n", + "25% 2.012000e+03 7.000000e+00\n", + "50% 2.015000e+03 1.100000e+01\n", + "75% 2.018000e+03 2.500000e+01\n", + "max 2.020000e+03 3.644000e+03" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.describe() #get the stats for all numeric fields" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "e9fbce12", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
0AKF2010Sophia62
1AKF2010Emma51
2AKF2010Isabella51
3AKF2010Olivia44
4AKF2010Ava33
..................
1032678WYM2020Simon5
1032679WYM2020Sterling5
1032680WYM2020Stetson5
1032681WYM2020Timothy5
1032682WYM2020Wesley5
\n", + "

1032683 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "0 AK F 2010 Sophia 62\n", + "1 AK F 2010 Emma 51\n", + "2 AK F 2010 Isabella 51\n", + "3 AK F 2010 Olivia 44\n", + "4 AK F 2010 Ava 33\n", + "... ... ... ... ... ...\n", + "1032678 WY M 2020 Simon 5\n", + "1032679 WY M 2020 Sterling 5\n", + "1032680 WY M 2020 Stetson 5\n", + "1032681 WY M 2020 Timothy 5\n", + "1032682 WY M 2020 Wesley 5\n", + "\n", + "[1032683 rows x 5 columns]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "944eb35e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "year\n", + "2016 95357\n", + "2015 95214\n", + "2014 94782\n", + "2017 94449\n", + "2018 94060\n", + "2019 93961\n", + "2010 93424\n", + "2012 93237\n", + "2013 93052\n", + "2011 92707\n", + "2020 92440\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['year'].value_counts() #get the number of rows for each value" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "0c347930", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 2010\n", + "1 2010\n", + "2 2010\n", + "3 2010\n", + "4 2010\n", + " ... \n", + "1032678 2020\n", + "1032679 2020\n", + "1032680 2020\n", + "1032681 2020\n", + "1032682 2020\n", + "Name: year, Length: 1032683, dtype: int64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['year'] #return a single column from the dataframe, this is refered to as a 'series'" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "03c8a1f1", + "metadata": {}, + "outputs": [], + "source": [ + "years=df['year'].tolist() #create a list of all the years in the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "c2dfe256", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2010,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2011,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2012,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2013,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " 2014,\n", + " ...]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "years" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "65e09d95", + "metadata": {}, + "outputs": [], + "source": [ + "years=df['year'].drop_duplicates().tolist() #drop the duplicates and then put in a list" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "0b5aff21", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 2010\n", + "1 2011\n", + "2 2012\n", + "3 2013\n", + "4 2014\n", + "5 2015\n", + "6 2016\n", + "7 2017\n", + "8 2018\n", + "9 2019\n", + "10 2020\n" + ] + } + ], + "source": [ + "for i,y in enumerate(years):\n", + " print(i,y)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "c27a0744", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
0AKF2010Sophia62
1AKF2010Emma51
2AKF2010Isabella51
3AKF2010Olivia44
4AKF2010Ava33
..................
1032678WYM2020Simon5
1032679WYM2020Sterling5
1032680WYM2020Stetson5
1032681WYM2020Timothy5
1032682WYM2020Wesley5
\n", + "

1032683 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "0 AK F 2010 Sophia 62\n", + "1 AK F 2010 Emma 51\n", + "2 AK F 2010 Isabella 51\n", + "3 AK F 2010 Olivia 44\n", + "4 AK F 2010 Ava 33\n", + "... ... ... ... ... ...\n", + "1032678 WY M 2020 Simon 5\n", + "1032679 WY M 2020 Sterling 5\n", + "1032680 WY M 2020 Stetson 5\n", + "1032681 WY M 2020 Timothy 5\n", + "1032682 WY M 2020 Wesley 5\n", + "\n", + "[1032683 rows x 5 columns]" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "41b62d4f", + "metadata": {}, + "outputs": [], + "source": [ + "#here is a dictionary that maps state abbreviations to state names\n", + "states = {\n", + " 'AK': 'Alaska',\n", + " 'AL': 'Alabama',\n", + " 'AR': 'Arkansas',\n", + " 'AZ': 'Arizona',\n", + " 'CA': 'California',\n", + " 'CO': 'Colorado',\n", + " 'CT': 'Connecticut',\n", + " 'DC': 'District of Columbia',\n", + " 'DE': 'Delaware',\n", + " 'FL': 'Florida',\n", + " 'GA': 'Georgia',\n", + " 'HI': 'Hawaii',\n", + " 'IA': 'Iowa',\n", + " 'ID': 'Idaho',\n", + " 'IL': 'Illinois',\n", + " 'IN': 'Indiana',\n", + " 'KS': 'Kansas',\n", + " 'KY': 'Kentucky',\n", + " 'LA': 'Louisiana',\n", + " 'MA': 'Massachusetts',\n", + " 'MD': 'Maryland',\n", + " 'ME': 'Maine',\n", + " 'MI': 'Michigan',\n", + " 'MN': 'Minnesota',\n", + " 'MO': 'Missouri',\n", + " 'MS': 'Mississippi',\n", + " 'MT': 'Montana',\n", + " 'NC': 'North Carolina',\n", + " 'ND': 'North Dakota',\n", + " 'NE': 'Nebraska',\n", + " 'NH': 'New Hampshire',\n", + " 'NJ': 'New Jersey',\n", + " 'NM': 'New Mexico',\n", + " 'NV': 'Nevada',\n", + " 'NY': 'New York',\n", + " 'OH': 'Ohio',\n", + " 'OK': 'Oklahoma',\n", + " 'OR': 'Oregon',\n", + " 'PA': 'Pennsylvania',\n", + " 'RI': 'Rhode Island',\n", + " 'SC': 'South Carolina',\n", + " 'SD': 'South Dakota',\n", + " 'TN': 'Tennessee',\n", + " 'TX': 'Texas',\n", + " 'UT': 'Utah',\n", + " 'VA': 'Virginia',\n", + " 'VT': 'Vermont',\n", + " 'WA': 'Washington',\n", + " 'WI': 'Wisconsin',\n", + " 'WV': 'West Virginia',\n", + " 'WY': 'Wyoming'\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "04140052", + "metadata": {}, + "outputs": [], + "source": [ + "df['state']=df['state'].map(states) #replace the abbreviation with the full name in the 'state' column" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "e6a43188", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
0AlaskaF2010Sophia62
1AlaskaF2010Emma51
2AlaskaF2010Isabella51
3AlaskaF2010Olivia44
4AlaskaF2010Ava33
..................
1032678WyomingM2020Simon5
1032679WyomingM2020Sterling5
1032680WyomingM2020Stetson5
1032681WyomingM2020Timothy5
1032682WyomingM2020Wesley5
\n", + "

1032683 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "0 Alaska F 2010 Sophia 62\n", + "1 Alaska F 2010 Emma 51\n", + "2 Alaska F 2010 Isabella 51\n", + "3 Alaska F 2010 Olivia 44\n", + "4 Alaska F 2010 Ava 33\n", + "... ... ... ... ... ...\n", + "1032678 Wyoming M 2020 Simon 5\n", + "1032679 Wyoming M 2020 Sterling 5\n", + "1032680 Wyoming M 2020 Stetson 5\n", + "1032681 Wyoming M 2020 Timothy 5\n", + "1032682 Wyoming M 2020 Wesley 5\n", + "\n", + "[1032683 rows x 5 columns]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "385b7188", + "metadata": {}, + "outputs": [], + "source": [ + "df['gender']=df['gender'].map({'F' : 'FEMALE','M' : 'MALE'}) #update the gender column" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "3e80b4a1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "gender\n", + "FEMALE 558670\n", + "MALE 474013\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['gender'].value_counts()" + ] + }, + { + "cell_type": "markdown", + "id": "f98257f6", + "metadata": {}, + "source": [ + "Filtering" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "fb1c6dc4", + "metadata": {}, + "outputs": [], + "source": [ + "df_female=df.query(\"gender=='FEMALE'\") #filter on FEMALE" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "b6599745", + "metadata": {}, + "outputs": [], + "source": [ + "df_female=df.query(\"gender=='FEMALE' and state=='Georgia'\") #filter on FEMALE and Georgia" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "28383c29", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
125950GeorgiaFEMALE2010Isabella570
125951GeorgiaFEMALE2010Madison525
125952GeorgiaFEMALE2010Emma522
125953GeorgiaFEMALE2010Abigail463
125954GeorgiaFEMALE2010Olivia458
..................
145025GeorgiaFEMALE2020Zenobia5
145026GeorgiaFEMALE2020Zori5
145027GeorgiaFEMALE2020Zoriah5
145028GeorgiaFEMALE2020Zyla5
145029GeorgiaFEMALE2020Zylah5
\n", + "

19080 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "125950 Georgia FEMALE 2010 Isabella 570\n", + "125951 Georgia FEMALE 2010 Madison 525\n", + "125952 Georgia FEMALE 2010 Emma 522\n", + "125953 Georgia FEMALE 2010 Abigail 463\n", + "125954 Georgia FEMALE 2010 Olivia 458\n", + "... ... ... ... ... ...\n", + "145025 Georgia FEMALE 2020 Zenobia 5\n", + "145026 Georgia FEMALE 2020 Zori 5\n", + "145027 Georgia FEMALE 2020 Zoriah 5\n", + "145028 Georgia FEMALE 2020 Zyla 5\n", + "145029 Georgia FEMALE 2020 Zylah 5\n", + "\n", + "[19080 rows x 5 columns]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_female" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "3e36eabc", + "metadata": {}, + "outputs": [], + "source": [ + "df['state']=df['state'].apply(lambda x : x.upper()) #convert state values to uppercase" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "53692ff6", + "metadata": {}, + "outputs": [], + "source": [ + "df.sort_values(by=['state','gender','name'],inplace=True) #sort the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "2a32b3e6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stategenderyearnamenumber
2398ALABAMAFEMALE2010Aaliyah70
3303ALABAMAFEMALE2011Aaliyah88
4235ALABAMAFEMALE2012Aaliyah64
5081ALABAMAFEMALE2013Aaliyah83
5966ALABAMAFEMALE2014Aaliyah86
..................
1031948WYOMINGMALE2015Zayden6
1032081WYOMINGMALE2016Zayden7
1032212WYOMINGMALE2017Zayden8
1032337WYOMINGMALE2018Zayden9
1031428WYOMINGMALE2012Zayne5
\n", + "

1032683 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " state gender year name number\n", + "2398 ALABAMA FEMALE 2010 Aaliyah 70\n", + "3303 ALABAMA FEMALE 2011 Aaliyah 88\n", + "4235 ALABAMA FEMALE 2012 Aaliyah 64\n", + "5081 ALABAMA FEMALE 2013 Aaliyah 83\n", + "5966 ALABAMA FEMALE 2014 Aaliyah 86\n", + "... ... ... ... ... ...\n", + "1031948 WYOMING MALE 2015 Zayden 6\n", + "1032081 WYOMING MALE 2016 Zayden 7\n", + "1032212 WYOMING MALE 2017 Zayden 8\n", + "1032337 WYOMING MALE 2018 Zayden 9\n", + "1031428 WYOMING MALE 2012 Zayne 5\n", + "\n", + "[1032683 rows x 5 columns]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "0e2d4809", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: openpyxl in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (3.1.5)\n", + "Requirement already satisfied: et-xmlfile in c:\\users\\benjamin.reed\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from openpyxl) (2.0.0)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install openpyxl" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "37dc22c2", + "metadata": {}, + "outputs": [ + { + "ename": "PermissionError", + "evalue": "[Errno 13] Permission denied: 'C:\\\\Users\\\\benjamin.reed\\\\Downloads\\\\babynames_by_year.xlsx'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mPermissionError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[36]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m xlr=\u001b[43mpd\u001b[49m\u001b[43m.\u001b[49m\u001b[43mExcelWriter\u001b[49m\u001b[43m(\u001b[49m\u001b[43mos\u001b[49m\u001b[43m.\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m.\u001b[49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilePath\u001b[49m\u001b[43m,\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mbabynames_by_year.xlsx\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m#create a placeholder for an Excel file\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\benjamin.reed\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\excel\\_openpyxl.py:61\u001b[39m, in \u001b[36mOpenpyxlWriter.__init__\u001b[39m\u001b[34m(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs)\u001b[39m\n\u001b[32m 57\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mopenpyxl\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mworkbook\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Workbook\n\u001b[32m 59\u001b[39m engine_kwargs = combine_kwargs(engine_kwargs, kwargs)\n\u001b[32m---> \u001b[39m\u001b[32m61\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[34;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[32m 62\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 63\u001b[39m \u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 64\u001b[39m \u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 65\u001b[39m \u001b[43m \u001b[49m\u001b[43mif_sheet_exists\u001b[49m\u001b[43m=\u001b[49m\u001b[43mif_sheet_exists\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 66\u001b[39m \u001b[43m \u001b[49m\u001b[43mengine_kwargs\u001b[49m\u001b[43m=\u001b[49m\u001b[43mengine_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 67\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 69\u001b[39m \u001b[38;5;66;03m# ExcelWriter replaced \"a\" by \"r+\" to allow us to first read the excel file from\u001b[39;00m\n\u001b[32m 70\u001b[39m \u001b[38;5;66;03m# the file and later write to it\u001b[39;00m\n\u001b[32m 71\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mr+\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._mode: \u001b[38;5;66;03m# Load from existing workbook\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\benjamin.reed\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1246\u001b[39m, in \u001b[36mExcelWriter.__init__\u001b[39m\u001b[34m(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs)\u001b[39m\n\u001b[32m 1242\u001b[39m \u001b[38;5;28mself\u001b[39m._handles = IOHandles(\n\u001b[32m 1243\u001b[39m cast(IO[\u001b[38;5;28mbytes\u001b[39m], path), compression={\u001b[33m\"\u001b[39m\u001b[33mcompression\u001b[39m\u001b[33m\"\u001b[39m: \u001b[38;5;28;01mNone\u001b[39;00m}\n\u001b[32m 1244\u001b[39m )\n\u001b[32m 1245\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(path, ExcelWriter):\n\u001b[32m-> \u001b[39m\u001b[32m1246\u001b[39m \u001b[38;5;28mself\u001b[39m._handles = \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1247\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mis_text\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\n\u001b[32m 1248\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1249\u001b[39m \u001b[38;5;28mself\u001b[39m._cur_sheet = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1251\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m date_format \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\benjamin.reed\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\common.py:882\u001b[39m, in \u001b[36mget_handle\u001b[39m\u001b[34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[39m\n\u001b[32m 873\u001b[39m handle = \u001b[38;5;28mopen\u001b[39m(\n\u001b[32m 874\u001b[39m handle,\n\u001b[32m 875\u001b[39m ioargs.mode,\n\u001b[32m (...)\u001b[39m\u001b[32m 878\u001b[39m newline=\u001b[33m\"\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 879\u001b[39m )\n\u001b[32m 880\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 881\u001b[39m \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m882\u001b[39m handle = \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mioargs\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 883\u001b[39m handles.append(handle)\n\u001b[32m 885\u001b[39m \u001b[38;5;66;03m# Convert BytesIO or file objects passed with an encoding\u001b[39;00m\n", + "\u001b[31mPermissionError\u001b[39m: [Errno 13] Permission denied: 'C:\\\\Users\\\\benjamin.reed\\\\Downloads\\\\babynames_by_year.xlsx'" + ] + } + ], + "source": [ + "xlr=pd.ExcelWriter(os.path.join(filePath,'babynames_by_year.xlsx')) #create a placeholder for an Excel file" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "8f70533c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2010\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2011\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2012\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2013\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2014\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2015\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2016\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2017\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2018\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2019\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "year==2020\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\benjamin.reed\\AppData\\Local\\Temp\\ipykernel_22704\\469401706.py:5: FutureWarning: Starting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n" + ] + } + ], + "source": [ + "for y in years: #loop through each year\n", + " criteria=f\"year=={y}\" #create a criteria for each year\n", + " print(criteria)\n", + " df_temp=df.query(criteria) #create a temporary dataframe for each year\n", + " df_temp.to_excel(xlr,str(y),index=False) #push the temporary dataframe to a tab in the Excel file\n", + "xlr.close() #save the Excel file" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "f4e8b8ff", + "metadata": {}, + "outputs": [], + "source": [ + "df_pivot=pd.pivot_table(data=df,values=['number'],columns=['gender'],aggfunc='sum') #create a pivot table" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "1794e0ed", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
genderFEMALEMALE
number1552080317851928
\n", + "
" + ], + "text/plain": [ + "gender FEMALE MALE\n", + "number 15520803 17851928" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_pivot" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/SampleGradeTracker.py b/SampleGradeTracker.py new file mode 100644 index 00000000..1243afd6 --- /dev/null +++ b/SampleGradeTracker.py @@ -0,0 +1,73 @@ +# Displaying the title and instructions for the user +print("-------- Weighted Course Grade Calculator --------") +print("\nInstructions: Enter the number of weighted assignments, then input each grade (0-100) and its weight (0-100). The total weight must not exceed 100. Use this calculator to determine your overall course grade, assess the impact of assignments, and track your academic progress throughout the semester.") + +# Initialize an empty list to store each assignment's grade and weight +assignments = [] + +# Ask the user how many assignments or sections they want to enter +num = int(input("\nHow many weighted assignments/sections do you have? ")) + +# Track the total weight entered by the user to ensure it doesn't exceed 100 +total_weight = 0 + +# Loop through each assignment +for i in range(num): + print("\nAssignment/Section", i + 1) + + # Get a valid grade from the user (between 0 and 100) + while True: + grade = float(input(" Enter the grade (0-100): ")) + if 0 <= grade <= 100: + break + else: + print(" Please enter a grade between 0 and 100.") + + # Get a valid weight from the user and ensure total doesn't exceed 100 + while True: + weight = float(input(" Enter the weight: ")) + if 0 <= weight <= 100 and total_weight + weight <= 100: + total_weight += weight + break + else: + print(" Weight must be between 0 and 100 and total weights cannot exceed 100.") + + # Store the grade and weight as a dictionary and add to the list + assignment = {"grade": grade, "weight": weight} + assignments.append(assignment) + + +# Function to calculate the weighted overall grade +def calculate_grade(assignments): + total = 0 + for a in assignments: + # Multiply each grade by its weight and add to the total + total += a["grade"] * a["weight"] + + # Check to avoid division by zero + if total_weight == 0: + print(" Weight must be between 0 and 100 and total weights cannot exceed 100.") + else: + overall = total / total_weight + return overall + + +# Function to return a motivational message based on the final grade +def grade_message(grade): + if grade >= 90: + return "Great job! You're doing excellent!" + elif grade >= 80: + return "Good work! Keep it up!" + elif grade >= 70: + return "You're getting there, keep pushing!" + else: + return "Don't give up! You can improve!" + + +# Call the calculation function and print the result and message +overall = calculate_grade(assignments) +print("\nYour current overall grade is:", overall, "%") +print(grade_message(overall)) + +# Closing message +print("\nThanks for using the calculator! Good luck!") \ No newline at end of file diff --git a/elements1_20.txt b/elements1_20.txt new file mode 100644 index 00000000..4748f17a --- /dev/null +++ b/elements1_20.txt @@ -0,0 +1,20 @@ +Hydrogen +Helium +Lithium +Beryllium +Boron +Carbon +Nitrogen +Oxygen +Fluorine +Neon +Sodium +Magnesium +Aluminum +Silicon +Phosphorus +Sulfur +Chlorine +Argon +Potassium +Calcium \ No newline at end of file diff --git a/grades_data.txt b/grades_data.txt new file mode 100644 index 00000000..08d95f36 --- /dev/null +++ b/grades_data.txt @@ -0,0 +1,3 @@ +Is 3020,50.0,Quiz,60.0 +Is 3020,95.0,Homework,10.0 +Math 1101,90.0,Test,60.0 diff --git a/ksu_news_08_28_2025_all.csv b/ksu_news_08_28_2025_all.csv new file mode 100644 index 00000000..e11d5c01 --- /dev/null +++ b/ksu_news_08_28_2025_all.csv @@ -0,0 +1,91 @@ +Number,Title,URL,Date +1,Kennesaw State and Fukuoka University sign agreement to expand global fintech education,https://www.kennesaw.edu/coles/news/stories/2025-08-28-kennesaw-state-and-fukuoka-university-sign-agreement-to-expand-global-fintech-education.php,"August 28, 2025" +2,"Kennesaw State coach Jerry Mack embraces relationships, community as KSU football enters new era",https://www.kennesaw.edu/news/stories/2025/coach-embraces-community-ksu-football-enters-new-era.php,"August 28, 2025" +3,"Kennesaw State lab serves as hub for undergraduate research, scholarship",https://www.kennesaw.edu/news/stories/2025/andrew-haddow-lab-serves-hub-undergraduate-research.php,"August 27, 2025" +4,Kennesaw State passes SACSCOC Fifth-Year Interim Review,https://www.kennesaw.edu/news/stories/2025/kennesaw-state-passes-sacscoc-fifth-year-interim-review.php,"August 26, 2025" +5,Kennesaw State program earns 2025 Regents' Award,https://www.kennesaw.edu/news/stories/2025/kennesaw-state-program-earns-2025-regents-award.php,"August 26, 2025" +6,Kennesaw State researcher taps engineering background to discover solutions for stomach diseases,https://www.kennesaw.edu/news/stories/2025/researcher-taps-engineering-discover-solutions-stomach-diseases.php,"August 25, 2025" +7,AI expert Kathy Pham speaking at Kennesaw State to begin Presidential Lecture Series,https://www.kennesaw.edu/news/stories/2025/ksu-presidential-lecture-series-ai-expert-kathy-pham.php,"August 25, 2025" +8,Kennesaw State University recognized as Military Support College of Distinction,https://www.kennesaw.edu/news/stories/2025/ksu-recognized-military-support-college-distinction.php,"August 22, 2025" +9,Kennesaw State trio spend summer interning at Air Force Research Lab,https://www.kennesaw.edu/news/stories/2025/ksu-trio-summer-interning-air-force-research-lab.php,"August 21, 2025" +10,Kennesaw State student earns competitive internship with NBC's Today Show,https://www.kennesaw.edu/news/stories/2025/student-earns-competitive-internship-nbc-today-show.php,"August 20, 2025" +1,"Kennesaw State, Walens Family Announce Fifth Third Stadium Field Naming Partnership",https://ksuowls.com/news/2025/8/19/football-kennesaw-state-walens-family-announce-fifth-third-stadium-field-naming-partnership-halftime-ceremony.aspx,"August 19, 2025" +2,Kennesaw State associate professor appointed to national mathematics education commission,https://www.kennesaw.edu/news/stories/2025/associate-professor-appointed-national-mathematics-education-commission.php,"August 19, 2025" +3,"Kennesaw State researchers create low-cost system to monitor dams, prevent floods",https://www.kennesaw.edu/news/stories/2025/researchers-create-low-cost-system-monitor-dams.php,"August 18, 2025" +4,Dr. Luc Guglielmi appointed to full-time ombuds role at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/luc-guglielmi-appointed-full-time-ombuds-kennesaw-state.php,"August 14, 2025" +5,Kennesaw State economic impact on the rise to $2.3 billion,https://www.kennesaw.edu/news/stories/2025/kennesaw-state-economic-impact-2.3-billion.php,"August 14, 2025" +6,Kennesaw State's MOVE Center aims to redefine the future of human mobility,https://www.kennesaw.edu/news/stories/2025/move-center-aims-to-redefine-future-of-human-mobility.php,"August 13, 2025" +7,Kennesaw State and VyStar Credit Union announce partnership and arena naming,https://ksuowls.com/news/2025/8/12/general-kennesaw-state-and-vystar-credit-union-announce-partnership-and-arena-naming.aspx,"August 12, 2025" +8,Kennesaw State student helps develop new index for cancer treatment time costs,https://www.kennesaw.edu/news/stories/2025/kennesaw-state-student-helps-develop-new-index-for-cancer-treatment-time-costs.php,"August 11, 2025" +9,Kennesaw State physics professor receives grant to help create precise simulations for particle colliders,https://www.kennesaw.edu/news/stories/2025/physics-professor-receives-grant-simulations-particle-colliders.php,"August 08, 2025" +10,"From criminology to the classroom, Kennesaw State graduate finds purpose in special education",https://www.kennesaw.edu/news/stories/2025/ksu-student-finds-purpose-in-special-education.php,"August 07, 2025" +1,Kennesaw State's Owl Cyber Team earns top finish in national cybersecurity competition,https://www.kennesaw.edu/news/stories/2025/owlcyberteamearnstopfinishinnationalcybersecurity.php,"August 06, 2025" +2,National publication recognizes Kennesaw State with Excellence in Mental Health and Well-Being Award,https://www.kennesaw.edu/news/stories/2025/publication-recognizes-ksu-excellence-mental-health-well-being-award.php,"August 05, 2025" +3,Kennesaw State researchers examine how parents navigate children's smartphone use,https://www.kennesaw.edu/news/stories/2025/ksu-researchers-examine-parents-navigate-children-smartphone-use.php,"August 04, 2025" +4,"Kennesaw State launches Center for Interactive Media to drive innovation in VR, gaming, and digital storytelling",https://www.kennesaw.edu/news/stories/2025/center-interactive-media-drive-innovation-vr-gaming-storytelling.php,"August 01, 2025" +5,Kennesaw State alumna to compete in international Deaflympics games in Tokyo,https://www.kennesaw.edu/news/stories/2025/ksu-alum-compete-international-deaflympics-games-tokyo.php,"July 31, 2025" +6,Kennesaw State nurses excel on the front lines and at home,https://www.kennesaw.edu/news/stories/2025/nurses-excel-on-front-lines-and-at-home.php,"July 30, 2025" +7,Kennesaw State graduates earn international recognition for award-winning architectural drawing,https://www.kennesaw.edu/news/stories/2025/graduates-earn-international-recognition-award-winning-architectural-drawing.php,"July 29, 2025" +8,Student's CrossFit passion leads to breakthrough research at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/crossfit-passion-leads-to-breakthrough-research-ksu.php,"July 28, 2025" +9,Kennesaw State student and faculty use supercomputing to advance Alzheimer's drug research,https://www.kennesaw.edu/news/stories/2025/student-and-faculty-use-supercomputing-advance-alzheimers-drug-research.php,"July 25, 2025" +10,KSU student working to address challenges with elder care,https://www.kennesaw.edu/news/stories/2025/ksu-student-working-address-challenges-elder-care.php,"July 24, 2025" +1,Kennesaw State student researcher streamlining manufacturing automation through digital twin technology,https://www.kennesaw.edu/news/stories/2025/student-researchers-streamlining-manufacturing-digital-twin-technology.php,"July 23, 2025" +2,Discovery courses provide hands-on experiences for Kennesaw State Honors students,https://www.kennesaw.edu/news/stories/2025/discovery-courses-provide-hands-on-experience-honors-students.php,"July 22, 2025" +3,Kennesaw State student's research aims to create more confident math teachers,https://www.kennesaw.edu/news/stories/2025/student-research-aims-to-create-confident-math-teachers.php,"July 21, 2025" +4,Double Owl Pathways propels Kennesaw State student toward recognition in neuroscience research,https://www.kennesaw.edu/news/stories/2025/double-owl-pathways-propels-student-recognition-neuroscience-research.php,"July 18, 2025" +5,KSU student developing stroke-screening tool for children with sickle cell ,https://www.kennesaw.edu/news/stories/2025/student-stroke-screening-tool-for-children-with-sickle-cell.php,"July 17, 2025" +6,Kennesaw State associate professor honored with national award for excellence in engineering education,https://www.kennesaw.edu/news/stories/2025/national-award-excellence-engineering-education.php,"July 16, 2025" +7,Kennesaw State professor planting knowledge with his latest research,https://www.kennesaw.edu/news/stories/2025/professor-planting-knowledge-with-latest-research.php,"July 15, 2025" +8,Kennesaw State business students to benefit from the Madhuri and Jagdish N. Sheth Marketing Scholarship,https://www.kennesaw.edu/news/stories/2025/business-students-to-benefit-marketing-scholarship.php,"July 14, 2025" +9,Five recent Kennesaw State physics graduates to pursue doctoral studies,https://www.kennesaw.edu/news/stories/2025/five-recent-ksu-physics-graduates-pursue-doctoral-studies.php,"July 11, 2025" +10,"Kennesaw State researcher nominated to NSF center, wins American Chemical Society Petroleum Research Funds award",https://www.kennesaw.edu/news/stories/2025/researcher-award-american-chemical-society-petroleum-research-funds.php,"July 10, 2025" +1,Kennesaw State student selected for Georgia's American Society of Civil Engineers Student of the Year award,https://www.kennesaw.edu/news/stories/2025/student-selected-georgia-america-society-civil-engineers-award.php,"July 09, 2025" +2,Kennesaw State computer game design and development students turn stargazing into interactive learning,https://www.kennesaw.edu/news/stories/2025/game-design-students-turn-stargazing-interactive-learning.php,"July 08, 2025" +3,KSU researcher's exceptional mentorship prioritizes students first,https://www.kennesaw.edu/research/news/2025-undergraduate-research-mentor-award.php,"July 07, 2025" +4,Kennesaw State student working to simplify cardiovascular disease detection,https://www.kennesaw.edu/news/stories/2025/ksu-student-works-to-simplify-cardiovascular-disease-detection.php,"July 03, 2025" +5,Kennesaw State certification programs broaden reach of professional education,https://www.kennesaw.edu/news/stories/2025/ksu-certification-programs-broaden-reach-of-professional-education.php,"July 02, 2025" +6,Student-staffed marketing firm raising success of real-world clients,https://www.kennesaw.edu/news/stories/2025/ksu-student-staffed-marketing-raising-success-of-clients.php,"July 01, 2025" +7,Kennesaw State steel bridge team wins award for ingenuity in national competition,https://www.kennesaw.edu/news/stories/2025/steel-bridge-team-wins-award-ingenuity-national-competition.php,"June 30, 2025" +8,Kennesaw State expands support for student-parents through new grants,https://www.kennesaw.edu/news/stories/2025/ksu-expands-support-student-parents-through-new-grants.php,"June 30, 2025" +9,Kennesaw State professor inducted as International Organization for Physical Education in Higher Education fellow,https://www.kennesaw.edu/news/stories/2025/professor-inducted-international-organization-physical-education-fellow.php,"June 27, 2025" +10,KSU project designing automated exoskeleton to aid stroke victims,https://www.kennesaw.edu/news/stories/2025/ksu-project-designing-exoskeleton-aid-stroke-victims.php,"June 26, 2025" +1,Kennesaw State assistant professor named 2025 AIA Georgia Educator of the Year,https://www.kennesaw.edu/news/stories/2025/assistant-professor-named-aia-georgia-educator-of-year.php,"June 25, 2025" +2,Kennesaw State public health students win gold designation at national competition,https://www.kennesaw.edu/news/stories/2025/public-health-students-win-gold-designation-national-competititon.php,"June 24, 2025" +3,KSU researcher awarded prestigious NSF Medium Grant to advance balance technologies in VR,https://www.kennesaw.edu/news/stories/2025/researcher-awarded-grant-advance-balance-technologies-virtual-reality.php,"June 23, 2025" +4,Kennesaw State researchers developing AI-powered drones to protect peanut farms from wildlife,https://www.kennesaw.edu/news/stories/2025/researchers-developing-ai-powered-drones-protect-peanut-farms.php,"June 20, 2025" +5,Kennesaw State alumna triumphs through adversity to inspire as Gwinnett County educator,https://www.kennesaw.edu/news/stories/2025/alumna-triumphs-adversity-inspire-gwinnett-educator.php,"June 18, 2025" +6,Kennesaw State alumni awarded prestigious Fulbright scholarships,https://www.kennesaw.edu/news/stories/2025/ksu-alumni-awarded-fulbright-scholarships.php,"June 17, 2025" +7,Kennesaw State physics professor receives Department of Energy grant to explore light-matter interactions in quantum materials,https://www.kennesaw.edu/news/stories/2025/physics-grant-light-matter-interactions-quantum-materials.php,"June 13, 2025" +8,Triplets each find their own path to success at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/triplets-find-path-to-success-at-ksu.php,"June 12, 2025" +9,Kennesaw State architecture students bring eco-centered design to global stage in Italy,https://www.kennesaw.edu/news/stories/2025/architecture-students-eco-centered-design-italy.php,"June 11, 2025" +10,Kennesaw State educator brings industry experience to the classroom,https://www.kennesaw.edu/news/stories/2025/educator-brings-industry-experience-to-classroom.php,"June 10, 2025" +1,Kennesaw State student draws on personal experience in graduate program,https://www.kennesaw.edu/news/stories/2025/student-draws-on-personal-experience-graduate-program.php,"June 09, 2025" +2,Growth fuels passion for Kennesaw State master's graduate,https://www.kennesaw.edu/news/stories/2025/growth-fuels-passion-for-ksu-masters-graduate.php,"June 06, 2025" +3,Kennesaw State public health grad seeks to make a difference,https://www.kennesaw.edu/news/stories/2025/public-health-grad-seeks-make-a-difference.php,"June 05, 2025" +4,"Kennesaw State professor uses speed, crash data to better understand how to protect school children ",https://www.kennesaw.edu/news/stories/2025/ksu-professor-speed-crash-data-protect-school-children.php,"June 04, 2025" +5,Kennesaw State students with Center for Sustainable Journalism hit the ground reporting,https://www.kennesaw.edu/news/stories/2025/ksu-students-center-for-sustainable-journalism-reporting.php,"June 03, 2025" +6,Kennesaw State student secures prestigious VICEROY Maven internship,https://www.kennesaw.edu/news/stories/2025/student-secures-viceroy-maven-internship.php,"June 02, 2025" +7,KSU Game Studio levels up with new release,https://www.kennesaw.edu/research/news/posts/chiba-launch.php,"May 30, 2025" +8,Research helps dual major forge path at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/research-helps-dual-major-forge-path-at-ksu.php,"May 30, 2025" +9,Student-led public relations agency at Kennesaw State finds success with client campaign work,https://www.kennesaw.edu/news/stories/2025/student-led-public-relations-agency-ksu-finds-success-client-campaign.php,"May 29, 2025" +10,KSU dancers selected to participate in prestigious summer workshops,https://www.kennesaw.edu/news/stories/2025/dancers-participate-prestigious-summer-workshops.php,"May 28, 2025" +1,Kennesaw State researchers develop phone application to combat elderly loneliness,https://www.kennesaw.edu/news/stories/2025/researchers-develop-app-combat-elderly-loneliness.php,"May 27, 2025" +2,Kennesaw State graduates latest cohort of the Paul Radow Scholars Program,https://www.kennesaw.edu/news/stories/2025/ksu-graduates-latest-cohort-paul-radow-scholars.php,"May 23, 2025" +3,Kennesaw State faculty member wins prestigious Art Directors Club award for creative excellence,https://www.kennesaw.edu/news/stories/2025/faculty-member-wins-art-directors-club-award.php,"May 22, 2025" +4,Kennesaw State researcher develops AI robot to aid farmers in fight against pests,https://www.kennesaw.edu/news/stories/2025/researcher-develops-ai-robot-aid-farmers-against-pests.php,"May 21, 2025" +5,Kennesaw State recognized for environmental stewardship,https://www.kennesaw.edu/news/stories/2025/kennesaw-state-recognized-for-environmental-stewardship.php,"May 20, 2025" +6,Kennesaw State alum receives international scientific honor,https://www.kennesaw.edu/news/stories/2025/ksu-alum-recieves-international-scientific-honor.php,"May 19, 2025" +7,Kennesaw State men's team wins Conference USA Outdoor Championship,https://ksuowls.com/news/2025/5/19/mens-track-and-field-kennesaw-state-men-win-conference-usa-outdoor-championship.aspx,"May 19, 2025" +8,Parent and Family initiatives enhance sense of community at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/parent-and-family-initiatives-enhance-sense-of-community.php,"May 16, 2025" +9,Kennesaw State to launch Bachelor of Science in Aerospace Engineering degree program,https://www.kennesaw.edu/news/stories/2025/ksu-launch-bachelor-science-aerospace-engineering-program.php,"May 15, 2025" +10,Kennesaw State student wins marketing competition at international conference,https://www.kennesaw.edu/news/stories/2025/student-wins-marketing-competition-international-conference.php,"May 14, 2025" +1,Recent Kennesaw State architecture graduate named to Metropolis Future100 list,https://www.kennesaw.edu/news/stories/2025/architecture-graduate-named-metropolis-future-100-list.php,"May 13, 2025" +2,Kennesaw State researchers earn National Institutes of Health grant to address diabetic eye care via technology,https://www.kennesaw.edu/news/stories/2025/nih-grant-address-diabetic-eye-care-technology.php,"May 12, 2025" +3,'Dynamic Duo' impact exercise science through undergraduate research at Kennesaw State,https://www.kennesaw.edu/news/stories/2025/dynamic-duo-impact-exercise-science-undergraduate-research.php,"May 08, 2025" +4,"Kennesaw State students, C-suite executives of Student Managed Investment Fund soon to begin finance careers",https://www.kennesaw.edu/news/stories/2025/executives-student-managed-investment-fund-begin-finance-careers.php,"May 07, 2025" +5,"Kennesaw State student, assistant principal sharpens educational leadership skills through doctoral program ",https://www.kennesaw.edu/news/stories/2025/student-sharpens-educational-leadership-skills-doctoral-program.php,"May 06, 2025" +6,Master's in robotics systems fulfills Kennesaw State online student's goal,https://www.kennesaw.edu/news/stories/2025/masters-robotics-systems-fulfills-online-student-goal.php,"May 05, 2025" +7,Honors biology student makes most of KSU experience,https://www.kennesaw.edu/news/stories/2025/honors-biology-student-makes-most-of-ksu-experience.php,"May 02, 2025" +8,College of Science and Mathematics recognizes faculty teaching excellence from 2024,https://www.kennesaw.edu/news/stories/2025/science-mathematics-recognizes-faculty-teaching-excellence.php,"May 01, 2025" +9,"Kennesaw State information technology student, Fulbright semifinalist chasing interest in cybersecurity",https://www.kennesaw.edu/news/stories/2025/information-technology-student-fulbright-interest-cybersecurity.php,"May 01, 2025" +10,Kennesaw State recognizes outstanding staff at annual awards ceremony,https://www.kennesaw.edu/news/stories/2025/ksu-recognizes-outstanding-staff-annual-awards.php,"April 30, 2025" diff --git a/mean_temp.txt b/mean_temp.txt new file mode 100644 index 00000000..ed6372c5 --- /dev/null +++ b/mean_temp.txt @@ -0,0 +1,9 @@ +city,country,month ave: highest high,month ave: lowest low +Beijing,China,30.9,-8.4 +Cairo,Egypt,34.7,1.2 +London,UK,23.5,2.1 +Nairobi,Kenya,26.3,10.5 +New York City,USA,28.9,-2.8 +Sydney,Australia,26.5,8.7 +Tokyo,Japan,30.8,0.9 +RIO de Janeiro, Brazil, 30.0,18.0 diff --git a/poemJUSTNOW.txt b/poemJUSTNOW.txt new file mode 100644 index 00000000..d8d57e34 --- /dev/null +++ b/poemJUSTNOW.txt @@ -0,0 +1,7 @@ +Loops I repeat +loops +loops +loops +I repeat +until I +break