Answers for "how to slice a string using a loop in python"

7

how to reverse array in python

a = [1,2,3,4]
a = a[::-1]
print(a)
>>> [4,3,2,1]
Posted by: Guest on March-06-2020
28

reverse string in python

'hello world'[::-1]
'dlrow olleh'
Posted by: Guest on December-06-2019
0

loop and save letters in a string java

public static void main(String[] args){
        Scanner input = new Scanner(System.in);

            System.out.print("Enter phone number: ");
            String number = input.nextLine();
            String phone ="";

            for (int i = 0; i < number.length(); i++){
                if (Character.isLetter(number.charAt(i)))
                    phone = getNumber(Character.toUpperCase(number.charAt(i)));
                else
                    number.charAt(i);
            }
            System.out.println("Your number is " + phone);              
    }


public static int getNumber(char uppercaseLetter){
        if (uppercaseLetter >= 'W' && uppercaseLetter <= 'Z')
            return 9;
        else if (uppercaseLetter >= 'T' && uppercaseLetter < 'W')
            return 8;
        else if (uppercaseLetter >= 'P' && uppercaseLetter < 'T')
            return 7;
        else if (uppercaseLetter >= 'M' && uppercaseLetter < 'P')
            return 6;
        else if (uppercaseLetter >= 'J' && uppercaseLetter < 'M')
            return 5;
        else if (uppercaseLetter >= 'G' && uppercaseLetter < 'J')
            return 4;
        else if (uppercaseLetter >= 'D' && uppercaseLetter < 'G')
            return 3;
        else 
            return 2;
    }
}
Posted by: Guest on January-04-2020

Code answers related to "how to slice a string using a loop in python"

Python Answers by Framework

Browse Popular Code Answers by Language