From 9e488b4c3578a3b727e4e546186e13cef02619ff Mon Sep 17 00:00:00 2001 From: Melanie Almeida Date: Sun, 26 Oct 2025 18:48:46 +0100 Subject: [PATCH 1/2] trying to simplify unit 2 --- unit_2/unit_2_capstone_project.py | 46 +++++++++++++++++-------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/unit_2/unit_2_capstone_project.py b/unit_2/unit_2_capstone_project.py index 3a44dba..a532692 100644 --- a/unit_2/unit_2_capstone_project.py +++ b/unit_2/unit_2_capstone_project.py @@ -1,46 +1,50 @@ #The problem #This is your first interactive programming task, so let's have some fun with the user! You want to write a program that automatically combines two names given by the user. -# That's an open-ended problem statement, so let's add a few more details and restrictions: +#That's an open-ended problem statement, so let's add a few more details and restrictions: #Tell the user to give you two names in the format: FIRST LAST #Show the user two possible new names in the format:FIRST LAST. #The new first name is a combination of the first names given by the user, and the new last name is a combination of the last names given by the user. #For example, if the user gives you Alice Cat and Bob, a possible mashup is Bolice Dot. user_first=input("Give two names: ") #ask the user to give two names -answer_1=user_first.upper() #make the answer uppercase -print(answer_1) +answer1=user_first.upper() #make the answer uppercase +print(answer1) user_second=input("Give again two names: ") #ask the user to give two names -answer_2=user_second.upper() #make the answer uppercase -print(answer_2) +answer2=user_second.upper() #make the answer uppercase +print(answer2) -split_index_1=answer_1.find(" ") -split_index_2=answer_2.find(" ") +split_index_1=answer1.find(" ") +split_index_2=answer2.find(" ") print(split_index_1) #finds the index of the space #split the first names and the last names -first_name_1=answer_1[0:split_index_1] -print(first_name_1) -first_name_2=answer_2[0:split_index_2] -print(first_name_2) +firstname1=answer1[0:split_index_1] +print(firstname1) +firstname2=answer2[0:split_index_2] +print(firstname2) -last_name_1=answer_1[split_index_1+1:len(answer_1)] -print(last_name_1) -last_name_2=answer_2[split_index_2+1:len(answer_2)] -print(last_name_2) +#Tuka asked me to simplify from line 29 to line 39 +lastname1=answer1[split_index_1+1:len(answer1)] +print(lastname1) +lastname1a=answer1[len(answer1)-1:split_index_1] +print(lastname1a) + +lastname2=answer2[split_index_2+1:len(answer2)] +print(lastname2) #split letters and combine them first name 1 and first name 2 -sub_string_first_name_1=first_name_1[0:1] -sub_string_first_name_2=first_name_2[0:1] +sub_string_first_name_1=firstname1[0:1] +sub_string_first_name_2=firstname2[0:1] -print(first_name_1.replace(sub_string_first_name_1,sub_string_first_name_2)) -print(first_name_2.replace(sub_string_first_name_2,sub_string_first_name_1)) +print(firstname1.replace(sub_string_first_name_1,sub_string_first_name_2)) +print(firstname2.replace(sub_string_first_name_2,sub_string_first_name_1)) #split letters and combine them last name 1 and last name 2 sub_string_last_name_1=last_name_1[len(last_name_1)-1:len(last_name_1)-2:-1] sub_string_last_name_2=last_name_2[len(last_name_1)-1:len(last_name_1)-2:-1] -print(last_name_1.replace(sub_string_last_name_1,sub_string_last_name_2)) -print(last_name_2.replace(sub_string_last_name_2,sub_string_last_name_1)) \ No newline at end of file +print(lastname1.replace(sub_string_last_name_1,sub_string_last_name_2)) +print(lastname2.replace(sub_string_last_name_2,sub_string_last_name_1)) \ No newline at end of file From c753c4a9c18cac96c08717b1c6dddbd713abfe7d Mon Sep 17 00:00:00 2001 From: Melanie Almeida Date: Fri, 7 Nov 2025 21:30:23 +0100 Subject: [PATCH 2/2] chapter 30 --- unit_7/unit_7_exercices.ipynb | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/unit_7/unit_7_exercices.ipynb b/unit_7/unit_7_exercices.ipynb index e69de29..46c0714 100644 --- a/unit_7/unit_7_exercices.ipynb +++ b/unit_7/unit_7_exercices.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "970a0a95", + "metadata": {}, + "source": [ + "### Quick check 30.1\n", + "For each of the following scenarios, would you need to create a new object type or can you represent it with an object type you already know?\n", + "1. Someone's age ->integers\n", + "2. Latitude and longitude of a group of map points -> tuple\n", + "3. A person -> no\n", + "4. a chair -> no" + ] + }, + { + "cell_type": "markdown", + "id": "06a5e28f", + "metadata": {}, + "source": [ + "### Quick check 30.2 \n", + "What are some appropriate data you may use to represent each of the following types?\n", + "1. Rectangle -> a width and a height\n", + "2. TV -> a width, a height, a depth, number of ports, number of pixels, and so forth\n", + "3. Chair -> number of legs, seat back or not, cushioned or not\n", + "4. Person -> name, age, height, hair color, eye color..." + ] + }, + { + "cell_type": "markdown", + "id": "d99d1053", + "metadata": {}, + "source": [ + "### Quick check 30.3\n", + "What are some appropriate behaviors you may add for each of the following object types?\n", + "1. Rectangle: find the area or the perimeter\n", + "2. TV: turn it on/off, get its diagonal, connect a cable to a port\n", + "3. Chair: have a person sit on a chair, cut off a leg, add a cushion\n", + "4. Person: change name, increment the age, change hair color" + ] + }, + { + "cell_type": "markdown", + "id": "dfa95229", + "metadata": {}, + "source": [ + "### Quick check 30.4\n", + "In the following examples of dot notation, on what object type is the operation being done? \n", + "1. \"wow\".replace(\"o\",\"a\") -> string\n", + "2. [1,2,3].append(4) -> list\n", + "3. {1:1,2:2}.keys() -> ictionnary\n", + "4. len(\"lalala\") -> string" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}