Programming Fourth Batch (Iteration) 30-44
Programming Fourth Batch (Iteration) 30-44
Fourth Batch
Iteration / loop
Notes:
• You will only use While Loop for all these questions solutions, for loop is not allowed.
• You will not treat a number as a string in any of the question.
• Do not use a built In function without permission.
• If a program requires you should test it multiple times to make sure the complete
functionality of the code.
•
Task # 30 : Write a program to print all numbers from zero to 20 with a while loop.
Task # 31 : Write a program to input 10 numbers and print the average of these 10 numbers.
Task # 32 : We are writing a program to print all odd numbers between 1 and 20 inclusive.
Task # 33 : Write a program to input a number and print the multiplication table of this number in the
given format from 1 to 12.
1*7=7
2 * 7 = 14
12 * 7 = 84
Task # 35 : Write a program to input 2 numbers A,B. Find the product of these numbers without using
the multiplication operator.
if A = 5 , and B = 4 output 20
Task 36 : Write a program to input two numbers, B and P. Find B raised to the power of P. For example if
B = 3, and P = 4 your output should be 81. You cannot use the power (**) operator in python and (^)
operator in pseudocode.
Task # 37 : Write a program to input a number, (no fixed digits) , print the sum of its digits.
92 = 11 is the sum
Task # 38 : Input characters and stop when a full stop is entered. Print the number of vowels and
consonants entered. Do not accept any non-characters and give an error if entered. Accept both lower
case and upper case alphabets.
Task # 39 : Input two numbers A and B. Find the product of all numbers between A and B inclusive.
A = 2, B = 5
2 * 3 * 4 * 5 = 120
Task # 40: Input a denary number and convert and print its binary equivalent. You cannot put any limit,
your logic must work for any positive number. The resultant binary number may be a string but the
input must be a denary number and not a string. You must read the modulus 2 method of converting
denary number to binary from your book.
Task # 41: Input numbers and stop when zero is entered. Print the largest and smallest positive number
entered by the user. Print the percentage of negative numbers entered. Zero is the rogue value that will
stop your program.
Task # 42: Collatz Sequence. Start with any number but you will reach to 1. If the number is Even the
next term is the number Divide by two if the number is Odd then the next term is 3*N + 1. Print the
sequence. Start will be input by user. Given below is an example of Collatz sequence that started from
seven.
Input : 7
7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8 ,4 ,2 ,1
Learn how to print multiple time in the same line. Your google search string will be
n1 = 9, n2 = 20
11+13+14+15+16+17+19
Task # 44 : Input a number and print if it is a Prime number or not. A Prime number is the one that is
only divisible by 1 and itself. Your program should work with logically any positive number(no limit).