Instagram
youtube
Facebook
Twitter

Python Chef and Chapters program Codechef solution

          Python Chef and Chapters program Codechef solution

Problem

This semester, Chef took X courses. Each course has Y units, and each unit has Z chapters in it.

Find the total number of chapters Chef has to study this semester.

Input Format

  • The first line will contain T, the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing three space-separated integers X,Y, and Z.

Output Format

For each test case, output in a single line the total number of chapters Chef has to study this semester.

Constraints:

  • 1≤T≤1000
  • 1<=X,Y,Z<=1000

Sample Input:

1 1 1

2 1 2

1 2 3

Sample Output:

1

4

6

 

Explanation:

Test case 1: There is only one course with one unit. The unit has one chapter. Thus, the total number of chapters is 1.

Test case 2: There are 2 courses with 1 unit each. Thus, there are two units. Each unit has two chapters. Thus, the total number of chapters is 4.

Test case 3: There is only 1 course with 2 units. Each unit has three chapters. Thus, the total number of chapters is 6.

Solution:

n=int(input(“Enter the number of terms needed: “))

for i in range(n):

    X,Y,Z=map(int,input(“Enter courses, units and chapters: “).split())

    print(X*Y*Z)

Steps to solve this problem:

  1. Ask the user to enter a number of terms.
  2. In the loop, ask the user to enter courses, units, and chapters, and using the map() function, get iterator objects and store them in X, Y, and Z, respectively.
  3. Calculate X*Y*Z and print the result.