for i in range(10):
print(i + 1)
###
# start = 2
# end = 11
# step = + 2
for i in range(2, 11, 2):
print(i)
###
# start = 10
# end = 0
# step = -1
for i in range(10, 0, -1):
print(i)
###
"""
your task is to print the multiples of 5 from 50 to 100.
What is your loop control variable? What is its start value,
continuing condition, and update action?
Once you've determined what these values are, use them to write
a short program that does this task.
"""
# end
# start, end
# start, end, step
for number in range(50, 105, 5):
print(number)
###
total = 0
for num in range(1, 11):
total = total + num
print("Current:", total)
print("Result:", total)
###
s = ""
for i in range(10, 100):
s = s + str(i) + "-"
print(s)
###
"""
11 # i = 1, spaces = 3, *s = 0
2**2 # i = 2, spaces = 2, *s = 2
3****3 # i = 3, spaces = 1, *s = 4
4******4 # i = 4, spaces = 0, *s = 6
*s
#1 -> 0 = (1-1)*2
#2 -> 2 = (2-1)*2
#3 -> 4 = (3-1)*2
#4 -> 6 = (4-1)*2
*s -> (i-1)*2
spaces
#1 -> 3 = (4-1)
#2 -> 2 = (4-2)
#3 -> 1 = (4-3)
#4 -> 0 = (4-4)
spaces -> (n-i)
"""
n = 20
# start = 1
# end = n + 1
# update = +1
# Approach 1: put asterisks in string
asterisks = ""
for i in range(1, n+1):
print(str(i) + asterisks + str(i))
asterisks += "**"
# Approach 2: generate asterisks based on number
for i in range(1, n+1):
spaces = " " * (n - i)
asterisks = "*" * ((i-1)*2)
print(spaces + str(i) + asterisks + str(i))
###
i = 1
while i <= 10:
print(i)
i = i + 1
###
num = 1
while num <= 100:
print(num)
num = num * 2
###
count = 0
number = 83276541
while number > 0:
number = number // 10
count = count + 1
print(count)