Posts

Unexpected Indent Error in Python

Here is an example of Unexpected Indent Error in Python  Problem: x=5   for i in range(0,x):       for j in range(0,i):         print("*") Correct Way: x=5 for i in range(0,x): for j in range(0,i): print("*")     

program to sort words in decreasing order of their length and display the words along with their length in python

 my_str = "i am a person who are u" # breakdown the string into a list of words words = my_str.split() words.sort(reverse=True,key=len) # display the sorted words for word in words: print(word,len(word))

Program to implement sleep method in java

 import java.io.*;  class A extends Thread { public void run(){ for(int i=0;i<10;i++){ System.out.println(i); try{ Thread.sleep(5000); }catch(Exception e){} } } public static void main(String[] args)throws Exception { A a=new A(); a.start(); } }

Add two number in javascript html dhtml

 <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <input type="text" id="a"> <br> <input type="text" id="b"> <br> <button onClick=fun() > Result</button> <br> <script type="text/javascript"> function fun() { var a1 =document.getElementById("a").value; var b1 =document.getElementById("b").value; alert(+a1 + +b1); } </script> </body> </html> Result

kotlin android studio set TextView to invisible

//Here txtview1 is your TextView txtview1.visibility=View.INVISIBLE txtviewTextPersonName .visibility=View.VISIBLE

Write a function int power (int x, int n) to return x^n without using pow function

#include <stdio.h> #include <math.h> void main() {       int z =(power(3,7));     printf("%d",z); } int power(int x,int n) {     int y=x;     if(n==0)     return 1;     else if (n==1)     return x;     else if(n>1)     {         while(n>1)                  {             x=x*y;             n--;         }     }        return x ; } OUTPUT : 2187