COL100 Assignment 4 Solved

30.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

Rate this product

1 Divisible Factorial (5 marks) (In lab Component)

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

2

OUTPUT: 1 1.00

EXPLANATION:
The factorial of 1 is equal to 1

Example 2:

INPUT: 1

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

2

OUTPUT: 1 50.00

EXPLANATION:
Thefactorialof10isequalto50because5,10areonlydivisibleby5. Usually10!=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

2

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 – 1 (5 marks) (In Lab Component)

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

1 1

5 2

10 5

6 17

2

apart 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: 15

OUTPUT:

1 2 3 4 5

INPUT: 16

OUTPUT:

1 2 3 4 5 6

INPUT: 13

OUTPUT:

1 2 3 4 5

INPUT: 14

OUTPUT:

1 2 3

***** ** ** ** *****

Example 2:

****** ** ** ** ** ******

3 Pattern Printing – 2 (10 Marks)

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:

*
***
*****
***
*

Example 2:

*
*** *****

3

*******
*****
***
*

4 5 6 7

INPUT: 15

OUTPUT:

1 2 3 4 5 6 7 8 9

Example 3:

*
***
*****
*******
*********
*******
*****
***
*

4 Pattern Printing – 3 (10 Marks)

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: 13

OUTPUT:

1 2 3

INPUT: 14

OUTPUT:

1 2 3 4

INPUT: 15

OUTPUT:

AAA BB C

Example 2:

AAAA BBB CC D

Example 3:

4

AAAAA
 BBBB
  CCC
   DD
    E

1 2 3 4 5

INPUT: 11

OUTPUT: 1A

5 Pattern Printing – 4 (15 Marks)

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: 13

OUTPUT:

1 2 3

INPUT: 14

OUTPUT:

1 2 3 4

INPUT: 15

OUTPUT:

1 2 3 4 5

Example 4:

1
23 456

Example 2:

1
23 456
7 8 9 10

Example 3:

1
23
456
7 8 9 10
11 12 13 14 15

6 Calculate the Terms of given Series (15 Marks)

(−1)n
Calculate the terms of a series considering the series be: x2n , and some terms of the series be:

−1, 1 ,−1, 1 … x2 x4 x6 x8

5

Input: 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

2

OUTPUT:

1 2 3

INPUT: 1

2

OUTPUT: 1

2

INPUT: 1

2

OUTPUT: 1

2

1 3

-1.00
1.00
-1.00

EXPLANATION:
The first term of the given series x2n Similarly the third term is -1 on putting n=3.

(−1)n

is -1 on putting n=1 and the second is 1 on putting n=2 and

Example 2:

3 2

-0.11 0.01

EXPLANATION:
Here x = 3 and n = 2 putting them in the series gives the following output.

Example 3:

-2 2

-0.25 0.06

Please take a note of the sign of the number since any term also includes the sign.

6

  • A4-ifrhjw.zip