Starting from:

$30

COL100 Assignment 4 -Solved

1 Divisible Factorial 
Write a program to calculate the divisible factorial of a number using loops. The difference here is 
that you only multiply numbers divisible by certain numbers. Thus the divisible factorial should 
be multiplication of numbers which are divisible by a specific number x. You can use any loop in 
your program, including for loops, while loops, and do-while. Since a normal factorial would be 
n! = 1 ∗ 2 ∗ 3...(n − 1) ∗ n but, the expected divisible factorial would be n! = 2 ∗ 4 ∗ 6 ∗ 8...(n − 1) ∗ n if 
the dividing number given is 2 and would be n! = 3 ∗ 6 ∗ 9 ∗ 12...(n − 1) ∗ n if the dividing number is 3. 
Input: Your program should prompt the user to enter the numbers, named a and x.Output: Print the factorial of a. 
Example 1: 
INPUT: 
1 1 
2 1 
OUTPUT: 
1 1.00 
EXPLANATION: 
The factorial of 1 is equal to 1 
Example 2: 
INPUT: 
1 5 
2 2 
OUTPUT: 
1 8.00 
EXPLANATION: 
The factorial of 5 is equal to 8. Explanation: 5! = 5*4*3*2*1. Only 4 and 2 are divisible by 2. Thus 
the final answer is 5! = 4*2 = 8 
Example 3: 
INPUT: 
1 10 
2 5 
OUTPUT: 
1 50.00 
EXPLANATION: 
The factorial of 10 is equal to 50 because 5, 10 are only divisible by 5. Usually 10! = 1 ∗ 2 ∗ 3 ∗ 4 ∗ 5 ∗ 
6 ∗ 7 ∗ 8 ∗ 9 ∗ 10 but we want to multiply numbers divisible by 5 thus 10! = 5 ∗ 10 
Example 4: 
INPUT: 
1 6 
2 17 
OUTPUT: 
1 1.00 
EXPLANATION: 
Here the answer is 1 as none of the numbers in the factorial are divisible by the specified number. 
Usually 6! = 1 ∗ 2 ∗ 3 ∗ 4 ∗ 5 ∗ 6 but none of these are divisible by 17 and the answer would be 6! = 1. 
2 Pattern Printing - 
Write a python program which takes a positive number as input and print the pattern as shown in the 
test cases (line spacing doesn’t matter). The input indicates the number of lines to be printed. 
The pattern is a hollow square and each line must have the same number of characters i.e. the lines 
2apart from the first and the end will have spaces in between. The number of lines and the number of 
characters in a line are the same. 
Note: Here it looks more like a rectangle due to improper line spacing and line width. You need 
not worry about line spacing or width in the output. 
Example 1: 
INPUT: 
1 5 
OUTPUT: 
1 ***** 
2 * * 
3 * * 
4 * * 
5 ***** 
Example 2: 
INPUT: 
1 6 
OUTPUT: 
1 ****** 
2 * * 
3 * * 
4 * * 
5 * * 
6 ****** 
3 Pattern Printing
Write a python program which takes a positive number as input and print the pattern as shown in the 
test cases. Each line has an odd number of stars and the number of lines where the input increases is 
equal to n where n is the input given. 
Example 1: 
INPUT: 
1 3 
OUTPUT: 
1 * 
2 *** 
3 ***** 
4 *** 
5 * 
Example 2: 
INPUT: 
1 4 
OUTPUT: 
1 * 
2 *** 
3 ***** 
34 ******* 
5 ***** 
6 *** 
7 * 
Example 3: 
INPUT: 
1 5 
OUTPUT: 
1 * 
2 *** 
3 ***** 
4 ******* 
5 ********* 
6 ******* 
7 ***** 
8 *** 
9 * 
4 Pattern Printing
Write a python program which takes a positive number as input and print the pattern as shown in the 
test cases. The number of characters in a line and the number of lines are equal to each other and to 
the input given. 
Note: The input number’s range is 1-26 only. The ouput must be in capital letters and outputs as 
aaa or bbb would not be accepted. 
Example 1: 
INPUT: 
1 3 
OUTPUT: 
1 AAA 

BB 


Example 2: 
INPUT: 
1 4 
OUTPUT: 
1 AAAA 

BBB 

CC 


Example 3: 
INPUT: 
1 5 
OUTPUT: 
41 AAAAA 

BBBB 

CCC 

DD 


Example 4: 
INPUT: 
1 1 
OUTPUT: 
1 A 
5 Pattern Printing
Write a python program which takes a positive number as input and print the pattern as shown in the 
test cases. The given input indicates the number of lines to be printed. Note that there is a space after 
each integer in a line. 
Example 1: 
INPUT: 
1 3 
OUTPUT: 
1 1 
2 2 3 
3 4 5 6 
Example 2: 
INPUT: 
1 4 
OUTPUT: 
1 1 
2 2 3 
3 4 5 6 
4 7 8 9 10 
Example 3: 
INPUT: 
1 5 
OUTPUT: 
1 1 
2 2 3 
3 4 5 6 
4 7 8 9 10 
5 11 12 13 14 15 
6 Calculate the Terms of given Series
Calculate the terms of a series considering the series be: (−
1)

x2

, and some terms of the series be: 
−1 
x2 
, x1
4 , −

x6 
, x1
8 ... 
5Input: Two numbers for x and n, where x is the value and n is the number of terms you have to print. 
Output: Printing the terms of the given series. Don’t print the sum of the terms. 
Note: You may use the pow() function or the math.pow() function to find the powers. 
Example 1: 
INPUT: 
1 1 
2 3 
OUTPUT: 
1 -1.00 
2 1.00 
3 -1.00 
EXPLANATION: 
The first term of the given series (−
1)

x2

is -1 on putting n=1 and the second is 1 on putting n=2 and 
Similarly the third term is -1 on putting n=3. 
Example 2: 
INPUT: 
1 3 
2 2 
OUTPUT: 
1 -0.11 
2 0.01 
EXPLANATION: 
Here x = 3 and n = 2 putting them in the series gives the following output. 
Example 3: 
INPUT: 
1 -2 
2 2 
OUTPUT: 
1 -0.25 
2 0.06 
Please take a note of the sign of the number since any term also includes the sign. 
6

More products