File tree 2 files changed +84
-0
lines changed
2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ # In Python, a string can be split on a delimiter.
2
+
3
+ # Example:
4
+
5
+ # >>> a = "this is a string"
6
+ # >>> a = a.split(" ") # a is converted to a list of strings.
7
+ # >>> print a
8
+ # ['this', 'is', 'a', 'string']
9
+ # Joining a string is simple:
10
+
11
+ # >>> a = "-".join(a)
12
+ # >>> print a
13
+ # this-is-a-string
14
+ # Task
15
+ # You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen.
16
+
17
+ # Input Format
18
+ # The first line contains a string consisting of space separated words.
19
+
20
+ # Output Format
21
+ # Print the formatted string as explained above.
22
+
23
+ # Sample Input
24
+
25
+ # this is a string
26
+ # Sample Output
27
+
28
+ # this-is-a-string
29
+
30
+
31
+
32
+ def split_and_join (line ):
33
+ line = line .split (" " )
34
+ line = "-" .join (line )
35
+ return (line )
36
+
37
+ if __name__ == '__main__' :
38
+ line = input ()
39
+ result = split_and_join (line )
40
+ print (result )
Original file line number Diff line number Diff line change
1
+ # You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
2
+
3
+ # For Example:
4
+
5
+ # Www.HackerRank.com → wWW.hACKERrANK.COM
6
+ # Pythonist 2 → pYTHONIST 2
7
+ # Input Format
8
+
9
+ # A single line containing a string .
10
+
11
+ # Constraints
12
+
13
+
14
+ # Output Format
15
+
16
+ # Print the modified string .
17
+
18
+ # Sample Input 0
19
+
20
+ # HackerRank.com presents "Pythonist 2".
21
+ # Sample Output 0
22
+
23
+ # hACKERrANK.COM PRESENTS "pYTHONIST 2".
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ def swap_case (s ):
33
+ new = ""
34
+ for i in range (0 ,len (s )):
35
+ if (s [i ].isupper ()):
36
+ new += s [i ].lower ()
37
+ elif (s [i ].islower ):
38
+ new += s [i ].upper ()
39
+ return (new )
40
+
41
+ if __name__ == '__main__' :
42
+ s = input ()
43
+ result = swap_case (s )
44
+ print (result )
You can’t perform that action at this time.
0 commit comments