Page 376 - Computer Science Class 11 Without Functions
P. 376

Program 10

        Write a program that accepts two numbers from the user and displays their greater common divisor (GCD) and least
        common multiple (LCM).

        Ans. '''
             Objective: To calculate GCD and LCM of 2 numbers
             Input: num1,num2
             Output: GCD,LCM

             '''
             num1 = int(input("Enter first number : "))
             num2 = int(input("Enter second number : "))

             gcd = 1
             for i in range(1,num1+1):
              if num1%i == 0 and num2%i == 0:

                gcd = i
             print("GCD of ", num1, "and", num2, "is : ", gcd)
             lcm = num1 * num2 / gcd

             print("LCM of ", num1, "and", num2, "is : ", lcm)
        Program 11
        Write a program that accepts a string as input from the user and prints the count of vowels, consonants, uppercase,
        and lowercase characters.

        Ans. '''
              Objective: To display the count of vowels, consonants, uppercase, and lowercase
             characters
             Input: dataString

             Output: count of vowels/consonants/upper case and lower case characters
             '''
             dataString = input("Enter a string : ")

             countVowels = 0
             countConsonants = 0
             countUpperCase = 0

             countLowerCase = 0
             for ch in dataString:
              if ch.isalpha():
                if ch in "aeiouAEIOU" :

                  countVowels += 1
                else:

                  countConsonants += 1
                if ch.islower():


         374   Touchpad Computer Science-XI
   371   372   373   374   375   376   377   378   379   380   381