1. Python program to find the union of two lists.

#define two lists
list1 = [10,20,30,40]
list2 = [30,40,50,60]
# find union using set
union_list = list(set(list1 + list2))
# display the result
print("Union of the two lists:",union_list)

Output 1

Union of the two lists: [40, 10, 50, 20, 60, 30]

2. Python program to find the intersection of two lists.

#define two lists
list1 = [50,60,70,80,100]
list2 = [70,80,90,100]
list3 = [10,100]
# find intersection using list comperhension
intersection = [ i for i in list2 if i in list1 and i in list3]
# display the result
print("intersection of the two lists:",intersection)

Output 2

intersection of the two lists: [100]

3. Using for loop, print a table of Celsius/Fahrenheit equivalences. Let e be the Celsius temperatures ranging from 0 to 100, for each value of c, print the corresponding Fahrenheit temperature.

# python program to print celsius ro fahrenheit table
print("celsius | fahrenheit")
print("-------------------")
for c in range(0,101):
    f = (c * 9/5) + 32
    print(f"{c:7} | {f:10.2f}")

Output 3

celsius | fahrenheit
------------------- 
      0 |      32.00
      1 |      33.80
      2 |      35.60
      3 |      37.40
      4 |      39.20
      5 |      41.00
      6 |      42.80
      7 |      44.60
      8 |      46.40
      9 |      48.20
     10 |      50.00
     11 |      51.80
     12 |      53.60
     13 |      55.40
     14 |      57.20
     15 |      59.00
     16 |      60.80
     17 |      62.60
     18 |      64.40
     19 |      66.20
     20 |      68.00
     21 |      69.80
     22 |      71.60
     23 |      73.40
     24 |      75.20
     25 |      77.00
     26 |      78.80
     27 |      80.60
     28 |      82.40
     29 |      84.20
     30 |      86.00
     31 |      87.80
     32 |      89.60
     33 |      91.40
     34 |      93.20
     35 |      95.00
     36 |      96.80
     37 |      98.60
     38 |     100.40
     39 |     102.20
     40 |     104.00
     41 |     105.80
     42 |     107.60
     43 |     109.40
     44 |     111.20
     45 |     113.00
     46 |     114.80
     47 |     116.60
     48 |     118.40
     49 |     120.20
     50 |     122.00
     51 |     123.80
     52 |     125.60
     53 |     127.40
     54 |     129.20
     55 |     131.00
     56 |     132.80
     57 |     134.60
     58 |     136.40
     59 |     138.20
     60 |     140.00
     61 |     141.80
     62 |     143.60
     63 |     145.40
     64 |     147.20
     65 |     149.00
     66 |     150.80
     67 |     152.60
     68 |     154.40
     69 |     156.20
     70 |     158.00
     71 |     159.80
     72 |     161.60
     73 |     163.40
     74 |     165.20
     75 |     167.00
     76 |     168.80
     77 |     170.60
     78 |     172.40
     79 |     174.20
     80 |     176.00
     81 |     177.80
     82 |     179.60
     83 |     181.40
     84 |     183.20
     85 |     185.00
     86 |     186.80
     87 |     188.60
     88 |     190.40
     89 |     192.20
     90 |     194.00
     91 |     195.80
     92 |     197.60
     93 |     199.40
     94 |     201.20
     95 |     203.00
     96 |     204.80
     97 |     206.60
     98 |     208.40
     99 |     210.20
    100 |     212.00

4. Using while loop, produce a table of sins, cosines and tangents. Make a variable x

in range from 0 to 10 in steps of 0.2. For each value of x, print the value of sin(x), cos(x) and tan(x).

# python program to print sin, cos and tan values using while loop
import math
x = 0.0
print("  x sin(x)    cos(x)    tan(x)   ")
print("---------------------------------")
while x <= 10:
    sin_val = math.sin(x)
    cos_val = math.cos(x)
    tan_val = math.tan(x)
    print(f"{x:4.1f}  {sin_val:7.4f}  {cos_val:7.4f}   {tan_val:7.4f}")
    x += 0.2

Output 4

 x sin(x)    cos(x)    tan(x)   
---------------------------------
 0.0   0.0000   1.0000    0.0000
 0.2   0.1987   0.9801    0.2027
 0.4   0.3894   0.9211    0.4228
 0.6   0.5646   0.8253    0.6841
 0.8   0.7174   0.6967    1.0296
 1.0   0.8415   0.5403    1.5574
 1.2   0.9320   0.3624    2.5722
 1.4   0.9854   0.1700    5.7979
 1.6   0.9996  -0.0292   -34.2325
 1.8   0.9738  -0.2272   -4.2863
 2.0   0.9093  -0.4161   -2.1850
 2.2   0.8085  -0.5885   -1.3738
 2.4   0.6755  -0.7374   -0.9160
 2.6   0.5155  -0.8569   -0.6016
 2.8   0.3350  -0.9422   -0.3555
 3.0   0.1411  -0.9900   -0.1425
 3.2  -0.0584  -0.9983    0.0585
 3.4  -0.2555  -0.9668    0.2643
 3.6  -0.4425  -0.8968    0.4935
 3.8  -0.6119  -0.7910    0.7736
 4.0  -0.7568  -0.6536    1.1578
 4.2  -0.8716  -0.4903    1.7778
 4.4  -0.9516  -0.3073    3.0963
 4.6  -0.9937  -0.1122    8.8602
 4.8  -0.9962   0.0875   -11.3849
 5.0  -0.9589   0.2837   -3.3805
 5.2  -0.8835   0.4685   -1.8856
 5.4  -0.7728   0.6347   -1.2175
 5.6  -0.6313   0.7756   -0.8139
 5.8  -0.4646   0.8855   -0.5247
 6.0  -0.2794   0.9602   -0.2910
 6.2  -0.0831   0.9965   -0.0834
 6.4   0.1165   0.9932    0.1173
 6.6   0.3115   0.9502    0.3279
 6.8   0.4941   0.8694    0.5683
 7.0   0.6570   0.7539    0.8714
 7.2   0.7937   0.6084    1.3046
 7.4   0.8987   0.4385    2.0493
 7.6   0.9679   0.2513    3.8523
 7.8   0.9985   0.0540   18.5068
 8.0   0.9894  -0.1455   -6.7997
 8.2   0.9407  -0.3392   -2.7737
 8.4   0.8546  -0.5193   -1.6457
 8.6   0.7344  -0.6787   -1.0820
 8.8   0.5849  -0.8111   -0.7211
 9.0   0.4121  -0.9111   -0.4523
 9.2   0.2229  -0.9748   -0.2286
 9.4   0.0248  -0.9997   -0.0248
 9.6  -0.1743  -0.9847    0.1770
 9.8  -0.3665  -0.9304    0.3939
10.0  -0.5440  -0.8391    0.6484