<jupyter_start><jupyter_text>First Assignment  1) Apply the appropriate string methods to the **x** variable (as '.upper') to change it exactly to: "$Dichlorodiphenyltrichloroethane$".<jupyter_code>x = "DiClOrod  IFeNi  lTRicLOr oETaNo  DiChlorod iPHeny lTrichL oroEThaNe"
answer = x[x.find('DiChl'):].replace(" ","").capitalize()
print(answer)<jupyter_output>Dichlorodiphenyltrichloroethane<jupyter_text>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.<jupyter_code>A, B, C, D = 'word', 15, 3.14, 'list'
print(A,B,C,D,sep=" ")

# Other option:
#print(f"{A} {B} {C} {D}")<jupyter_output>word 15 3.14 list<jupyter_text>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}<jupyter_code>w,h = input("Enter your weight and height, respectively, separated by a space: ").split()
BMI = float(w)/float(h)**2
print(BMI)<jupyter_output>Enter your weight and height, respectively, separated by a space:  73 1.83<jupyter_text>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.   (source: https://healthtravelguide.com/bmi-calculator/)<jupyter_code>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")<jupyter_output>normal weight<jupyter_text>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.<jupyter_code>num = int(input("Enter an integer: "))
fact = 1
for i in range(1,num+1):
    fact *= i # Equivalent to fact = fact * i
print(f"{num}! = {fact}")<jupyter_output>Enter an integer:  12<jupyter_text>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.<jupyter_code>sum_numbers, number = 0, 0
while number != -1:
    sum_numbers += number
    number = int(input("Enter an integer: "))
print(f"Sum of numbers = {sum_numbers}")<jupyter_output>Enter an integer:  12
Enter an integer:  23
Enter an integer:  12
Enter an integer:  98
Enter an integer:  23
Enter an integer:  12
Enter an integer:  -1<jupyter_text>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.<jupyter_code>name, hours_wk, hour_sal = input("Insert name, amount of hours worked and salary per hour, separated by commas: ").split(",")
total_sal = float(hours_wk)*float(hour_sal)
print('{:.2f}'.format(total_sal))<jupyter_output>Insert name, amount of hours worked and salary per hour separated by commas:  James, 23, 100<jupyter_text>7) Read three floating point values **A**, **B** and **C** respectively. Then calculate itens a, b, c, d and e:<jupyter_code>A, B, C = [float(x) for x in input("Insert A, B and C").split(",")]
# a, b, c = input().split(",")
# A, B, C = float(a), float(b), float(c)<jupyter_output>Insert A, B and C 3,2,5<jupyter_text>a) the area of the triangle rectangle with A as the base and C as the height.<jupyter_code>print("Area:", A*C/2)<jupyter_output>Area: 7.5<jupyter_text>b) the area of the circle of radius C. (pi = 3.14159)<jupyter_code>print("Area:", 3.14159*C**2)<jupyter_output>Area: 78.53975<jupyter_text>c) the area of the trapezoid that has A and B for bases and C for height.<jupyter_code>print("Area:", (A+B)*C/2)<jupyter_output>Area: 12.5<jupyter_text>d) the area of the square that has side B.<jupyter_code>print("Area:", B**2)<jupyter_output>Area: 4.0<jupyter_text>e) the area of the rectangle that has sides A and B.<jupyter_code>print("Area:", A*B)<jupyter_output>Area: 6.0<jupyter_text>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”**.<jupyter_code>a, b, c = [float(x) for x in input("Enter a, b and c separated by commas: ").split(",")]
if a == 0:
    print("'a' should not be equal to zero!")
else:
    delta = (b**2) - (4*a*c)
    if delta < 0:
        print("no real roots")
    elif delta == 0:
        x = -b/(2*a)
        print(f"Root: {x}")
    else:
        #Reminder: sqrt(n) = n^(1/2)
        x1 = (-b+delta**0.5)/(2*a)
        x2 = (-b-delta**0.5)/(2*a)
        print(f"Roots: {x1}, {x2}")<jupyter_output>Enter a, b and c separated by commas:  2,1,-4<jupyter_text>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 commas. Then calculate and show the distance between these two points. (obs: $d=\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$)<jupyter_code>x1, y1 = [float(i) for i in input("Enter coordinates x1 and y1: ").split(",")]
x2, y2 = [float(i) for i in input("Enter coordinates x2 and y2: ").split(",")]
d = ((x1-x2)**2+(y1-y2)**2)**0.5
print(f"d = {d}")<jupyter_output>Enter coordinates x1 and y1:  3,5
Enter coordinates x2 and y2:  2,6<jupyter_text>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'**.<jupyter_code>x, y = [float(x) for x in input("Insert x e 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:
    print('q4')
elif y > 0:
    print('q2')
else:
    print('q3')<jupyter_output><empty_output><jupyter_text>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)<jupyter_code>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)
ccode = int(input("Enter the country calling code:"))
code_dict = {43:'Austria',
             32:'Belgium',
             359:'Bulgaria',
             385:'Croatia',
             357:'Cyprus',
             420:'Czech Republic',
             45:'Denmark',
             372:'Estonia',
             359:'Finland',
             33:'France',
            }
if ccode in code_dict.keys():
    print(code_dict[ccode])
else:
    print('Code not recognized.')<jupyter_output>Enter the country calling code: 43<jupyter_text>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.<jupyter_code>responses = [float(x) for x in input("Enter six values separated by commas: ").split(",")]

pos, total = 0, 0
for i in responses:
    total += i
    if i > 0:
        pos += 1
print(f"{pos} positive numbers")
print(f"Average = {total/6}")<jupyter_output>Enter six values separated by commas:  3,-4,98,1,-4,5<jupyter_text>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.<jupyter_code>N = int(input("Enter number N: "))
for i in range(1,N+1):
    if i%2==0:
        print(i**2)<jupyter_output>Enter number N:  20<jupyter_text>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'**.<jupyter_code>number = int(input('Enter an integer: '))
class1 = "even" if number%2 == 0 else "odd"
class2 = 'positive' if number == abs(number) else 'negative' 
if number == 0:
    print("Null")
else:
    print(class1, class2)<jupyter_output>Enter an integer:  23<jupyter_text>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.<jupyter_code>numbers = [int(x) for x in input("Enter any 6 integers: ").split(",")]
changed = True
while changed:
    changed = False
    for i in range(0,len(numbers)-1):
        if numbers[i] > numbers[i+1]:
            numbers[i],numbers[i+1] = numbers[i+1],numbers[i]
#           aux = numbers[i]                                        #alternative way of doing
#           numbers[i] = numbers[i+1]
#           numbers[i+1] = aux
            changed = True
print(' '.join([str(x) for x in numbers]))<jupyter_output>Enter any 6 integers:  4,6,1,4,6,9
{'fraction_non_alphanumeric': 0.134429781366949, 'fraction_numerical': 0.027181406342328147, 'mean_word_length': 4.258933195235629, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '21', 'dir': 'jupyter-structured-clean-dedup', 'id': '369360', 'license': 'Apache-2.0', 'n_tokens_mistral': 3517, 'n_tokens_neox': 3332, 'n_words': 1240, 'path': 'Assignments/Assignment_1_solutions.ipynb', 'repo_name': 'pavelcristina/Python_Course', 'size': '10154'}