TORONTO KIDS COMPUTER CLUB | PMCA Sunday 14:00 Python Homework 21.02.07.
19045
post-template-default,single,single-post,postid-19045,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

PMCA Sunday 14:00 Python Homework 21.02.07.

11 Feb PMCA Sunday 14:00 Python Homework 21.02.07.

Question:
Create a wordReverse to reverse a string.

  • You need one argument (which is the original string) for the function
    def wordReverse(word)
  • You must return the reversed string from the function.
  • For e.g The reverse of string “1234abcd” is “dcba4321”

Hint 1:

using len() to find out the length of the string e.g.

a = ‘Hello’

b = len(a) #b is now equal to 5

Hint 2:

String is also a kind of list, so we can using [] to access each character of the string e.g.

a = ‘Hello’

b = a[1] #b now is letter ‘e’ in the “Hello”

Hint 3:

We can use + or += to add string together

Hint 4:

You can write the main program like following:

myString = input(‘Which string do you want to reverse? ‘)

wr = wordReverse(myString)

print(wr)

No Comments

Sorry, the comment form is closed at this time.