-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.py
More file actions
69 lines (60 loc) · 1.91 KB
/
test2.py
File metadata and controls
69 lines (60 loc) · 1.91 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
# Print numbers from 1 to 100 using while loop
i = 1
while (i <= 100):
print(i)
i += 1
print("Finished printing numbers from 1 to 100")
# Print numbers from 100 to 1 using while loop
i = 100
while (i >= 1):
print(i)
i -= 1
print("Finished printing numbers from 100 to 1")
# Get the multiplication table of a number entered by the user using while loop
multiplication_table = int(input("Enter the number: "))
i = 1
while (i <= 10):
print(multiplication_table * i)
i += 1
print("Finished multiplication table of number", multiplication_table)
# For the below list, print the numbers using while loop
list = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
count = len(list)
i = 0
while (i < count):
print(list[i])
i += 1
print("Finished printing the list")
# search if number x exists in the list using while loop
list = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
search_number = int(input("Enter a number to search in the list: "))
j = 0
found = False
while j < len(list):
if search_number == list[j]:
print("Number exists in the list at index: ", j)
found = True
break
j += 1
if not found:
print("Number does not exist in the list")
print("Finished searching for the number in the list")
# For the below list, print the numbers using for loop
list = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
for item in list:
print(item)
print("Finished printing the list")
# search if number x exists in the list using for loop
list = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
search_number = int(input("Enter a number to search in the list: "))
found = False
for item in list:
if search_number == item:
print("Number exists in the list at index: ", list.index(item))
found = True
break
if not found:
print("Number does not exist in the list")
print("Finished searching for the number in the list")
while True:
print("This is an infinite loop. Press Ctrl+C to stop it.")