<jupyter_start><jupyter_text>![nerw_zad6_stopka.jpg](attachment:nerw_zad6_stopka.jpg) Programming Language With Numerical Methods<NAME>, Msc     Class 02. Flow Control  **Whenever you learn a new feature, you should try it out in interactive mode and make errors on purpose to see what goes wrong and what types of errors you run into.**  Conditional statements  Exercise 1Sort three numbers `a`, `b` and `c` defined by the user in an ascending order.<jupyter_code>a = float(input("a: "))
b = float(input("b: "))
c = float(input("c: "))
# one of the possible solutions
if a >= b and a >= c:
    if b >= c:
        print(a, b, c)
    else:
        print(a, c, b)
elif b >= a and b >= c:
    if a >= c:
        print(b, a, c)
    else:
        print(b, c, a)
elif b >= a: # c has to be the highest in this case
    print(c, b, a)
else:
    print(c, a, b)<jupyter_output><empty_output><jupyter_text>Exercise 2Given three values, `a`, `b` and `c`, containing the lengths of the edges, check if these values can create a triangle. If possible, decide what kind of triangle it is.<jupyter_code>a = float(input("a: "))
b = float(input("b: "))
c = float(input("c: "))
# to create a triangle, a + b > c & b+c > a & c+a >b

if a + b > c and b + c > a and c + a > b:
    print("triangle exists!")
    if a == b and a == c:
        print("equilateral triangle!")  # equilateral triangle is also an isosceles triangle 
    if a == b or b == c or c == a:
        print("isosceles triangle!")
    if abs(a**2 + b**2 - c**2) < 10**(-3) 
        or abs(a**2 + c**2 - b**2) < 10**(-3) 
        or abs(-a**2 + b**2 + c**2) < 10**(-3):
        print("right triangle!")  # a right triangle can be an isosceles triangle
else:
    print("a triangle with sides", a, b, "and", c, "does not exist")
    # three conditions above can be linked with elifs 
    # if we want a triangle to be only one thing at a time: either equilateral, right or isosceles<jupyter_output><empty_output><jupyter_text>Exercise 3Compute the roots of a quadratic equation ($P(x) = 0$), base on the polynomial coefficients `a`, `b` and `c` given by the user (or defined in code):$$P(x) = ax^2 + bx + c$$<jupyter_code>"""
1. Coefficients -> input -> float
2. Delta = b ** 2 - 4 * a *c
3. if Delta > 0: 
    -> two roots
       x1 = (-b+sqrt(Delta))/ (2*a)
       x2 = (-b-sqrt(Delta))/ (2*a)
   if Delta == 0:
       two roots (one root)
       x = -b/(2*a)
   if Delta < 0:
       no real solution
"""
import math
b = 100
a = math.sqrt(b)

a = input("a")
#if a.isnumeric():
    
import math

a = float(input("a"))
b = float(input("b"))
c = float(input("c"))

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

if delta > 0:
    x1 = (-b + math.sqrt(delta)) / (2 * a)
    x2 = (-b - math.sqrt(delta)) / (2 * a)
    print(x1, x2)
elif delta == 0:
    x1 = -b / (2 * a)
    print(x1)
else:
    print("No real roots!")<jupyter_output><empty_output><jupyter_text>Loops  Exercise 4Execute calculations for Celsius-Fahrenheit for every value in $$.<jupyter_code>for F in range(0, 101, 10):
    C = 5/9 * (F - 32)
    print(F, "Fahrenheit", C, "Celsius")<jupyter_output>0 Fahrenheit -17.77777777777778 Celsius
10 Fahrenheit -12.222222222222223 Celsius
20 Fahrenheit -6.666666666666667 Celsius
30 Fahrenheit -1.1111111111111112 Celsius
40 Fahrenheit 4.444444444444445 Celsius
50 Fahrenheit 10.0 Celsius
60 Fahrenheit 15.555555555555557 Celsius
70 Fahrenheit 21.11111111111111 Celsius
80 Fahrenheit 26.666666666666668 Celsius
90 Fahrenheit 32.22222222222222 Celsius
100 Fahrenheit 37.77777777777778 Celsius<jupyter_text>Exercise 5Write a `while` loop creating a list of odd numbers from 1 to `n`.<jupyter_code># define the starting value of i
i = 1
# define the limit n
n = 17
# defining an empty list to save the results
a = []

while i <= n:
    # check if i is even or odd; i is even if reminder from division by 2 is ==0, otherwise it's odd
    if i % 2 == 1:
        # if i is odd, print the value and add to a list
        print(i)
        a.append(i)
    # incrementing iterating variable
    i += 1

# print the results
a<jupyter_output>1
3
5
7
9
11
13
15
17<jupyter_text>Exercise 6Find prime numbers lower than 100.<jupyter_code>import math as m

n = 100

# we start the loop from 2, because 1 is either complex nor prime
for i in range(2, n):
    # find all the divisors lower than sqrt(n)
    for divisor in range(2, int(m.sqrt(i))+1):
        if i % divisor == 0:
            # i is divisible by some other number than itself and 1, so it's not a prime number
            #print(i, " is not a prime number")
            # we know it's not prime, so we can escape
            break
    else:
        # if we land here, it means, that we did not find the divisor for i
        print(i, "is a prime number")<jupyter_output>2 is a prime number
3 is a prime number
5 is a prime number
7 is a prime number
11 is a prime number
13 is a prime number
17 is a prime number
19 is a prime number
23 is a prime number
29 is a prime number
31 is a prime number
37 is a prime number
41 is a prime number
43 is a prime number
47 is a prime number
53 is a prime number
59 is a prime number
61 is a prime number
67 is a prime number
71 is a prime number
73 is a prime number
79 is a prime number
83 is a prime number
89 is a prime number
97 is a prime number
{'fraction_non_alphanumeric': 0.11288483466362599, 'fraction_numerical': 0.06442417331812998, 'mean_word_length': 3.039140445126631, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '435183', 'license': 'MIT', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1828, 'n_words': 771, 'path': '_exercise_answers/LNM_class_02-solved.ipynb', 'repo_name': 'Fikrahelhifzi/Python_Numerical_Method', 'size': '5274'}