File tree Expand file tree Collapse file tree 7 files changed +40
-4
lines changed Expand file tree Collapse file tree 7 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 1
- # 11. Print out the sentence from A10 but make the month upper case.
1
+ # A11 - Print out the sentence from A10 but make the month upper case.
2
2
3
3
# Ask the user for input for the month and the temperatures
4
4
month = input ("What month is it?\n " )
Original file line number Diff line number Diff line change 1
- # 12. Create a variable that holds your favourite animals and print it out.
1
+ # A12 - Create a variable that holds your favourite animals and print it out.
2
2
# Make sure the animals are all on different lines and tabbed.
3
3
4
4
# Create a list of your favourite animals, using \n\t for the new line and new tab
Original file line number Diff line number Diff line change 1
- # 13. Ask the user to enter their name as well as a number.
1
+ # A13 - Ask the user to enter their name as well as a number.
2
2
# Print out the uppercase character at that position in the string.
3
3
4
4
# Ask the user for input
Original file line number Diff line number Diff line change
1
+ # A14 - Slice the string with steps of 2, excluding the first and last characters of the string "WelcometoPython"
2
+
3
+
4
+ # creating a variable with the string in
5
+ str = "WelcometoPython"
6
+
7
+ # finding out the length of the string to decide which characters to exclude
8
+ print (len (str ))
9
+
10
+ # slicing the string with steps of 2, excluding the first and last character
11
+ print (str [1 :14 :2 ])
Original file line number Diff line number Diff line change 1
- # Ask the user to enter their favourite colour and find out the length of the colour they input.
1
+ # A8 - Ask the user to enter their favourite colour and find out the length of the colour they input.
2
2
3
3
# Ask the user for input
4
4
colour = input ("What is your favourite colour?\n " )
Original file line number Diff line number Diff line change 14
14
11 . Print out the above sentence but make the month upper case.
15
15
12 . Create a variable that holds your favourite animals and print it out. Make sure the animals are all on different lines and tabbed.
16
16
13 . Ask the user to enter their name as well as a number. Print out the uppercase character at that position in the string.
17
+ 14 . Slice the string with steps of 2, excluding the first and last characters of the string "WelcometoPython"
Original file line number Diff line number Diff line change @@ -351,6 +351,30 @@ print("HeLlO".lower()) # hello
351
351
352
352
---
353
353
<
8000
td data-grid-cell-id="diff-1353e054b26178449aad8429a20e3f3543d93fd61b1afe418a65fc5c30c5ac33-353-353-2" data-line-anchor="diff-1353e054b26178449aad8429a20e3f3543d93fd61b1afe418a65fc5c30c5ac33R353" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
354
+ # Slicing
355
+
356
+ ---
357
+
358
+ # Slicing
359
+
360
+ ```
361
+ # slicing from one point to another
362
+ "string"[0:6] #string
363
+ "string"[1:4] #tri
364
+
365
+ # slicing from one point to the end
366
+ "string"[0:] #string
367
+ "string"[1:] #ing
368
+
369
+ # slicing from the start to another point
370
+ "string"[:0] #
371
+ "string"[:2] #st
372
+
373
+ # slicing from the start to end, by skipping step
374
+ "string"[0:6:2] #srn
375
+ ```
376
+ ---
377
+
354
378
# Putting it together
355
379
356
380
``` python
You can’t perform that action at this time.
0 commit comments