-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercises 4.py
More file actions
80 lines (60 loc) · 1.41 KB
/
Copy pathExercises 4.py
File metadata and controls
80 lines (60 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#phase 1
n = 1
while n < 1000:
if n % 3 == 0:
print(str(n))
n = n + 1
#phase 2
n = float(input("Enter the value in inches"))
while n != 0:
if n < 0:
break
print(f"centimeters {n*2.54:0.2f}")
n = float(input("Enter the value in inches"))
print("Incorrect value")
#phase 3
nums = []
while True:
num = input("Enter a number: ")
if num == "":
break
nums.append(num)
largest = max(nums)
smallest = min(nums)
print("Largest number is", largest)
print("Smallest number is", smallest)
#phase 4
import random
target_num, guess_num = random.randint(1, 10), 0
while target_num != guess_num:
guess_num = int(input("Guess a number between 1 and 10 : "))
if guess_num > target_num:
print("Too high")
if guess_num < target_num:
print("Too low")
print("Correct")
#phase 5
count = 0
while count < 5:
username = input("Enter username: ")
password = input("Enter password: ")
if password == "Nadim" and username == "Ahmed":
print("Access granted")
count = 5
else:
print("Access denied. Try again.")
count += 1
#phase 66
import random
input_num = int(input("Enter numbers"))
n = 0
N = 0
for i in range(input_num**2):
x = random.uniform(-1, 1)
y = random.uniform(-1, 1)
origin_dist = x ** 2 + y ** 2
if origin_dist < 1:
n += 1
N += 1
pi = 4 * n / N
print(" Estimation of Pi=", pi)