## First Assignment

#### 1) Apply the appropriate string methods to the **x** variable (as '.upper') to change it exactly to: "$Dichlorodiphenyltrichloroethane$".


```python
x = "DiClOrod  IFeNi  lTRicLOr oETaNo  DiChlorod iPHeny lTrichL oroEThaNe"
```


```python
x = "DiClOrod  IFeNi  lTRicLOr oETaNo  DiChlorod iPHeny lTrichL oroEThaNe"
x[32:68].lower().replace(" ", "").capitalize()

```




    'Dichlorodiphenyltrichloroethane'



#### 2) Assign respectively the values: 'word', 15, 3.14 and 'list' to variables A, B, C and D in a single line of code. Then, print them in that same order on a single line separated by a space, using only one print statement.


```python
A, B, C, D = "word", 15, 3.14, "list"

print(A, B, C, D)
```

    word 15 3.14 list


#### 3) Use the **input()** function to receive an input in the form **'68.4 1.71'**, that is, two floating point numbers in a line separated by space. Then, assign these numbers to the variables **w** and **h** respectively, which represent an individual's weight and height (hint: take a look at the '.split()' method). With this data, calculate the individual's Body Mass Index (BMI) from the following relationship: 
    
\begin{equation}
BMI = \dfrac{weight}{height^2}
\end{equation}


```python
w, h = map(float, input("Enter your weight and height: ").split())
bmi = w / (h * h)
print("Your BMI is " + str(round(bmi, 1)))
```

    Enter your weight and height: 55 1.66
    Your BMI is 20.0


#### This value can also be classified according to ranges of values, following to the table below. Use conditional structures to classify and print the classification assigned to the individual. 

<center><\center>  


(source: https://healthtravelguide.com/bmi-calculator/)


```python
w, h = map(float, input("Enter your weight and height: ").split())
bmi = w / (h * h)

if (bmi < 18.5):
    print("Underweight")
elif(bmi >= 25.0 and bmi <= 29.9):
    print("Pre-obesity")
elif(bmi >= 30.0 and bmi <= 34.9):
    print("Obesity class I")
elif(bmi >= 35.0 and bmi <= 39.9):
    print("Obesity class II")
elif(bmi > 40):
    print("Obesity class III")
else:
    print("Normal weight")

```

    Enter your weight and height: 55 1.66
    Normal weight


#### 4) Receive an integer as an input and, using a loop, calculate the factorial of this number, that is, the product of all the integers from one to the number provided. 


```python
num = int(input("Enter a number:"))

f = 1

for i in range(1, num + 1):
    f = f * i

print(f)
```

    Enter a number:6
    720


#### 5) Using a while loop and the input function, read an indefinite number of integers until the number read is -1. Present the sum of all these numbers in the form of a print, excluding the -1 read at the end. 


```python
inputs = input("Enter Number: ")
list = []

while int(inputs) != -1:
    list.append(inputs)
    inputs = input("Enter Num: ")
print(list)    
```

    Enter Number: 6
    Enter Num: 6
    Enter Num: -1
    ['6', '6']


#### 6) Read the **first name** of an employee, his **amount of hours worked** and the **salary per hour** in a single line separated by commas. Next, calculate the **total salary** for this employee and show it to two decimal places.


```python
employee = {
    "first_name": "Joe",
    "hours_worked": 304,
    "hourly_wage": 24
}

print(employee)

total_salary = employee["hours_worked"] * employee["hourly_wage"]

print(round(total_salary, 2))
```

    {'first_name': 'Joe', 'hours_worked': 304, 'hourly_wage': 24}
    7296


#### 7) Read three floating point values **A**, **B** and **C** respectively. Then calculate itens a, b, c, d and e: 


```python
A, B, C = map(float, input("Enter decimal numbers: ").split())
```

    Enter decimal numbers: 6.6 5.5 3.3


    a) the area of the triangle rectangle with A as the base and C as the height.


```python
A, C = map(float, input("Enter base and height: ").split())

area = (A * C) / 2 

print("The area of this triangle is: " + str(area))
```

    Enter base and height: 4 5
    The area of this triangle is: 10.0


    b) the area of the circle of radius C. (pi = 3.14159) 


