---
# System prepended metadata

title: Untitled

---


**Table employees**

| EmpId | FullName | ManagerId | DateOfJoining | City |
|-------|--------------|-----------|---------------|------------|
| 121 | John Snow | 321 | 01/31/2014 | Toronto |
| 321 | Walter White | 986 | 01/30/2015 | California |
| 421 | Kuldeep Rana | 876 | 27/11/2016 | New Delhi |
| 450|BLAZEJ FIDEREK | | | |

**Table salaries**
| EmpId | Project | Salary |
|-------|---------|--------|
| 121   | P1      | 8000   |
| 321   | P2      | 10000  |
| 421   | P1      | 12000  |




1. Write an SQL query to fetch project-wise count of employees.

2. Write an SQL query to list names of all employes with salary higher than 9000


```sql
SELECT Project, COUNT(*)
FROM salaries
GROUP BY Project;

SELECT a.FullName, b.Salary
FROM employees a
LEFT JOIN salaries b on a.EmpId = b.EmpID and b.Salary > 9000
```






You are given a random number generator - Find number PI

``` python3
import random
def rand_coords():
    return [random.random(),random.random()]

points_in_circle = 0
for i in range(10000):
    coords = rand_coords()
    if coords[0]**2+coords[1]**2 <=1:
        points_in_circle +=1
    
print(4*points_in_circle/10000)

```

Print all the prime numbers <= 10000

n = 10000
from math import sqrt

start = range(1,n)
non_prime = []
for i in range(2,sqrt(n)):
    non_prime.extend(range(2*i,10000, i))

non_prime = set(non_prime)
prime = set(start) - non_prime


is_prime = [True for i in range(2, n)]
for i in range(2,sqrt(n)):
    if is_prime[i]:
        for j in range(2*i, n, i):
            is_prime[j] = False
            
    
----


We will see N=100 job candidates whose levels are random between 0 and 10. We see the candidates one-by-one, and after seeing each candidate, we have to make a decision on the spot whether to hire this candidate or not. This decision is irrevocable and we cannot change our mind later! Our policy for selecting a candidate is the following:
* Reject the first R candidates, for some value R.
* Then hire the first one we see that is better than the best among the first R.

Write a program that finds the value of R that is maximizing the probability to hire the best out of the N candidates_ using simulations.


```python3
import random

N = 100


R = 10
found_highest = 0
for i in range(10000):
    sample = [random.random(10) for _ in range(N)]
    high_reference = max(sample[:R])
    best_candidate = max(sample)
    for j in range(R,N):
        if sample[j] > high_reference:
            if sample[j] == best_candidate:
                found_highest +=1
            break
            
print(found_highest / 10000)
    


```

