+ 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)
21 Antworten
+ 16
# no capital P
print(c)
+ 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.
+ 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.
+ 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.
+ 8
Zarafshan Amiri ,
> first of all you should mention the tutorial name and also the lesson name / number.
+ 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.
+ 4
Zarafshan Amiri Instead of using 2005 and 2011 you should use input() function to read the values into variables and use those variables.
+ 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.
+ 3
Your code attempts to only answer the sample(hardcoded), it doesn't answer ALL possible inputs a user could enter.
+ 2
But i am confused what is wrong with my code?
+ 2
Thank you so much everyone, finally done with no begs
+ 1
Thats in lowercase but here thats printed
+ 1
Sorry I didn't see that 😕 it's my typing fault
+ 1
Haa once again thank you to correct my mistakes 😊
+ 1
i think you can see
print(c)
+ 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)
+ 1
a = 2005
b = 2011
c = list(range(a, b))
print(c)
0
Please assist me because i have been not moving forward for 2 weeks because of this code
0
Hardcoded??! Like?
0
Python/list/range