Question

Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use...

Use the Pythone programming language. see the #bold hashtags in the code for instructions. Also use the website provided for an idea on how the code should be approached. please provide the code along with a screen shot of the code working with the outcome.

s1 = str("abc text xyz")
print("String s1 =", s1)
print("First letter of s1 = ", s1[0])
print("length of s1= ", len(s1))#len for length
length = len(s1)
last = s1[length-1]
print("Last letter = ", last)
print("First four letters:", s1[4:8])
# copy the content of one string to another
s2 = s1.upper()
print("length of s2 =", len(s2))
print("String s2 =", s2)



# Copy the letters form s1 into s2 in the reverse order
# output = zyx txet cba

# https://www.w3schools.com/python/python_howto_reverse_string.asp
s2 = s1[::-1]
# the a reverse count
print("[reverse s1] String s2 =", s2)

i = 0
aList = ['a']*len(s1)
while i < len(s1):
aList[i] = s1[len(s1)-1-i]
i = i + 1
print("String s1 =", s1)
print("aList =", aList)

Homework Answers

Answer #1

In python, we have a feature called slicing.

  1. First, we will take the input
  2. Then inside another variable, we will copy the variable
  3. We will apply negative slicing which means we will start from the end of the string.
  4. The index starts to move one step back and stores the reverse string in the variable s2
  5. Print the reversed string
s1=str("abc text xyz") #input the sentence 
s2=s1[::-1] #copying the sentence and applying slicing 
print(s2) #print the reverse

Below is the screenshot of the code and the output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() { char str[100]; /*Buffer to hold reversed string */ reverse("cat", str); /*Reverse the string "cat" */ printf("reverse(\"cat\")=%s\n", str); /*Display result */ reverse("noon", str); /*Reverse the string "noon" */ printf("reverse(\"noon\")=%s\n", str); /*Display result */ } reverse(char *before,...
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED....
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED. ALSO THE 2 POINTS MENTIONED BELOW SHOULD BE PRESENT IN THE CODE Write a script that calculates the 3 longest words of a text stored in a file and print them from the longest to the smaller of the 3. Please note: 1. The name of the file is word_list.csv and it doesn’t need to be asked to the user (meaning the name will...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
THIS PYTHON PROGRAMMING On a chessboard, positions are marked with letters between a and h for...
THIS PYTHON PROGRAMMING On a chessboard, positions are marked with letters between a and h for the column and a number between 1 and 8 for the row. The first place on the board, a1, is black. The next is white, alternating across a row. Odd rows start with black, even rows start with white. Given a 2 character input string with a letter (a-h) and a number (1-8), print "Black" or "White" indicating if the square is black or...
Each person in the group will be responsible for rewriting the code to solve ​one​ of...
Each person in the group will be responsible for rewriting the code to solve ​one​ of the original parts (celebrity names), ​without using arrays or loops.​ The purpose of this assignment is to practice Strings manipulation and String methods so full credit will only be given if you are utilizing the code for Strings (substring, charAt, compareTo, equals, etc). program Java this was my last assigment Take the 4th and the 5th words from part 1 and print out both...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
Develop a Traceroute application in python using ICMP. Your application will use ICMP but, in order...
Develop a Traceroute application in python using ICMP. Your application will use ICMP but, in order to keep it simple, will not exactly follow the official specification in RFC 1739.. Below you will find the skeleton code for the client. You are to complete the skeleton code. The places where you need to fill in code are marked with #Fill in start and #Fill in end. Code from socket import * import os import sys import struct import time import...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []        //create empty list to merge the lists M and N if not M:                //if M is empty list, m = 0                //set m = 0 else: m = len(M)             //otherwise, set m = len(M) if not N:                //if N is empty list, n = 0       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT