Exercise 1:
for i in [1,2,3,4,5,6,7,8,9]:
print(i,"* 9 = ",i*9)
Exercise 2:
number = int(input("Please input an integer greater than 1000:"))
sum = 0;
if number > 1000:
for i in range(number):
if i%7 == 0:
sum += i
print("sum of all the numbers can be divided by 7 less than ", number," is: ",sum)
else:
print("Invalid input")
Exercise 2, another way:
n = int(input("Please input a integer greater than 1000")
sum = 0
for i in range(0,n,7):
sum += i
print(sum)
Homework:
result = 0
for i in range(1000):
if i%2 == 0:
result -= i
else:
result += i
print("1-2+3-4+....+999=",result)
[…] 3| |____Unit 19 while loop| |____Unit 20 while loop practice| |____Unit 21 guess number game| |____Unit 22 for loop| |____Unit 23 break and continue| |____Unit 24 nested loop| |____Unit 25 Pycharm and turtle| […]