+ 2

Range/ python

I have tried many ways but showing errors, is there anyone who can help me? a = int(2005) b = int(2011) c = list(range(2005,2011)) Print(c)

13th Apr 2023, 10:41 AM
Zarafshan Amiri
Zarafshan Amiri - avatar
21 Antworten
+ 16
# no capital P print(c)
13th Apr 2023, 10:44 AM
JaScript
JaScript - avatar
+ 12
Zarafshan Amiri , ok, i found the exercise. here is the task description: You are making a date picker for a website and need to output all the years in a given period. Write a program that takes two integers as input and outputs the range of numbers between the two inputs as a list. The output sequence should start with the first input number and end with the second input number, without including it. Sample Input 2005 2011 Sample Output [2005, 2006, 2007, 2008, 2009, 2010] respecting this description, we need to use input() function to get 2 numbers. these numbers has to be converted to integer values. these values has to be used (var names) as arguments in the range() function. the result of the range has to be converted to a list. the list has to be printed.
13th Apr 2023, 11:02 AM
Lothar
Lothar - avatar
+ 9
Zarafshan Amiri , > the issue is that the code uses *hardcoded values* instead of using the variables *a* and *b*. => c = list(range(a, b)) > also *print(...)* has to be in lower case.
13th Apr 2023, 10:46 AM
Lothar
Lothar - avatar
+ 9
Zarafshan Amiri , > hard coded: there are 2 variables that get numbers from int() functions. but you never use them. instead of this, you use allways the same numbers for creating the range() when the test cases of the exercise are used.
13th Apr 2023, 10:56 AM
Lothar
Lothar - avatar
+ 8
Zarafshan Amiri , > first of all you should mention the tutorial name and also the lesson name / number.
13th Apr 2023, 10:52 AM
Lothar
Lothar - avatar
+ 6
Sofiya Shaik , it is not seen as very helpful when we are going to post a ready-made code. it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself. >>> also there are multiple issues in the code you posted: (1) print(...) has to be in lower case. (2) (...Year2 + 1) is not correct. read the task description that i have posted here: > The output sequence should start with the first input number and end with the second input number, without including it. ^^^^^^^^^^^^^^^^^^^^^ (3) the line which is going to output the result is missing a closing parenthesis. (4) the arguments (variable names) for the print() function are written in lower case, whereas they are written in upper case in the lines where input() is used.
14th Apr 2023, 5:45 AM
Lothar
Lothar - avatar
+ 4
Zarafshan Amiri Instead of using 2005 and 2011 you should use input() function to read the values into variables and use those variables.
13th Apr 2023, 1:20 PM
Евгений
Евгений - avatar
+ 4
Sofiya Shaik , read my last post to rework your code. run the code. if there are still issues, follow the error messages and fix it.
14th Apr 2023, 6:07 AM
Lothar
Lothar - avatar
+ 3
Your code attempts to only answer the sample(hardcoded), it doesn't answer ALL possible inputs a user could enter.
13th Apr 2023, 12:24 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
But i am confused what is wrong with my code?
13th Apr 2023, 11:54 AM
Zarafshan Amiri
Zarafshan Amiri - avatar
+ 2
Thank you so much everyone, finally done with no begs
13th Apr 2023, 10:47 PM
Zarafshan Amiri
Zarafshan Amiri - avatar
+ 1
Thats in lowercase but here thats printed
13th Apr 2023, 10:47 AM
Zarafshan Amiri
Zarafshan Amiri - avatar
+ 1
Sorry I didn't see that 😕 it's my typing fault
14th Apr 2023, 6:15 AM
Sofiya Shaik
+ 1
Haa once again thank you to correct my mistakes 😊
14th Apr 2023, 6:15 AM
Sofiya Shaik
+ 1
i think you can see print(c)
14th Apr 2023, 1:45 PM
Young Pro
Young Pro - avatar
+ 1
PROBLEM 1 : a = int(2005) b = int(2011) error ⚠️ : why are you using 'int' function it is not input function where it is used then don't use int function. correct ✅ : a = 2005 b = 2011 PROBLEM 2 : c = list(range(2005,2011)) error ⚠️ : don't use list skip list. correct ✅ : c = range(2005,2011)
14th Apr 2023, 2:39 PM
Ramesh Beniwal
Ramesh Beniwal - avatar
+ 1
a = 2005 b = 2011 c = list(range(a, b)) print(c)
14th Apr 2023, 11:05 PM
osman gereyxanov
osman gereyxanov - avatar
0
Please assist me because i have been not moving forward for 2 weeks because of this code
13th Apr 2023, 10:48 AM
Zarafshan Amiri
Zarafshan Amiri - avatar
0
Hardcoded??! Like?
13th Apr 2023, 10:50 AM
Zarafshan Amiri
Zarafshan Amiri - avatar
0
Python/list/range
13th Apr 2023, 10:53 AM
Zarafshan Amiri
Zarafshan Amiri - avatar