```python
C = float(input("Enter radius: "))

import math
area = (C * C) * math.pi

print("The area of this circle is: " + str(area))
```

    Enter radius: 5
    The area of this circle is: 78.53981633974483


    c) the area of the trapezoid that has A and B for bases and C for height. 


```python
A, B, C = map(float, input("Enter bases and height: ").split())

area = ((A + B) / 2) * C 

print("The area of this trapezoid is: " + str(area))
```

    Enter bases and height: 6 5 4
    The area of this trapezoid is: 22.0


    d) the area of the square that has side B. 


```python
B = float(input("Enter side: "))

area = B * B

print("The area of this square is: " + str(area))
```

    Enter side: 4
    The area of this square is: 16.0


    e) the area of the rectangle that has sides A and B. 


```python
A, B = map(float, input("Enter base and height: ").split())

area = A * B

print("The area of this rectangle is: " + str(area))
```

    Enter base and height: 3 5
    The area of this rectangle is: 15.0


#### 8) Read **the values a, b and c** and calculate the **roots of the second degree equation** $ax^{2}+bx+c=0$ using [this formula](https://en.wikipedia.org/wiki/Quadratic_equation). If it is not possible to calculate the roots, display the message **“There are no real roots”**. 


```python
import cmath

a, b, c = map(float, input("Enter numbers: ").split())

d = (b**2) - (4 *a * c)

r1 = (-b - cmath.sqrt(d)) / (2 * a)
r2 = (-b + cmath.sqrt(d)) / (2 * a)

if(d < 0):
    print("There are no real roots")
else:
    print(r1, r2)
```

    Enter numbers: 2 1 1
    There are no real roots


#### 9) Read four floating point numerical values corresponding to the coordinates of two geographical coordinates in the cartesian plane. Each point will come in a line with its coordinates separated by space. Then calculate and show the distance between these two points. 

(obs: $d=\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$)


```python
import math

p1 = []
p2 = []

x1, y1 = map(float, input("Enter first point coordinates: ").split())
x2, y2 = map(float, input("Enter second point coordinates: ").split())

p1.append(x1)
p1.append(y1)
p2.append(x2)
p2.append(y2)

distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))

print(distance)
```

    Enter first point coordinates: 5 6
    Enter second point coordinates: 3 5
    2.23606797749979


#### 10) Read **two floating point numbers** on a line that represent **coordinates of a cartesian point**. With this, use **conditional structures** to determine if you are at the origin, printing the message **'origin'**; in one of the axes, printing **'x axis'** or **'y axis'**; or in one of the four quadrants, printing **'q1'**, **'q2**', **'q3'** or **'q4'**. 


```python
x, y  = map(float, input("Enter x-value and y-value: ").split())

if x > 0 and y > 0:
    print("q1")
elif x < 0 and y > 0:
    print("q2")
elif x < 0 and y < 0:
    print("q3")
elif x > 0 and y < 0:
    print("q4")
else: 
    print("origin")
```

    Enter x-value and y-value: 1 -4
    q4


#### 11) Read an integer that represents a phone code for international dialing.  
#### Then, inform to which country the code belongs to, considering the generated table below:
(You just need to consider the first 10 entries)  


```python
import pandas as pd
df = pd.read_html('https://en.wikipedia.org/wiki/Telephone_numbers_in_Europe')[1]
df = df.iloc[:,:2]
df.head(20)
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Country</th>
      <th>Country calling code</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Austria</td>
      <td>43</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Belgium</td>
      <td>32</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Bulgaria</td>
      <td>359</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Croatia</td>
      <td>385</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Cyprus</td>
      <td>357</td>
    </tr>
    <tr>
      <th>5</th>
      <td>Czech Republic</td>
      <td>420</td>
    </tr>
    <tr>
      <th>6</th>
      <td>Denmark</td>
      <td>45</td>
    </tr>
    <tr>
      <th>7</th>
      <td>Estonia</td>
      <td>372</td>
    </tr>
    <tr>
      <th>8</th>
      <td>Finland</td>
      <td>358</td>
    </tr>
    <tr>
      <th>9</th>
      <td>France</td>
      <td>33</td>
    </tr>
    <tr>
      <th>10</th>
      <td>Germany</td>
      <td>49</td>
    </tr>
    <tr>
      <th>11</th>
      <td>Greece</td>
      <td>30</td>
    </tr>
    <tr>
      <th>12</th>
      <td>Hungary</td>
      <td>36</td>
    </tr>
    <tr>
      <th>13</th>
      <td>Iceland</td>
      <td>354</td>
    </tr>
    <tr>
      <th>14</th>
      <td>Ireland</td>
      <td>353</td>
    </tr>
    <tr>
      <th>15</th>
      <td>Italy</td>
      <td>39</td>
    </tr>
    <tr>
      <th>16</th>
      <td>Latvia</td>
      <td>371</td>
    </tr>
    <tr>
      <th>17</th>
      <td>Liechtenstein</td>
      <td>423</td>
    </tr>
    <tr>
      <th>18</th>
      <td>Lithuania</td>
      <td>370</td>
    </tr>
    <tr>
      <th>19</th>
      <td>Luxembourg</td>
      <td>352</td>
    </tr>
  </tbody>
</table>
</div>




```python
n = int(input("Enter phone code: "))

