-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.py
More file actions
33 lines (29 loc) · 693 Bytes
/
test.py
File metadata and controls
33 lines (29 loc) · 693 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
list1 = [10, 20, 30, 40, 50]
# reverse list
new_list = reversed(list1)
# iterate reversed list
for item in new_list:
print(item)
list1 = [10, 20, 30, 40, 50]
# get list size
# len(list1) -1: because index start with 0
# iterate list in reverse order
# star from last item to first
size = len(list1) - 1
for i in range(size, -1, -1):
print(list1[i])
for i in range(5):
print(i)
else:
print("Done!")
n = 5
# first number of sequence
start = 5
sum_seq = 0
# run loop n times
for i in range(0, n):
print(start, end="+")
sum_seq += start
# calculate the next term
start = start * 10 + 5
print("\nSum of above series is:", sum_seq)