From 289931d408848f716f81b960060c47fee62282d5 Mon Sep 17 00:00:00 2001 From: GR Date: Wed, 30 Dec 2020 21:44:52 +0530 Subject: [PATCH 01/25] Update if.md and loops.md --- basics/answers.md | 25 ++++++++++++++++++++++++- basics/if.md | 1 + basics/loops.md | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/basics/answers.md b/basics/answers.md index de739c3..1f49167 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -92,7 +92,18 @@ isn't exactly like mine but it works just fine it's ok, and you can print("Access denied.") ``` - Again, this is not a good way to ask a real password from the user. + Again, this is not a good way to ask a real password from the user. + +7. Here, we create a new variable `pallindrome_check`.We use this variable to store the reversed string(of`pallindrome_input`).
Then we check if the string that was given(`pallindrome_input`) + and the reversed sting(`pallindrome_check`) is the same using a simple `if loop` + ```python + pallindrome_input=input("Type the number to check:") #to get the input from user + pallindrome_check=pallindrome_input[::-1] #Reverses the string + if pallindrome_input==pallindrome_check: + print(f"This number is a pallindrome") + else: + print("This number is not a pallindrome") + ``` ## Handy stuff: Strings @@ -295,6 +306,18 @@ isn't exactly like mine but it works just fine it's ok, and you can converted_numbers.append(int(number)) print(converted_numbers) ``` +5. We actually use the first `for` loop to loop through the number of rows needed.Now, + through that `for` loop we got the row number.
+ Now,the next `for` loop helps us to identify which numbers should be printed on the row which we currently accessed from the `for` loop above + ```python + rows=int(input("Type the number of rows needed:")) #gets the number of rows from the user + + for row in range(1,rows+1): #finds the row from rows' variable + for column in range(1,row+1): # this is actually the column where a number has to be added + print(column,end=" ") # this is where the number is printed into rows + print()#creates a new line for the next row + ``` + ## Trey Hunner: zip and enumerate diff --git a/basics/if.md b/basics/if.md index a1fed8e..32b6c07 100644 --- a/basics/if.md +++ b/basics/if.md @@ -311,6 +311,7 @@ you are asked to "fix code", feel free to add missing blank lines. `Access denied` or `You didn't enter anything` depending on whether the user entered the correct password, a wrong password, or nothing at all by pressing Enter without typing anything. +7. Make a programme to take the input from the user and check if it is a pallindrome. The answers are [here](answers.md#if-else-and-elif). diff --git a/basics/loops.md b/basics/loops.md index 4abb172..be4d9b7 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -470,6 +470,13 @@ while True: number = int(number) print(numbers) ``` +5. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed + >**OUTPUT** for 5 rows
+1
+1 2
+1 2 3
+1 2 3 4
+1 2 3 4 5
The answers are [here](answers.md#loops). From 6f1d88287388cdf81f96a290dadaab4071657791 Mon Sep 17 00:00:00 2001 From: GR Date: Wed, 30 Dec 2020 21:56:05 +0530 Subject: [PATCH 02/25] Update if.md and loops.md --- basics/answers.md | 10 +++++++++- basics/loops.md | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/basics/answers.md b/basics/answers.md index 1f49167..975ffea 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -317,7 +317,15 @@ isn't exactly like mine but it works just fine it's ok, and you can print(column,end=" ") # this is where the number is printed into rows print()#creates a new line for the next row ``` - +6. The idea is more or less same as in the above question. + ```python + rows=int(input("Type the number of rows needed:"))#gets the number of rows from the user + + for row in range(1, rows + 2): #finds the row from rows' variable + for column in range(row,rows+1, 1): # this is actually the column where a number has to be added + print(column, end=' ')# this is where the number is printed into rows + print()#creates a new line for the next row + ``` ## Trey Hunner: zip and enumerate diff --git a/basics/loops.md b/basics/loops.md index be4d9b7..e78d7bc 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -478,6 +478,13 @@ while True: 1 2 3 4
1 2 3 4 5
+6. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed + >**OUTPUT** when rows is equal to 5
+1 2 3 4 5
+2 3 4 5
+3 4 5
+4 5
+5
The answers are [here](answers.md#loops). *** From 9181d7a84fcc12d545aef6f7ab98047b2322a136 Mon Sep 17 00:00:00 2001 From: GR Date: Fri, 1 Jan 2021 23:45:53 +0530 Subject: [PATCH 03/25] Fixed Typo --- basics/answers.md | 14 +++++++------- basics/if.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index 975ffea..db98c02 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -94,15 +94,15 @@ isn't exactly like mine but it works just fine it's ok, and you can Again, this is not a good way to ask a real password from the user. -7. Here, we create a new variable `pallindrome_check`.We use this variable to store the reversed string(of`pallindrome_input`).
Then we check if the string that was given(`pallindrome_input`) - and the reversed sting(`pallindrome_check`) is the same using a simple `if loop` +7. Here, we create a new variable `palindrome_check`.We use this variable to store the reversed string(of`palindrome_input`). Then we check if the string that was given(`palindrome_input`) + and the reversed sting(`palindrome_check`) is the same using a simple `if loop` ```python - pallindrome_input=input("Type the number to check:") #to get the input from user - pallindrome_check=pallindrome_input[::-1] #Reverses the string - if pallindrome_input==pallindrome_check: - print(f"This number is a pallindrome") + palindrome_input=input("Type the number to check:") #to get the input from user + palindrome_check=palindrome_input[::-1] #Reverses the string + if palindrome_input==palindrome_check: + print(f"This number is a palindrome") else: - print("This number is not a pallindrome") + print("This number is not a palindrome") ``` ## Handy stuff: Strings diff --git a/basics/if.md b/basics/if.md index 32b6c07..ff5e2d3 100644 --- a/basics/if.md +++ b/basics/if.md @@ -311,7 +311,7 @@ you are asked to "fix code", feel free to add missing blank lines. `Access denied` or `You didn't enter anything` depending on whether the user entered the correct password, a wrong password, or nothing at all by pressing Enter without typing anything. -7. Make a programme to take the input from the user and check if it is a pallindrome. +7. Make a programme to take the input from the user and check if it is a palindrome. The answers are [here](answers.md#if-else-and-elif). From d5cf490239b01b3f0b369c6b6095c204ae091a03 Mon Sep 17 00:00:00 2001 From: GR Date: Sat, 2 Jan 2021 00:22:50 +0530 Subject: [PATCH 04/25] Removed unnecessary comments in the programmes --- basics/answers.md | 33 ++++++++++++++++++--------------- basics/loops.md | 28 ++++++++++++++++------------ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index db98c02..d4526d4 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -97,7 +97,7 @@ isn't exactly like mine but it works just fine it's ok, and you can 7. Here, we create a new variable `palindrome_check`.We use this variable to store the reversed string(of`palindrome_input`). Then we check if the string that was given(`palindrome_input`) and the reversed sting(`palindrome_check`) is the same using a simple `if loop` ```python - palindrome_input=input("Type the number to check:") #to get the input from user + palindrome_input=input("Type the number to check:") palindrome_check=palindrome_input[::-1] #Reverses the string if palindrome_input==palindrome_check: print(f"This number is a palindrome") @@ -306,25 +306,28 @@ isn't exactly like mine but it works just fine it's ok, and you can converted_numbers.append(int(number)) print(converted_numbers) ``` -5. We actually use the first `for` loop to loop through the number of rows needed.Now, - through that `for` loop we got the row number.
+ +5. ``` python + rows=int(input("Type the number of rows needed:")) + for row in range(1,rows+1): + for column in range(1,row+1): + print(column,end=" ") + print()#creates a new line for the next row + ``` + We actually use the first `for` loop to loop through the number of rows needed.Now, + through that `for` loop we got the row number. Now,the next `for` loop helps us to identify which numbers should be printed on the row which we currently accessed from the `for` loop above - ```python - rows=int(input("Type the number of rows needed:")) #gets the number of rows from the user + - for row in range(1,rows+1): #finds the row from rows' variable - for column in range(1,row+1): # this is actually the column where a number has to be added - print(column,end=" ") # this is where the number is printed into rows - print()#creates a new line for the next row - ``` + 6. The idea is more or less same as in the above question. ```python - rows=int(input("Type the number of rows needed:"))#gets the number of rows from the user + rows=int(input("Type the number of rows needed:")) - for row in range(1, rows + 2): #finds the row from rows' variable - for column in range(row,rows+1, 1): # this is actually the column where a number has to be added - print(column, end=' ')# this is where the number is printed into rows - print()#creates a new line for the next row + for row in range(1, rows + 1): + for column in range(row,rows+1): + print(column, end=' ') + print() ``` ## Trey Hunner: zip and enumerate diff --git a/basics/loops.md b/basics/loops.md index e78d7bc..31d6cac 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -471,20 +471,24 @@ while True: print(numbers) ``` 5. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed - >**OUTPUT** for 5 rows
-1
-1 2
-1 2 3
-1 2 3 4
-1 2 3 4 5
+ ``` + OUTPUT for 5 rows + 1 + 1 2 + 1 2 3 + 1 2 3 4 + 1 2 3 4 5 + ``` 6. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed - >**OUTPUT** when rows is equal to 5
-1 2 3 4 5
-2 3 4 5
-3 4 5
-4 5
-5
+ ``` + OUTPUT when rows is equal to 5 + 1 2 3 4 5 + 2 3 4 5 + 3 4 5 + 4 5 + 5 + ``` The answers are [here](answers.md#loops). *** From 33049e14eabcdd70ba7916affcd9b33ff9de1ef6 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:18:05 +0530 Subject: [PATCH 05/25] Update basics/loops.md Co-authored-by: Akuli --- basics/loops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/loops.md b/basics/loops.md index 31d6cac..4c78f20 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -480,7 +480,7 @@ while True: 1 2 3 4 5 ``` -6. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed +6. Modify your program from the previous exercise to print this instead: ``` OUTPUT when rows is equal to 5 1 2 3 4 5 From a509a8e0bbbd72ea2d74abb3e3352a251402664c Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:18:19 +0530 Subject: [PATCH 06/25] Update basics/loops.md Co-authored-by: Akuli --- basics/loops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/loops.md b/basics/loops.md index 4c78f20..97cab80 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -482,7 +482,7 @@ while True: 6. Modify your program from the previous exercise to print this instead: ``` - OUTPUT when rows is equal to 5 + OUTPUT for 5 rows 1 2 3 4 5 2 3 4 5 3 4 5 From 8fd60e4224e0d511de79c1c38478e3a507db35a1 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:26:34 +0530 Subject: [PATCH 07/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index d4526d4..b370891 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -308,11 +308,11 @@ isn't exactly like mine but it works just fine it's ok, and you can ``` 5. ``` python - rows=int(input("Type the number of rows needed:")) - for row in range(1,rows+1): - for column in range(1,row+1): - print(column,end=" ") - print()#creates a new line for the next row + row_count = int(input("Type the number of rows needed:")) + for column_count in range(1, row_count+1): + for number in range(1, column_count+1): + print(number, end=" ") + print() # creates a new line for the next row ``` We actually use the first `for` loop to loop through the number of rows needed.Now, through that `for` loop we got the row number. From 1eeda48572ba919e6da6554eeb1e2b943537bf9c Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:38:12 +0530 Subject: [PATCH 08/25] I have made the necessary changes as requested --- basics/answers.md | 32 +++++++++++++++----------------- basics/handy-stuff-strings.md | 1 + basics/if.md | 2 +- basics/loops.md | 6 +++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index b370891..e43c3f5 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -94,17 +94,6 @@ isn't exactly like mine but it works just fine it's ok, and you can Again, this is not a good way to ask a real password from the user. -7. Here, we create a new variable `palindrome_check`.We use this variable to store the reversed string(of`palindrome_input`). Then we check if the string that was given(`palindrome_input`) - and the reversed sting(`palindrome_check`) is the same using a simple `if loop` - ```python - palindrome_input=input("Type the number to check:") - palindrome_check=palindrome_input[::-1] #Reverses the string - if palindrome_input==palindrome_check: - print(f"This number is a palindrome") - else: - print("This number is not a palindrome") - ``` - ## Handy stuff: Strings 1. The program is not like you might expect it to be. It actually works @@ -167,7 +156,16 @@ isn't exactly like mine but it works just fine it's ok, and you can print(message, "!!!") print(message, "!!!") ``` - +3. Here, we create a new variable `palindrome_check`.We use this variable to store the reversed string(of`palindrome_input`). Then we check if the string that was given(`palindrome_input`) + and the reversed sting(`palindrome_check`) is the same using a simple `if loop` + ```python + palindrome_input=input("Type the number to check:") + palindrome_check=palindrome_input[::-1] #Reverses the string + if palindrome_input==palindrome_check: + print(f"This number is a palindrome") + else: + print("This number is not a palindrome") + ``` ## Lists and tuples 1. Look carefully. The `namelist` is written in `()` instead of `[]`, @@ -315,18 +313,18 @@ isn't exactly like mine but it works just fine it's ok, and you can print() # creates a new line for the next row ``` We actually use the first `for` loop to loop through the number of rows needed.Now, - through that `for` loop we got the row number. + through that `for` loop we got to which column the number should be inserted. Now,the next `for` loop helps us to identify which numbers should be printed on the row which we currently accessed from the `for` loop above 6. The idea is more or less same as in the above question. ```python - rows=int(input("Type the number of rows needed:")) + row_count=int(input("Type the number of rows needed:")) - for row in range(1, rows + 1): - for column in range(row,rows+1): - print(column, end=' ') + for column_count in range(1, row_count + 1): + for number in range(row_count,column_count+1): + print(number, end=' ') print() ``` diff --git a/basics/handy-stuff-strings.md b/basics/handy-stuff-strings.md index be89c55..ba0f24e 100644 --- a/basics/handy-stuff-strings.md +++ b/basics/handy-stuff-strings.md @@ -424,6 +424,7 @@ ValueError: could not convert string to float: 'hello' print(message, "!!!") print(message, "!!!") ``` +3. Make a program to take the input from the user and check if it is a palindrome. The answers are [here](answers.md#handy-stuff-strings). diff --git a/basics/if.md b/basics/if.md index ff5e2d3..9247ed6 100644 --- a/basics/if.md +++ b/basics/if.md @@ -311,7 +311,7 @@ you are asked to "fix code", feel free to add missing blank lines. `Access denied` or `You didn't enter anything` depending on whether the user entered the correct password, a wrong password, or nothing at all by pressing Enter without typing anything. -7. Make a programme to take the input from the user and check if it is a palindrome. + The answers are [here](answers.md#if-else-and-elif). diff --git a/basics/loops.md b/basics/loops.md index 97cab80..d0653af 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -470,7 +470,7 @@ while True: number = int(number) print(numbers) ``` -5. Make a programme to get a pyramid like shown in the OUTPUT section where user can type the number of rows needed +5. Make a program to get a pyramid like shown below where user can type the number of rows needed. ``` OUTPUT for 5 rows 1 @@ -480,9 +480,9 @@ while True: 1 2 3 4 5 ``` -6. Modify your program from the previous exercise to print this instead: +6. Make a program to get a pyramid like shown below where user can type the number of rows needed. ``` - OUTPUT for 5 rows + OUTPUT when rows is equal to 5 1 2 3 4 5 2 3 4 5 3 4 5 From 2ce1e7da0198dbe09056a8e306a2c23f8170ac23 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 01:52:51 +0530 Subject: [PATCH 09/25] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e9c652f..93baa59 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The instructions and text in this tutorial (the "software") are licensed under the zlib License. - (C) 2016-2018 Akuli + (C) 2016-2021 Akuli This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages From 7a93d2adb4b56915255a29253c32de85ca248abb Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:06:40 +0530 Subject: [PATCH 10/25] Update basics/loops.md Co-authored-by: Akuli --- basics/loops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/loops.md b/basics/loops.md index d0653af..ae7adfc 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -482,7 +482,7 @@ while True: 6. Make a program to get a pyramid like shown below where user can type the number of rows needed. ``` - OUTPUT when rows is equal to 5 + OUTPUT for 5 rows 1 2 3 4 5 2 3 4 5 3 4 5 From 39f94f553f354fec18a73f767ce49494592249b8 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:10:52 +0530 Subject: [PATCH 11/25] Update basics/loops.md Co-authored-by: Akuli --- basics/loops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/loops.md b/basics/loops.md index ae7adfc..4e69c60 100644 --- a/basics/loops.md +++ b/basics/loops.md @@ -470,7 +470,7 @@ while True: number = int(number) print(numbers) ``` -5. Make a program to get a pyramid like shown below where user can type the number of rows needed. +5. Make a program that prints a pyramid like shown below. Ask the user to type the number of rows needed. ``` OUTPUT for 5 rows 1 From 546f769aa0bf4dceaf43a68b22c6638fc28db9d9 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:11:10 +0530 Subject: [PATCH 12/25] Update basics/handy-stuff-strings.md Co-authored-by: Akuli --- basics/handy-stuff-strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/handy-stuff-strings.md b/basics/handy-stuff-strings.md index ba0f24e..5f53d28 100644 --- a/basics/handy-stuff-strings.md +++ b/basics/handy-stuff-strings.md @@ -424,7 +424,7 @@ ValueError: could not convert string to float: 'hello' print(message, "!!!") print(message, "!!!") ``` -3. Make a program to take the input from the user and check if it is a palindrome. +3. Make a program that asks the user to type a string and checks if it is a palindrome. The answers are [here](answers.md#handy-stuff-strings). From afafcdbfec1e029acf2b47c4b350f209c71c43ba Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:12:47 +0530 Subject: [PATCH 13/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/basics/answers.md b/basics/answers.md index e43c3f5..fd07e53 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -308,6 +308,7 @@ isn't exactly like mine but it works just fine it's ok, and you can 5. ``` python row_count = int(input("Type the number of rows needed:")) for column_count in range(1, row_count+1): + # Print numbers from 1 to column_count for number in range(1, column_count+1): print(number, end=" ") print() # creates a new line for the next row From 9f35e3a069420eeba63b0a134af71a69775970a9 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:18:20 +0530 Subject: [PATCH 14/25] updated handy-stuff-strings.md --- basics/handy-stuff-strings.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basics/handy-stuff-strings.md b/basics/handy-stuff-strings.md index ba0f24e..9cc532c 100644 --- a/basics/handy-stuff-strings.md +++ b/basics/handy-stuff-strings.md @@ -424,7 +424,8 @@ ValueError: could not convert string to float: 'hello' print(message, "!!!") print(message, "!!!") ``` -3. Make a program to take the input from the user and check if it is a palindrome. +3. Make a program to take the input from the user and check if it is a palindrome.
+ (Hint: Google how to reverse a string) The answers are [here](answers.md#handy-stuff-strings). From ea0d4e6d3bd254d616679a8b2f4e5cde74821511 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:29:18 +0530 Subject: [PATCH 15/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index fd07e53..27b61a5 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -160,8 +160,7 @@ isn't exactly like mine but it works just fine it's ok, and you can and the reversed sting(`palindrome_check`) is the same using a simple `if loop` ```python palindrome_input=input("Type the number to check:") - palindrome_check=palindrome_input[::-1] #Reverses the string - if palindrome_input==palindrome_check: + if palindrome_input == palindrome_input[::-1]: print(f"This number is a palindrome") else: print("This number is not a palindrome") From 69e62b32a0f139552826cd260ee0d383eab767a3 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:39:54 +0530 Subject: [PATCH 16/25] updated handy-stuff-strings.md --- basics/answers.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index fd07e53..2bb384a 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -319,16 +319,17 @@ isn't exactly like mine but it works just fine it's ok, and you can -6. The idea is more or less same as in the above question. - ```python +6. ```python row_count=int(input("Type the number of rows needed:")) - for column_count in range(1, row_count + 1): - for number in range(row_count,column_count+1): + for column_count in range(1, row_count + 1): # first for loop + for number in range(column_count,row_count+1):# second for loop print(number, end=' ') print() ``` - +Here,the first for loop fetches us the column to which we have to add the number.
+Now,suppose the column is 2.The second for loop finds all the numbers that lie between the column number(i.e. here 2) and the total rows we need.
+If total rows we need is 5 then we get 2,3,4 and 5 in the second for loop ## Trey Hunner: zip and enumerate 1. Read some lines with `input` into a list and then enumerate it. From b2e23dfdecaee92d9e779545cd0dceb10a9ffcda Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Wed, 14 Jul 2021 02:48:06 +0530 Subject: [PATCH 17/25] updated handy-stuff-strings.md --- basics/answers.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index c477d7a..c4325ad 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -326,9 +326,10 @@ isn't exactly like mine but it works just fine it's ok, and you can print(number, end=' ') print() ``` -Here,the first for loop fetches us the column to which we have to add the number.
-Now,suppose the column is 2.The second for loop finds all the numbers that lie between the column number(i.e. here 2) and the total rows we need.
-If total rows we need is 5 then we get 2,3,4 and 5 in the second for loop + Here,the first `for` loop fetches us the column to which we have to add the number.
+ Now,suppose the column is `2`.The second `for` loop finds all the numbers that lie between the column number(i.e. here 2) and the total rows we need. + Eg:If total rows we need is 5 then we get 2,3,4 and 5 in the second `for` loop, when column_count is 2
+ ## Trey Hunner: zip and enumerate 1. Read some lines with `input` into a list and then enumerate it. From 7e79089d3c3cf78e0eb3625531541e2cc2510d99 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:11:56 +0530 Subject: [PATCH 18/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/answers.md b/basics/answers.md index c4325ad..017fa1c 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -161,7 +161,7 @@ isn't exactly like mine but it works just fine it's ok, and you can ```python palindrome_input=input("Type the number to check:") if palindrome_input == palindrome_input[::-1]: - print(f"This number is a palindrome") + print("This string is a palindrome") else: print("This number is not a palindrome") ``` From 8cbe80f3e91b2ff31b525582cf34bcd7fc38638f Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:12:20 +0530 Subject: [PATCH 19/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index 017fa1c..9ba8f1a 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -321,8 +321,8 @@ isn't exactly like mine but it works just fine it's ok, and you can 6. ```python row_count=int(input("Type the number of rows needed:")) - for column_count in range(1, row_count + 1): # first for loop - for number in range(column_count,row_count+1):# second for loop + for line_number in range(1, row_count + 1): + for number in range(line_number, row_count+1): print(number, end=' ') print() ``` From 0e407c302cfe2023fdbba1b3f5a80687a4174cdf Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:12:37 +0530 Subject: [PATCH 20/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index 9ba8f1a..ba68e6e 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -327,8 +327,7 @@ isn't exactly like mine but it works just fine it's ok, and you can print() ``` Here,the first `for` loop fetches us the column to which we have to add the number.
- Now,suppose the column is `2`.The second `for` loop finds all the numbers that lie between the column number(i.e. here 2) and the total rows we need. - Eg:If total rows we need is 5 then we get 2,3,4 and 5 in the second `for` loop, when column_count is 2
+ 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)`. ## Trey Hunner: zip and enumerate From 228c862707a425413124eebdf5b266aa660cd759 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:13:07 +0530 Subject: [PATCH 21/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index ba68e6e..1c920aa 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -312,9 +312,14 @@ isn't exactly like mine but it works just fine it's ok, and you can print(number, end=" ") print() # creates a new line for the next row ``` - We actually use the first `for` loop to loop through the number of rows needed.Now, - through that `for` loop we got to which column the number should be inserted. - Now,the next `for` loop helps us to identify which numbers should be printed on the row which we currently accessed from the `for` loop above + If the user enters 5, we want to do a row with 1 column, then 2 columns, and so on until 5 columns. + That would be `for column_count in range(1, 6)`, because the end of the range is excluded. + In general, we need to specify `row_count + 1` so that it actually ends at `row_count`. + The second loop is similar. + + Usually `print(number)` puts a newline character at the end of the line, so that the next print goes to the next line. + To get all numbers on the same line, we use a space instead of a newline character, + but we still need `print()` to add a newline character once we have printed the entire row. From ea2f5f76a67924495e7c7877be3efbc7ae7f9e4f Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:13:19 +0530 Subject: [PATCH 22/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/answers.md b/basics/answers.md index 1c920aa..fa9fefa 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -331,7 +331,7 @@ isn't exactly like mine but it works just fine it's ok, and you can print(number, end=' ') print() ``` - Here,the first `for` loop fetches us the column to which we have to add the number.
+ Just like in the previous exercise, if the user enters 5, the first `for` loop gives the line numbers `1, 2, 3, 4, 5`.
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)`. ## Trey Hunner: zip and enumerate From b9ef72918aa192530dd0d47115a53021007807a9 Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:13:52 +0530 Subject: [PATCH 23/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/answers.md b/basics/answers.md index fa9fefa..ffceaf4 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -163,7 +163,7 @@ isn't exactly like mine but it works just fine it's ok, and you can if palindrome_input == palindrome_input[::-1]: print("This string is a palindrome") else: - print("This number is not a palindrome") + print("This string is not a palindrome") ``` ## Lists and tuples From f8549e8434fd51d991589072892b138303e2152c Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Sat, 31 Jul 2021 00:48:37 +0530 Subject: [PATCH 24/25] Update basics/answers.md Co-authored-by: Akuli --- basics/answers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index ffceaf4..f2fcdf1 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -156,8 +156,8 @@ isn't exactly like mine but it works just fine it's ok, and you can print(message, "!!!") print(message, "!!!") ``` -3. Here, we create a new variable `palindrome_check`.We use this variable to store the reversed string(of`palindrome_input`). Then we check if the string that was given(`palindrome_input`) - and the reversed sting(`palindrome_check`) is the same using a simple `if loop` +3. In the code below, `palindrome_input[::-1]` is the string `palindrome_input` reversed. + For example, if `palindrome_input` is `"hello"`, then `palindrome_input[::-1]` is `"olleh"`. ```python palindrome_input=input("Type the number to check:") if palindrome_input == palindrome_input[::-1]: From 985a52f1b99680ed285f4d861c889b5641e0deee Mon Sep 17 00:00:00 2001 From: George Rahul <75750164+georgerahul24@users.noreply.github.com> Date: Sat, 31 Jul 2021 00:49:04 +0530 Subject: [PATCH 25/25] Update basics/handy-stuff-strings.md Co-authored-by: Akuli --- basics/handy-stuff-strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basics/handy-stuff-strings.md b/basics/handy-stuff-strings.md index 9cc532c..c8458ce 100644 --- a/basics/handy-stuff-strings.md +++ b/basics/handy-stuff-strings.md @@ -425,7 +425,7 @@ ValueError: could not convert string to float: 'hello' print(message, "!!!") ``` 3. Make a program to take the input from the user and check if it is a palindrome.
- (Hint: Google how to reverse a string) + (Hint: A string is a palindrome if it is the same when reversed. Google how to reverse a string.) The answers are [here](answers.md#handy-stuff-strings).