## 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 = x.replace(" ", "")  
x = x.capitalize() 

print(x)
```

    Diclorodifeniltricloroetanodichlorodiphenyltrichloroethane


#### 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 = (input("what is your weight and hight? ").split())
w= float(w)
h=float(h)
bmi = w/(h**2)
print(round(bmi,5))

```

    what is your weight and hight? 100 1.70
    34.60208


#### 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
if bmi <= 18.5:
    print("underweight")
elif bmi <= 24.9:
    print("normal weight")
elif bmi <= 29.9:
    print("pre-obesity")
elif bmi <= 34.9:
    print("Obesity class I")
elif bmi <= 39.9:
    print("Obesity class II")
else:
    print("Obesity class III")
```

    Obesity class I


#### 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
def factorial(number):
    n = 1
    for i in range(number):
        n *=i+1
    return n 
print(factorial(int(input("write the number you want to get det factorial of "))))
```

    write the number you want to get det factorial of 5
    120


#### 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
def sum_of_numbers():
    
    while True:
        number = int(input("Enter a number: "))
        if number == -1:
            break
        number += number
    print("Sum of numbers: ", number+1)


sum_of_numbers()
```

    Enter a number: 2
    Enter a number: -2
    Enter a number: -1
    Sum of numbers:  0


#### 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
name, hours, salary_per_hour = input("Insert name, amount of hours worked and salary per hour, separated by commas: ").split(",")
total_salary = float(hours)*float(salary_per_hour)
print(total_salary)

```

    Insert name, amount of hours worked and salary per hour, separated by commas: aleks,12,45
    540.0


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


```python
A, B, C = input("input a three numbers ").split()
A = float(A)
B = float(B)
C = float(C)
pi = 3.14159
```

    input a three numbers 2 3 4 


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


```python
triangle = (A*C)/2
print('Triangle: ', triangle )
```

    Triangle:  10.35


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


```python
circle = pi*(C**2)
print('circle: ', circle)
```

    circle:  66.47604439999999


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


```python
trapezoid = (A+B)*C/2
print('trapezoid: ', trapezoid)
```

    trapezoid:  10.0


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


```python
square = B**2
print('Squere: ', square)
```

    Squere:  44.89


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


```python
rectangle = A*B
print('rectangle: ', rectangle)
```

    rectangle:  6.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
a = int(input("input a numbaer for a "))
while a == 0:
    print('a can\'t be zero')
    a = int(input("input a numbaer for a "))

b, c =[float(i) for i in input('input a number for b and c').split(',')]

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

if d < 0:
    print("No real roots")
else:
    print("x1 =", (-b + d**0.5)/(2*a), ", x2 =", (-b - d**0.5)/(2*a))
```

    input a numbaer for a 3
    input a number for b and c3,4
    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
x1, y1, x2, y2 = [float(i) for i in input("insert coordinates x1, y1, x2, y2 ").split()]

distance = ((x2 - x1)**2 + (y2 - y1)**2)**0.5

print('distance =', distance)
```

    insert coordinates x1, y1, x2, y2 1 2 4 5
    distance = 4.242640687119285


#### 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 = [float(x) for x in input("type in numbers for x and y ").split()]

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

    type in numbers for x and y 3 4
    q1


#### 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)


def country(countrycode):
    for i in range(len(df.iloc[:])):
        if str(countrycode) == df.iloc[i,1]:
            return(df.iloc[i,0])
    else:
        print("this is not a landcode")
print(country(43))
```

    Austria


#### 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
number = [float(x) for x in input('type in six numbers ').split(',')]

sum_, positive=0, 0

for i in number:
    sum_ += i
    if i >0:
        positive += 1
print('The number of positive values is: ', positive, '\n', 'The avrage value is:', sum_/6)
    
```

    type in six numbers 1,2,3,4,5,6
    The number of positive values is:  6 
     The avrage value is: 3.5


#### 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
a = int(input("input a number"))
for i in range(1,a+1):
    if i%2 ==0:
        print(i**2)
```

    input a number8
    4
    16
    36
    64


#### 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
number = int(input("enter a number "))
even = ""
positive = ""

if number == 0:
    print("null")
    
elif number%2==0:
    even = 'even'
else: 
    even = 'odd'

if number < 0:
    positive = 'negative'
else: 
    posisitve = 'positive'

print(positive, even)
    

```

    enter a number -9
    negative odd


## 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
number = [int(x) for x in input('Input six numbers: ').split(',')]
for i in range(len(number) - 1):
        for j in range(len(number) - 1 - i):
            if number[j] > number[j + 1]:
                number[j], number[j + 1] = number[j + 1], number[j]
print(numbers)
```

    Input six numbers: 1,3,4,2,1,5,4,32,6
    [1, 1, 2, 3, 4, 4, 5, 6, 32]



```python

```

ea1e40f89a91ac1aa9bb4a7fc20a9709cf641d61
ipynb
Jupyter Notebook
Assignments/Assignment_1_my_solution.ipynb
AleksanderKaspersen/Python_Course
9561e71ee5e15413ca0b2828f1b430ef062772b9
Apache-2.0
Assignments/Assignment_1_my_solution.ipynb
AleksanderKaspersen/Python_Course
9561e71ee5e15413ca0b2828f1b430ef062772b9
Apache-2.0
Assignments/Assignment_1_my_solution.ipynb
AleksanderKaspersen/Python_Course
9561e71ee5e15413ca0b2828f1b430ef062772b9
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES