Write a program that prints out a list of the integers from 1 to 20 and their squares and also count all the squared numbers that are divided by 5. The output should look like this: 1----1 2----4 3----9 And so on.. Total count of Squared number divisible by 5 is : 4
Answers
Answered by
8
Language:
Python
Program:
count=0
for i in range(1,21):
print(f"{i} ---- {i * * 2}")
count+=1 if i * * 2%5==0 else 0
print(f"Total count of Squared number divisible by 5 is: {count}")
Output:
1 ---- 1
2 ---- 4
3 ---- 9
4 ---- 16
5 ---- 25
6 ---- 36
7 ---- 49
8 ---- 64
9 ---- 81
10 ---- 100
11 ---- 121
12 ---- 144
13 ---- 169
14 ---- 196
15 ---- 225
16 ---- 256
17 ---- 289
18 ---- 324
19 ---- 361
20 ---- 400
Total count of Squared number divisible by 5 is: 4
Explanation:
- Count acts as a counter for numbers divisible by 5. i * * 2 returns the number raised tot he power of 2 and %5==0 checks if the number when divided by 5 returns 0 or not. If yes counter increases by 1 if not then 0 is added.
- Using f with print makes it connect the text written within {} to variables outside. For example : a= 5, print(f"{a}"} will print 5.
Attachments:
Attachments:
Answered by
2
Answer:
Refer this ATTACHMENT
Mark me as brainlist
Attachments:
Similar questions
Math,
1 month ago
Geography,
1 month ago
India Languages,
3 months ago
Math,
10 months ago
Physics,
10 months ago