Ask Question
17 March, 02:12

1. Write a program that asks the user to enter a string. The program should then print the following: (a) The total number of characters in the string (b) The string repeated 10 times (c) The first character of the string (remember that string indices start at 0) (d) The first three characters of the string (e) The last three characters of the string (f) The string backwards (g) The seventh character of the string if the string is long enough and a message otherwise (h) The string with its first and last characters removed (i) The string in all caps (j) The string with every a replaced with an e

+2
Answers (1)
  1. 17 March, 02:45
    0
    s = input ("Enter a string: ")

    print (len (s))

    print (s*10)

    print (s[0])

    print (s[:3])

    print (s[len (s) - 3:])

    print (s[::-1])

    if len (s) > = 7:

    print (s[6])

    else:

    print ("The string is not long enough")

    print (s[1:len (s) - 1])

    print (s. upper ())

    print (s. replace ("a", "e"))

    Explanation:

    *The code is in Python.

    Ask the user to enter a string

    Use len method to get the total number of characters

    Use "*" to repeat 10 times

    Use index, 0, to get first character

    Use slicing to get first three characters

    Use slicing to get last three characters

    Use slicing to get it in backwards

    Check if the length is greater than or equal to 7. If it is, use index, 6. Otherwise, print a message.

    Use slicing to remove first and last characters

    Use upper method to get it in all caps

    Use replace method to replace the "a" with the "e"
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “1. Write a program that asks the user to enter a string. The program should then print the following: (a) The total number of characters in ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers