8, ఆగస్టు 2025, శుక్రవారం

lab-4 python ..................

rows = int(input("Enter number of rows: "))


for i in range(rows):

    for j in range(i+1):

        print(j+1, end=" ")

    print()




 // C++ implementation of the above approach


#include "bits/stdc++.h"

using namespace std;


// Function to return the word

// of the corresponding digit

void printValue(char digit)

{


    // Switch block to check for each digit c

    switch (digit) {


    // For digit 0

    case '0':

        cout << "Zero ";

        break;


    // For digit 1

    case '1':

        cout << "One ";

        break;


    // For digit 2

    case '2':

        cout << "Two ";

        break;


    // For digit 3

    case '3':

        cout << "Three ";

        break;


    // For digit 4

    case '4':

        cout << "Four ";

        break;


    // For digit 5

    case '5':

        cout << "Five ";

        break;


    // For digit 6

    case '6':

        cout << "Six ";

        break;


    // For digit 7

    case '7':

        cout << "Seven ";

        break;


    // For digit 8

    case '8':

        cout << "Eight ";

        break;


    // For digit 9

    case '9':

        cout << "Nine ";

        break;

    }

}


// Function to iterate through every

// digit in the given number

void printWord(string N)

{

    int i, length = N.length();


    // Finding each digit of the number

    for (i = 0; i < length; i++) {


        // Print the digit in words

        printValue(N[i]);

    }

}


// Driver code

int main()

{

    string N = "123";

    printWord(N);

    return 0;

}


Input: N = 1234 
Output: One Two Three Four 
Explanation: 
Every digit of the given number has been converted into its corresponding word.

# Python program to determine whether # the number is Armstrong number or not # Function to calculate x raised to # the power y def power(x, y): if y == 0: return 1 if y % 2 == 0: return power(x, y // 2) * power(x, y // 2) return x * power(x, y // 2) * power(x, y // 2) # Function to calculate order of the number def order(x): # Variable to store of the number n = 0 while (x != 0): n = n + 1 x = x // 10 return n # Function to check whether the given # number is Armstrong number or not def isArmstrong(x): n = order(x) temp = x sum1 = 0 while (temp != 0): r = temp % 10 sum1 = sum1 + power(r, n) temp = temp // 10 # If condition satisfies return (sum1 == x) # Driver code x = 153 print(isArmstrong(x)) x = 1253 print(isArmstrong(x))

 

 

 

 

 

 

# Multiplication table (from 1 to 10) in Python

 

num = 12

 

# To take input from the user

# num = int(input("Display multiplication table of? "))

 

# Iterate 10 times from i = 1 to 10

for i in range(1, 11):

   print(num, 'x', i, '=', num*i)

 

Input: N = 567 
Output: Five Six Seven 

 

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి