File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ question-1.py - Michael Bateman
3+ Python Coding Bat Test - ICS3U
4+ Feb 16/2017
5+ '''
6+
7+ # imports - none
8+
9+ # functions
10+
11+ def newString (word ): # creates a function called newString and recieves data
12+ if (len (word ) < 2 ): # checking to see if the string is less than 2
13+ return (word ) # if string is less than 2, it will just return the word
14+ else :
15+ first = word [:1 ] # this stores the first letter in the variable 'first'
16+ last = word [len (word )- 1 :] # this stores the last letter in the variable 'last'
17+ mid = word [1 :len (word )- 1 ] # this creates a string without the first and last letters, stored in 'mid'
18+ return (last + mid + first ) # this will return it with the first and last letters switched
19+
20+ # input
21+
22+ word = raw_input ("Please type a word: " ) # this is raw_input, therefore the variable 'word' is a string
23+
24+ # raw code
25+
26+ print (newString (word )) # this prints the funtion to the screen
You can’t perform that action at this time.
0 commit comments