'<=' not supported between instances of 'list' and 'int'. Beginner and do not...












3















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!










share|improve this question




















  • 1





    createDayNumberList () returns a list, which sets dayNumber to a list. Then you do dayNumber <= endOfMonth.

    – Loocid
    Nov 26 '18 at 3:57
















3















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!










share|improve this question




















  • 1





    createDayNumberList () returns a list, which sets dayNumber to a list. Then you do dayNumber <= endOfMonth.

    – Loocid
    Nov 26 '18 at 3:57














3












3








3








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!










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 sets dayNumber to a list. Then you do dayNumber <= endOfMonth.

    – Loocid
    Nov 26 '18 at 3:57














  • 1





    createDayNumberList () returns a list, which sets dayNumber to a list. Then you do dayNumber <= 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












1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer





















  • 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











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
});


}
});














draft saved

draft discarded


















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









2














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.






share|improve this answer





















  • 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
















2














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.






share|improve this answer





















  • 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














2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin