0% found this document useful (0 votes)
19 views2 pages

IterationTasks For

The document outlines 8 tasks that involve using for loops to print numbers, strings, times tables, averages, combinations, and binary to decimal conversions. The tasks get progressively more complex and cover a range of programming concepts involving for loops.

Uploaded by

reflex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

IterationTasks For

The document outlines 8 tasks that involve using for loops to print numbers, strings, times tables, averages, combinations, and binary to decimal conversions. The tasks get progressively more complex and cover a range of programming concepts involving for loops.

Uploaded by

reflex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Iteration tasks: for

Task 1 - Numbers
Write a program that uses for to display the numbers 1 to 100 inclusive.

Task 2 - Hello again!


Write a program that uses for to print “Hello again!” 1000 times

Task 3 - 7 Times Table


Write a program that uses for to print every line of the 7 times table, so it looks something like the example
below. (Hint: use a variable and print it twice, once unchanged, and once multiplied by 7 using the * operator.
In between print " x ". Remember you can use commas to separate several items being printed on the same
line)

1 x 7 = 7
2 x 7 = 14
3 x 7 = 21
4 x 7 = 28
...
12 x 7 = 84

Task 4 - Average of 10 numbers


Write a program that will ask for 10 numbers, adds them together, and prints the average of the 10 numbers at
the end.

Task 5 - All the times tables


Write a program that will print every times table from 1 to 12. (Hint: use your program from task 3, and think
about how you will use two loops)

Task 6 - Bits
Write a program that will print the number of combinations you can have with a certain amount of bits, as in the
example below. Show all the combinations up to 32 bits (Hint: 2**3 is 8 )

1 bit(s) gives 2 combinations


2 bit(s) gives 4 combinations
3 bit(s) gives 8 combinations
4 bit(s) gives 16 combinations
...
32 bit(s) gives 4294967296 combinations

Task 7 - Bits
Extend the program from Task 6 so that it if the number of bits is a multiple of 8, it will display how many bytes
that is, e.g.

32 bit(s) gives 4294967296 combinations


That is 4 bytes

(continues...)
By H. Mothada. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Task 8 - To Decimal

Write a program that uses a for loop to produce the output in the screenshot below.

Hint 1: print (10 * '@') will print 10 @ symbols.

Hint 2: 11111111 = 27

By H. Mothada. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You might also like