-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoopingStat.py
51 lines (42 loc) · 991 Bytes
/
LoopingStat.py
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
#FOR LOOP
#For loop for printing list items
languages = ['Swift', 'Python', 'Go']
# access elements of the list one by one
for i in languages:
print(i)
#Print the string
a = "Language"
for i in a:
print(i)
#print numbers from 0-20
for i in range(21):
print(i)
#setting a range
for i in range(15, 21):
print(i)
#printing all items in the list and executing else part
a = [1, 2, 3, 4, 5]
for i in a:
print(i)
else:
print("no elements")
#WHILE LOOP
#print even numbers from user input
num = int(input("Enter a number: "))
while num >= 0:
if ( num % 2 == 0 ):
print("\n", num, end='')
num = num - 1
# Calculate the sum of numbers until user enters 0
number = int(input('Enter a number: '))
total = 0
# iterate until the user enters 0
while number != 0:
total += number
number = int(input('Enter a number: '))
print('The sum is', total)
#Infinite loop
age = 32
# the test condition is always True
while age > 18:
print('You can vote')