forked from ava11235/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.py
More file actions
51 lines (40 loc) · 654 Bytes
/
Copy pathloops.py
File metadata and controls
51 lines (40 loc) · 654 Bytes
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
#loops
>>> sum = 0
>>> i = 1
>>> n = 5
>>> while i <= n:
sum = sum + i
i = i + 1
>>> i
6
>>> sum
15
>>> sum = 0
>>> i = 1
>>> while i < 2 * n:
sum = sum + 1
i = i + 2
>>> sum
5
>>> sum = 0
>>> x = int(input("Enter a number. 999 to exit "))
Enter a number. 999 to exit 3
>>> while x != 999:
sum = sum + x
x = int(input("Enter a number. 999 to exit "))
Enter a number. 999 to exit 1
Enter a number. 999 to exit 2
Enter a number. 999 to exit 3
Enter a number. 999 to exit 999
>>> sum
9
>>> count = 0
>>> n = 4
>>> while n > 1:
n = n // 2
count = count + 1
>>> n
1.0
>>> count
2
>>>