if(n == 43):
    print("Austria")
elif(n == 32):
    print("Belgium")
elif(n == 359):
    print("Bulgaria")
elif(n == 385):
    print("Croatia")
elif(n == 357):
    print("Cyprus")
elif(n == 420):
    print("Czech Republic")
elif(n == 45):
    print("Denmark")
elif(n == 372):
    print("Estonia")
elif(n == 358):
    print("Finland")
elif(n == 33):
    print("France")
```

    Enter phone code: 33
    France


#### 12) Write a piece of code that reads 6 numbers in a row. Next, show the number of positive values entered. On the next line, print the average of the values to one decimal place. 


```python
inputs = float(input("Enter Number: "))
list = []

while len(list) < 5:
    list.append(inputs)
    inputs = float(input("Enter Num: "))

pos_count = 1

for num in list:
    if num >= 0:
        pos_count += 1

print("number of positive numbers", pos_count)
print("average of values", round(sum(list) / len(list), 1))
```

#### 13) Read an integer **N**. Then print the **square of each of the even values**, from 1 to N, including N, if applicable, arranged one per line. 


```python
n = int(input("Enter Number: "))

for n in range(1, n + 1):
    if n % 2 == 0:
        print(n * n)
```

#### 14) Using **input()**, read an integer and print its classification as **'even / odd'** and **'positive / negative'** . The two classes for the number must be printed on the same line separated by a space. In the case of zero, print only **'null'**. 


```python
n = int(input("Enter a number: "))

if(n < 0 and n%2 != 0):
    print("negative odd")
elif(n > 0 and n%2 == 0):
    print("positive even")
elif(n < 0 and n%2 == 0):
    print("negative even")
elif(n > 0 and n%2 != 0):
    print("positive odd")
elif(n == 0):
    print("null")
```

## Challenge
#### 15) Ordering problems are recurrent in the history of programming. Over time, several algorithms have been developed to fulfill this function. The simplest of these algorithms is the [**Bubble Sort**](https://en.wikipedia.org/wiki/Bubble_sort), which is based on comparisons of elements two by two in a loop of passes through the elements. Your mission, if you decide to accept it, will be to input six whole numbers ramdonly ordered. Then implement the **Bubble Sort** principle to order these six numbers **using only loops and conditionals**.  
#### At the end, print the six numbers in ascending order on a single line separated by spaces. 


```python
inputs = int(input("Enter Number: "))
list = []

while len(list) < 6:
    list.append(inputs)
    inputs = int(input("Enter Number: "))
 
count = len(list)
 
for outer in range(count - 1):
    for i in range(count - outer - 1):
        if list[i] > list[i + 1]:
            list[i], list[i + 1] = list[i + 1], list[i]
 
print(*list)
```

708cb5e94cfa41f436161bf80e315c03daa9d32c
ipynb
Jupyter Notebook
Assignments/Assignment_1.ipynb
LAnnabelle/Python_Course
c87dd27776f55215c90f93592a424727f83170b0
Apache-2.0
Assignments/Assignment_1.ipynb
LAnnabelle/Python_Course
c87dd27776f55215c90f93592a424727f83170b0
Apache-2.0
Assignments/Assignment_1.ipynb
LAnnabelle/Python_Course
c87dd27776f55215c90f93592a424727f83170b0
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES