Skip to content

Commit e94f0d0

Browse files
upload question 1
1 parent 35bd26f commit e94f0d0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/question-1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

0 commit comments

Comments
 (0)