Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: September 2021

Thursday, September 30, 2021

Python program to enter 10 numbers in list and how many of them are ending with 5: Python

PYTHON PROGRASM FOR BEGINNERS

SCHOOL LEVEL PROGRAMMING

Write a Python program to enter 10 numbers in list and how many of them are ending with 5. Display all the numbers ending with 5 and the total of such numbers. If there are no numbers ending with 5 display "NIL".

Both Java and Python codes are given below.

In this program you will learn:

i. Taking input

ii. Adding numbers to list using append() method

iii. for loop

iv. using boolean variables

v. using if statements

PYTHON CODE

#Python program to enter 10 numbers in list and how many of them are ending with 5

numberList = []
for i in range(10):
    print("Enter the element at the position: ",i+1)
    numberList.append(int(input("Enter the value:")))
counter = 0
flagEndingFive = False
print("Numbers ending with 5 is/are:")
for i in numberList:
    if i%10 == 5:
        counter +=1
        flagEndingFive = True
        print(i)
if flagEndingFive == False:
    print("NIL")
print("Total number of numbers ending with 5 = ",counter)


JAVA CODE

import java.util.Scanner;
public class NumbersEndingFive{
       public static void main(String[] args) {
        int[] numberList;
        boolean flagEndingFive = false;
        int counter = 0;
        Scanner in = new Scanner(System.in);
        numberList = new int[10];
        for(int i = 0i10i++){
               System.out.println("Enter the element at the position:"+(i+1));
               numberList[i] = in.nextInt();
       }
       System.out.println("Numbers ending with 5 is/are:");
       for(int i = 0i10i++) 
              if(numberList[i]%10 == 5) {
                     flagEndingFive = true;
                     counter++;
                     System.out.println(numberList[i]);
              }
       if(!flagEndingFive)
              System.out.println("NIL");
       System.out.println("Total number of numbers ending with 5 = "+counter);
       in.close();
       }
}

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021: QUESTION 3 MOBIUS FUNCTION

Question 3
A MOBIUS function M(N) returns the value -1 or 0 or 1 for a natural number (N) by the following conditions are defined :
When,
M ( N ) = 1 if N=1.
M ( N ) = 0 if any prime factor of N is contained more than once.
M ( N ) = ( -1 )P if N is the product of ‘P’ distinct prime factors.

Write a program to accept a positive natural number (N) and display the MOBIUS result with proper message. Design your program which will enable the output in the format given below:

Sample 1
INPUT:78
OUTPUT: 78 = 2 x 3 x 13
NUMBER OF DISTINCT PRIME FACTORS = 3
M(78) = -1

Sample 2
INPUT:34
OUTPUT: 34 = 2 x 17
NUMBER OF DISTINCT PRIME FACTORS = 2
M(34) = 1

Sample 3
INPUT:12
OUTPUT: 12 = 2 x 2 x 3
DUPLICATE PRIME FACTORS
M(12) = 0

Sample 4
INPUT:1
OUTPUT: 1 = 1
NO PRIME FACTORS
M(1) = 1

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021

ENTER A POSITIVE INTEGER:

Wednesday, September 29, 2021

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021 : QUESTION 2 STRING

ISC COMPUTER SCIENCE PRACTICAL SPECIMEN PAPER 2021

Try out with different inputs

ENTER THE SENTENCE:


In most of the problems based on Strings in ISC Computer Science Practical it is common to test the validity of the sentence. In most of the cases the statement is terminated by either '.', '?' or '!' and are separated by a single blank and have only upper case characters or only lower case characters.
                            In most of my programs I have checked only for the terminating characters and the case for the characters. But in this program I have tested that the word must be separated by only one blank as well as the for the terminating characters. This will serve the blue print of all your programs involving strings. Also remember extracting words from a string forms a vital tradition of ISC practical programs and I have used this logic in almost all my programs under the method name "wordExtractor()". You should be familiar with all the above mention methods very well! Any comment is always welcome :)