'<=' not supported between instances of 'list' and 'int'. Beginner and do not...
I'm trying to write a program that sees if two dates match out of a list of 30 dates ranging from 1 to 365
While trying to test the program, I keep encountering the error "'<=' not supported between instances of 'list' and 'int'" and I'm not sure how to proceed.
Here is my program so far:
import random
MaxInList = 30
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
dayNumbers.append( nextDayNumber )
return dayNumbers
def determineDate( dayNumber = 1 ):
months = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
name = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
endOfMonth = 0
daysSoFar = 0
for month in range( len( months ) ):
endOfMonth += months[month]
if dayNumber <= endOfMonth:
date = name[month]
date += " " + str( dayNumber - daysSoFar )
return date
daysSoFar = endOfMonth
return "Bad date!"
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList () )
print("")
main ()
Any sort of help/feedback is greatly appreciated!
python python-3.x
add a comment |
I'm trying to write a program that sees if two dates match out of a list of 30 dates ranging from 1 to 365
While trying to test the program, I keep encountering the error "'<=' not supported between instances of 'list' and 'int'" and I'm not sure how to proceed.
Here is my program so far:
import random
MaxInList = 30
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
dayNumbers.append( nextDayNumber )
return dayNumbers
def determineDate( dayNumber = 1 ):
months = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
name = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
endOfMonth = 0
daysSoFar = 0
for month in range( len( months ) ):
endOfMonth += months[month]
if dayNumber <= endOfMonth:
date = name[month]
date += " " + str( dayNumber - daysSoFar )
return date
daysSoFar = endOfMonth
return "Bad date!"
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList () )
print("")
main ()
Any sort of help/feedback is greatly appreciated!
python python-3.x
1
createDayNumberList ()
returns a list, which setsdayNumber
to a list. Then you dodayNumber <= endOfMonth
.
– Loocid
Nov 26 '18 at 3:57
add a comment |
I'm trying to write a program that sees if two dates match out of a list of 30 dates ranging from 1 to 365
While trying to test the program, I keep encountering the error "'<=' not supported between instances of 'list' and 'int'" and I'm not sure how to proceed.
Here is my program so far:
import random
MaxInList = 30
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
dayNumbers.append( nextDayNumber )
return dayNumbers
def determineDate( dayNumber = 1 ):
months = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
name = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
endOfMonth = 0
daysSoFar = 0
for month in range( len( months ) ):
endOfMonth += months[month]
if dayNumber <= endOfMonth:
date = name[month]
date += " " + str( dayNumber - daysSoFar )
return date
daysSoFar = endOfMonth
return "Bad date!"
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList () )
print("")
main ()
Any sort of help/feedback is greatly appreciated!
python python-3.x
I'm trying to write a program that sees if two dates match out of a list of 30 dates ranging from 1 to 365
While trying to test the program, I keep encountering the error "'<=' not supported between instances of 'list' and 'int'" and I'm not sure how to proceed.
Here is my program so far:
import random
MaxInList = 30
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
dayNumbers.append( nextDayNumber )
return dayNumbers
def determineDate( dayNumber = 1 ):
months = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
name = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
endOfMonth = 0
daysSoFar = 0
for month in range( len( months ) ):
endOfMonth += months[month]
if dayNumber <= endOfMonth:
date = name[month]
date += " " + str( dayNumber - daysSoFar )
return date
daysSoFar = endOfMonth
return "Bad date!"
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList () )
print("")
main ()
Any sort of help/feedback is greatly appreciated!
python python-3.x
python python-3.x
edited Nov 26 '18 at 3:55
U9-Forward
16.9k51643
16.9k51643
asked Nov 26 '18 at 3:53
W. IshamW. Isham
182
182
1
createDayNumberList ()
returns a list, which setsdayNumber
to a list. Then you dodayNumber <= endOfMonth
.
– Loocid
Nov 26 '18 at 3:57
add a comment |
1
createDayNumberList ()
returns a list, which setsdayNumber
to a list. Then you dodayNumber <= endOfMonth
.
– Loocid
Nov 26 '18 at 3:57
1
1
createDayNumberList ()
returns a list, which sets dayNumber
to a list. Then you do dayNumber <= endOfMonth
.– Loocid
Nov 26 '18 at 3:57
createDayNumberList ()
returns a list, which sets dayNumber
to a list. Then you do dayNumber <= endOfMonth
.– Loocid
Nov 26 '18 at 3:57
add a comment |
1 Answer
1
active
oldest
votes
Issue is in your main()
function:
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList() ) ##
print("")
createDayNumberList()
returns a List
object. This is passed to determineDate()
and then the comparison is made:
if dayNumber <= endOfMonth
,
where dayNumber
is a List object and endOfMonth
is an INT
. Hence, the error.
In my understanding, since your createDayNumberList()
always returns just 1 value, you can store it in a variable rather than storing it in a list.
Something like:
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
#dayNumbers.append( nextDayNumber )
return nextDayNumber
Now, this function also returns an int
. So, the comparison in determineDate()
will always be correct.
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474586%2fnot-supported-between-instances-of-list-and-int-beginner-and-do-not-kn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Issue is in your main()
function:
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList() ) ##
print("")
createDayNumberList()
returns a List
object. This is passed to determineDate()
and then the comparison is made:
if dayNumber <= endOfMonth
,
where dayNumber
is a List object and endOfMonth
is an INT
. Hence, the error.
In my understanding, since your createDayNumberList()
always returns just 1 value, you can store it in a variable rather than storing it in a list.
Something like:
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
#dayNumbers.append( nextDayNumber )
return nextDayNumber
Now, this function also returns an int
. So, the comparison in determineDate()
will always be correct.
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
add a comment |
Issue is in your main()
function:
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList() ) ##
print("")
createDayNumberList()
returns a List
object. This is passed to determineDate()
and then the comparison is made:
if dayNumber <= endOfMonth
,
where dayNumber
is a List object and endOfMonth
is an INT
. Hence, the error.
In my understanding, since your createDayNumberList()
always returns just 1 value, you can store it in a variable rather than storing it in a list.
Something like:
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
#dayNumbers.append( nextDayNumber )
return nextDayNumber
Now, this function also returns an int
. So, the comparison in determineDate()
will always be correct.
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
add a comment |
Issue is in your main()
function:
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList() ) ##
print("")
createDayNumberList()
returns a List
object. This is passed to determineDate()
and then the comparison is made:
if dayNumber <= endOfMonth
,
where dayNumber
is a List object and endOfMonth
is an INT
. Hence, the error.
In my understanding, since your createDayNumberList()
always returns just 1 value, you can store it in a variable rather than storing it in a list.
Something like:
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
#dayNumbers.append( nextDayNumber )
return nextDayNumber
Now, this function also returns an int
. So, the comparison in determineDate()
will always be correct.
Issue is in your main()
function:
def main ():
listsToGenerate = 10
for n in range( listsToGenerate ):
determineDate( createDayNumberList() ) ##
print("")
createDayNumberList()
returns a List
object. This is passed to determineDate()
and then the comparison is made:
if dayNumber <= endOfMonth
,
where dayNumber
is a List object and endOfMonth
is an INT
. Hence, the error.
In my understanding, since your createDayNumberList()
always returns just 1 value, you can store it in a variable rather than storing it in a list.
Something like:
def createDayNumberList( howMany = MaxInList ):
dayNumbers =
for counter in range( howMany ):
nextDayNumber = random.randint( 1, 365 )
#dayNumbers.append( nextDayNumber )
return nextDayNumber
Now, this function also returns an int
. So, the comparison in determineDate()
will always be correct.
edited Nov 26 '18 at 4:14
answered Nov 26 '18 at 4:02
Mayank PorwalMayank Porwal
4,9982725
4,9982725
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
add a comment |
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
1
1
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
It worked! Thank you so much. That's one of the many issues I'm having fixed! I'm not sure how I should proceed but thank you again for the help!
– W. Isham
Nov 26 '18 at 4:41
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
@W.Isham Since the answer worked, please upvote it too. Thanks.
– Mayank Porwal
Dec 20 '18 at 12:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474586%2fnot-supported-between-instances-of-list-and-int-beginner-and-do-not-kn%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
createDayNumberList ()
returns a list, which setsdayNumber
to a list. Then you dodayNumber <= endOfMonth
.– Loocid
Nov 26 '18 at 3:57