@@ -92,7 +92,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
92
92
print (" Access denied." )
93
93
```
94
94
95
- Again, this is not a good way to ask a real password from the user.
95
+ Again, this is not a good way to ask a real password from the user.
96
96
97
97
# # Handy stuff: Strings
98
98
@@ -156,7 +156,15 @@ isn't exactly like mine but it works just fine it's ok, and you can
156
156
print (message, " !!!" )
157
157
print (message, " !!!" )
158
158
```
159
-
159
+ 3 . In the code below, `palindrome_input[::- 1 ]` is the string `palindrome_input` reversed .
160
+ For example, if `palindrome_input` is `" hello" ` , then `palindrome_input[::- 1 ]` is `" olleh" ` .
161
+ ```python
162
+ palindrome_input= input (" Type the number to check:" )
163
+ if palindrome_input == palindrome_input[::- 1 ]:
164
+ print (" This string is a palindrome" )
165
+ else :
166
+ print (" This string is not a palindrome" )
167
+ ```
160
168
## Lists and tuples
161
169
162
170
1 . Look carefully. The ` namelist ` is written in ` () ` instead of ` [] ` ,
@@ -296,6 +304,36 @@ isn't exactly like mine but it works just fine it's ok, and you can
296
304
print (converted_numbers)
297
305
```
298
306
307
+ 5 . ``` python
308
+ row_count = int (input (" Type the number of rows needed:" ))
309
+ for column_count in range (1 , row_count+ 1 ):
310
+ # Print numbers from 1 to column_count
311
+ for number in range (1 , column_count+ 1 ):
312
+ print (number, end = " " )
313
+ print () # creates a new line for the next row
314
+ ```
315
+ If the user enters 5 , we want to do a row with 1 column, then 2 columns, and so on until 5 columns.
316
+ That would be `for column_count in range (1 , 6 )` , because the end of the range is excluded.
317
+ In general, we need to specify `row_count + 1 ` so that it actually ends at `row_count` .
318
+ The second loop is similar.
319
+
320
+ Usually `print (number)` puts a newline character at the end of the line, so that the next print goes to the next line.
321
+ To get all numbers on the same line, we use a space instead of a newline character,
322
+ but we still need `print ()` to add a newline character once we have printed the entire row.
323
+
324
+
325
+
326
+ 6 . ```python
327
+ row_count = int (input (" Type the number of rows needed:" ))
328
+
329
+ for line_number in range (1 , row_count + 1 ):
330
+ for number in range (line_number, row_count+ 1 ):
331
+ print (number, end = ' ' )
332
+ print ()
333
+ ```
334
+ Just like in the previous exercise, if the user enters 5 , the first `for ` loop gives the line numbers ` 1 , 2 , 3 , 4 , 5 `.< br>
335
+ For example, on line 2 , we should print numbers from 2 to 5 , as in ` range (2 , 6 )`, or in general, ` range (line_number, row_count+ 1 )`.
336
+
299
337
# # Trey Hunner: zip and enumerate
300
338
301
339
1 . Read some lines with `input ` into a list and then enumerate it.
0 commit comments