Why is 'NoneType' object not iterable in HackerRank, but not PyCharm?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Using Python 3.x, I'm trying to round up students grades given a teacher's weird way of grading. Basically, if the student grade is below 38, do nothing. If the difference between the grade and the next multiple of 5 is less than 3, round the grade up to the next multiple of 5. Otherwise, don't change the grade. Here is the code I've used in both PyCharm and HackerRank's web-based IDE:



grades = [37, 39, 52, 83, 91]

def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

gradingStudents(grades)


The output in PyCharm is correct:



37
40
52
85
91


For comparison, here is the code from from the web-based IDE in HackerRank (https://www.hackerrank.com/):



#!/bin/python3
import os
import sys

#
# Complete the gradingStudents function below.
#
def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

if __name__ == '__main__':
f = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

grades =

for _ in range(n):
grades_item = int(input())
grades.append(grades_item)

result = gradingStudents(grades)

f.write('n'.join(map(str, result))) #<-- This is line 32 from error!
f.write('n')

f.close()


This throws the following error:



Traceback (most recent call last):
File "solution.py", line 32, in <module>
f.write('n'.join(map(str, result)))
TypeError: 'NoneType' object is not iterable









share|improve this question

























  • Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

    – Sreeram TP
    Nov 17 '18 at 4:46








  • 2





    It looks like HackerRank is expecting you to return the answer, rather than printing it...

    – jasonharper
    Nov 17 '18 at 4:49











  • Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

    – Andy
    Nov 17 '18 at 4:56











  • The Hackerrank website uses the above code to insert it's own test cases.

    – Andy
    Nov 17 '18 at 4:57






  • 1





    My bad, append to a list at the end of the loop, like the answer just posted. :)

    – Austin
    Nov 17 '18 at 5:18


















0















Using Python 3.x, I'm trying to round up students grades given a teacher's weird way of grading. Basically, if the student grade is below 38, do nothing. If the difference between the grade and the next multiple of 5 is less than 3, round the grade up to the next multiple of 5. Otherwise, don't change the grade. Here is the code I've used in both PyCharm and HackerRank's web-based IDE:



grades = [37, 39, 52, 83, 91]

def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

gradingStudents(grades)


The output in PyCharm is correct:



37
40
52
85
91


For comparison, here is the code from from the web-based IDE in HackerRank (https://www.hackerrank.com/):



#!/bin/python3
import os
import sys

#
# Complete the gradingStudents function below.
#
def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

if __name__ == '__main__':
f = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

grades =

for _ in range(n):
grades_item = int(input())
grades.append(grades_item)

result = gradingStudents(grades)

f.write('n'.join(map(str, result))) #<-- This is line 32 from error!
f.write('n')

f.close()


This throws the following error:



Traceback (most recent call last):
File "solution.py", line 32, in <module>
f.write('n'.join(map(str, result)))
TypeError: 'NoneType' object is not iterable









share|improve this question

























  • Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

    – Sreeram TP
    Nov 17 '18 at 4:46








  • 2





    It looks like HackerRank is expecting you to return the answer, rather than printing it...

    – jasonharper
    Nov 17 '18 at 4:49











  • Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

    – Andy
    Nov 17 '18 at 4:56











  • The Hackerrank website uses the above code to insert it's own test cases.

    – Andy
    Nov 17 '18 at 4:57






  • 1





    My bad, append to a list at the end of the loop, like the answer just posted. :)

    – Austin
    Nov 17 '18 at 5:18














0












0








0








Using Python 3.x, I'm trying to round up students grades given a teacher's weird way of grading. Basically, if the student grade is below 38, do nothing. If the difference between the grade and the next multiple of 5 is less than 3, round the grade up to the next multiple of 5. Otherwise, don't change the grade. Here is the code I've used in both PyCharm and HackerRank's web-based IDE:



grades = [37, 39, 52, 83, 91]

def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

gradingStudents(grades)


The output in PyCharm is correct:



37
40
52
85
91


For comparison, here is the code from from the web-based IDE in HackerRank (https://www.hackerrank.com/):



#!/bin/python3
import os
import sys

#
# Complete the gradingStudents function below.
#
def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

if __name__ == '__main__':
f = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

grades =

for _ in range(n):
grades_item = int(input())
grades.append(grades_item)

result = gradingStudents(grades)

f.write('n'.join(map(str, result))) #<-- This is line 32 from error!
f.write('n')

f.close()


This throws the following error:



Traceback (most recent call last):
File "solution.py", line 32, in <module>
f.write('n'.join(map(str, result)))
TypeError: 'NoneType' object is not iterable









share|improve this question
















Using Python 3.x, I'm trying to round up students grades given a teacher's weird way of grading. Basically, if the student grade is below 38, do nothing. If the difference between the grade and the next multiple of 5 is less than 3, round the grade up to the next multiple of 5. Otherwise, don't change the grade. Here is the code I've used in both PyCharm and HackerRank's web-based IDE:



grades = [37, 39, 52, 83, 91]

def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

gradingStudents(grades)


The output in PyCharm is correct:



37
40
52
85
91


For comparison, here is the code from from the web-based IDE in HackerRank (https://www.hackerrank.com/):



#!/bin/python3
import os
import sys

#
# Complete the gradingStudents function below.
#
def gradingStudents(grades):
for i in range(len(grades)):
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val
print(grade)

if __name__ == '__main__':
f = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

grades =

for _ in range(n):
grades_item = int(input())
grades.append(grades_item)

result = gradingStudents(grades)

f.write('n'.join(map(str, result))) #<-- This is line 32 from error!
f.write('n')

f.close()


This throws the following error:



Traceback (most recent call last):
File "solution.py", line 32, in <module>
f.write('n'.join(map(str, result)))
TypeError: 'NoneType' object is not iterable






python python-3.x pycharm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 5:05







Andy

















asked Nov 17 '18 at 4:42









AndyAndy

439316




439316













  • Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

    – Sreeram TP
    Nov 17 '18 at 4:46








  • 2





    It looks like HackerRank is expecting you to return the answer, rather than printing it...

    – jasonharper
    Nov 17 '18 at 4:49











  • Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

    – Andy
    Nov 17 '18 at 4:56











  • The Hackerrank website uses the above code to insert it's own test cases.

    – Andy
    Nov 17 '18 at 4:57






  • 1





    My bad, append to a list at the end of the loop, like the answer just posted. :)

    – Austin
    Nov 17 '18 at 5:18



















  • Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

    – Sreeram TP
    Nov 17 '18 at 4:46








  • 2





    It looks like HackerRank is expecting you to return the answer, rather than printing it...

    – jasonharper
    Nov 17 '18 at 4:49











  • Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

    – Andy
    Nov 17 '18 at 4:56











  • The Hackerrank website uses the above code to insert it's own test cases.

    – Andy
    Nov 17 '18 at 4:57






  • 1





    My bad, append to a list at the end of the loop, like the answer just posted. :)

    – Austin
    Nov 17 '18 at 5:18

















Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

– Sreeram TP
Nov 17 '18 at 4:46







Is that the full code.? Try doing like print(gradingStudents(grades)) in Hackerrank

– Sreeram TP
Nov 17 '18 at 4:46






2




2





It looks like HackerRank is expecting you to return the answer, rather than printing it...

– jasonharper
Nov 17 '18 at 4:49





It looks like HackerRank is expecting you to return the answer, rather than printing it...

– jasonharper
Nov 17 '18 at 4:49













Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

– Andy
Nov 17 '18 at 4:56





Added the entire code from hackerrank.com. Also, putting return, vice print(), throws the same error: 'NoneType' object is not iterable

– Andy
Nov 17 '18 at 4:56













The Hackerrank website uses the above code to insert it's own test cases.

– Andy
Nov 17 '18 at 4:57





The Hackerrank website uses the above code to insert it's own test cases.

– Andy
Nov 17 '18 at 4:57




1




1





My bad, append to a list at the end of the loop, like the answer just posted. :)

– Austin
Nov 17 '18 at 5:18





My bad, append to a list at the end of the loop, like the answer just posted. :)

– Austin
Nov 17 '18 at 5:18












3 Answers
3






active

oldest

votes


















1














Hackerrank is expecting a list of grades to be returned from your function, you are returning nothing, just printing.



def gradingStudents(grades):
result = # make an empty list
for i in range(len(grades)): # assuming this logic is correct
grade = grades[i]
if grade > 38:
for j in range(4):
next_val = grade + j
if ((next_val-grade) < 3) and (next_val%5 == 0):
grade = next_val

result.append(grade) # append the grade to list
return result # return the list, you had no return statement so it was returning none





share|improve this answer































    1














    The problem is because your function returns nothing or None, and therefore join will return an error. print only prints the value and does not return anything, yes it prints in your PyCharm IDE but nothing is being returned from it.



    If you want to use those values, I have slightly modified your code for it to return a new list after applying your logic by adding f_grades which is a list in the function.



    import os
    import sys

    #
    # Complete the gradingStudents function below.
    #
    def gradingStudents(grades):
    f_grade =
    for i in range(len(grades)):
    grade = grades[i]
    if grade > 38:
    for j in range(4):
    next_val = grade + j
    if ((next_val-grade) < 3) and (next_val%5 == 0):
    grade = next_val
    f_grade.append(grade)
    return f_grade

    if __name__ == '__main__':
    #f = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    grades =

    for _ in range(n):
    grades_item = int(input())
    grades.append(grades_item)

    result = gradingStudents(grades)

    f.write('n'.join(map(str, result))) #<-- No more error!
    f.write('n')

    f.close()


    What it does instead, without rewriting the whole code, is that it adds those values in a new list after it passes the logic and returns that list. From there you will be able to apply functions to that list like join.






    share|improve this answer
























    • what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

      – Vaibhav Vishal
      Nov 17 '18 at 5:21








    • 1





      The list will be empty, it still is a list and therefore will print ''.

      – BernardL
      Nov 17 '18 at 5:27











    • but you should return grades of all students, you can't just skip some because no change in grade was necessary.

      – Vaibhav Vishal
      Nov 17 '18 at 5:29











    • I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

      – BernardL
      Nov 17 '18 at 5:32



















    1














    Here is a list-comprehension way of doing the same:



    def gradingStudents(grades):
    return [5 * (x // 5) + 5 if x > 38 and x % 5 > 2 else x for x in grades]

    print(gradingStudents([37, 39, 52, 83, 91]))
    # [37, 40, 52, 85, 91]


    This would be more efficient considering it's a comprehension and is also concise.






    share|improve this answer
























      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%2f53348289%2fwhy-is-nonetype-object-not-iterable-in-hackerrank-but-not-pycharm%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Hackerrank is expecting a list of grades to be returned from your function, you are returning nothing, just printing.



      def gradingStudents(grades):
      result = # make an empty list
      for i in range(len(grades)): # assuming this logic is correct
      grade = grades[i]
      if grade > 38:
      for j in range(4):
      next_val = grade + j
      if ((next_val-grade) < 3) and (next_val%5 == 0):
      grade = next_val

      result.append(grade) # append the grade to list
      return result # return the list, you had no return statement so it was returning none





      share|improve this answer




























        1














        Hackerrank is expecting a list of grades to be returned from your function, you are returning nothing, just printing.



        def gradingStudents(grades):
        result = # make an empty list
        for i in range(len(grades)): # assuming this logic is correct
        grade = grades[i]
        if grade > 38:
        for j in range(4):
        next_val = grade + j
        if ((next_val-grade) < 3) and (next_val%5 == 0):
        grade = next_val

        result.append(grade) # append the grade to list
        return result # return the list, you had no return statement so it was returning none





        share|improve this answer


























          1












          1








          1







          Hackerrank is expecting a list of grades to be returned from your function, you are returning nothing, just printing.



          def gradingStudents(grades):
          result = # make an empty list
          for i in range(len(grades)): # assuming this logic is correct
          grade = grades[i]
          if grade > 38:
          for j in range(4):
          next_val = grade + j
          if ((next_val-grade) < 3) and (next_val%5 == 0):
          grade = next_val

          result.append(grade) # append the grade to list
          return result # return the list, you had no return statement so it was returning none





          share|improve this answer













          Hackerrank is expecting a list of grades to be returned from your function, you are returning nothing, just printing.



          def gradingStudents(grades):
          result = # make an empty list
          for i in range(len(grades)): # assuming this logic is correct
          grade = grades[i]
          if grade > 38:
          for j in range(4):
          next_val = grade + j
          if ((next_val-grade) < 3) and (next_val%5 == 0):
          grade = next_val

          result.append(grade) # append the grade to list
          return result # return the list, you had no return statement so it was returning none






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 17 '18 at 5:16









          Vaibhav VishalVaibhav Vishal

          1,68311020




          1,68311020

























              1














              The problem is because your function returns nothing or None, and therefore join will return an error. print only prints the value and does not return anything, yes it prints in your PyCharm IDE but nothing is being returned from it.



              If you want to use those values, I have slightly modified your code for it to return a new list after applying your logic by adding f_grades which is a list in the function.



              import os
              import sys

              #
              # Complete the gradingStudents function below.
              #
              def gradingStudents(grades):
              f_grade =
              for i in range(len(grades)):
              grade = grades[i]
              if grade > 38:
              for j in range(4):
              next_val = grade + j
              if ((next_val-grade) < 3) and (next_val%5 == 0):
              grade = next_val
              f_grade.append(grade)
              return f_grade

              if __name__ == '__main__':
              #f = open(os.environ['OUTPUT_PATH'], 'w')

              n = int(input())

              grades =

              for _ in range(n):
              grades_item = int(input())
              grades.append(grades_item)

              result = gradingStudents(grades)

              f.write('n'.join(map(str, result))) #<-- No more error!
              f.write('n')

              f.close()


              What it does instead, without rewriting the whole code, is that it adds those values in a new list after it passes the logic and returns that list. From there you will be able to apply functions to that list like join.






              share|improve this answer
























              • what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

                – Vaibhav Vishal
                Nov 17 '18 at 5:21








              • 1





                The list will be empty, it still is a list and therefore will print ''.

                – BernardL
                Nov 17 '18 at 5:27











              • but you should return grades of all students, you can't just skip some because no change in grade was necessary.

                – Vaibhav Vishal
                Nov 17 '18 at 5:29











              • I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

                – BernardL
                Nov 17 '18 at 5:32
















              1














              The problem is because your function returns nothing or None, and therefore join will return an error. print only prints the value and does not return anything, yes it prints in your PyCharm IDE but nothing is being returned from it.



              If you want to use those values, I have slightly modified your code for it to return a new list after applying your logic by adding f_grades which is a list in the function.



              import os
              import sys

              #
              # Complete the gradingStudents function below.
              #
              def gradingStudents(grades):
              f_grade =
              for i in range(len(grades)):
              grade = grades[i]
              if grade > 38:
              for j in range(4):
              next_val = grade + j
              if ((next_val-grade) < 3) and (next_val%5 == 0):
              grade = next_val
              f_grade.append(grade)
              return f_grade

              if __name__ == '__main__':
              #f = open(os.environ['OUTPUT_PATH'], 'w')

              n = int(input())

              grades =

              for _ in range(n):
              grades_item = int(input())
              grades.append(grades_item)

              result = gradingStudents(grades)

              f.write('n'.join(map(str, result))) #<-- No more error!
              f.write('n')

              f.close()


              What it does instead, without rewriting the whole code, is that it adds those values in a new list after it passes the logic and returns that list. From there you will be able to apply functions to that list like join.






              share|improve this answer
























              • what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

                – Vaibhav Vishal
                Nov 17 '18 at 5:21








              • 1





                The list will be empty, it still is a list and therefore will print ''.

                – BernardL
                Nov 17 '18 at 5:27











              • but you should return grades of all students, you can't just skip some because no change in grade was necessary.

                – Vaibhav Vishal
                Nov 17 '18 at 5:29











              • I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

                – BernardL
                Nov 17 '18 at 5:32














              1












              1








              1







              The problem is because your function returns nothing or None, and therefore join will return an error. print only prints the value and does not return anything, yes it prints in your PyCharm IDE but nothing is being returned from it.



              If you want to use those values, I have slightly modified your code for it to return a new list after applying your logic by adding f_grades which is a list in the function.



              import os
              import sys

              #
              # Complete the gradingStudents function below.
              #
              def gradingStudents(grades):
              f_grade =
              for i in range(len(grades)):
              grade = grades[i]
              if grade > 38:
              for j in range(4):
              next_val = grade + j
              if ((next_val-grade) < 3) and (next_val%5 == 0):
              grade = next_val
              f_grade.append(grade)
              return f_grade

              if __name__ == '__main__':
              #f = open(os.environ['OUTPUT_PATH'], 'w')

              n = int(input())

              grades =

              for _ in range(n):
              grades_item = int(input())
              grades.append(grades_item)

              result = gradingStudents(grades)

              f.write('n'.join(map(str, result))) #<-- No more error!
              f.write('n')

              f.close()


              What it does instead, without rewriting the whole code, is that it adds those values in a new list after it passes the logic and returns that list. From there you will be able to apply functions to that list like join.






              share|improve this answer













              The problem is because your function returns nothing or None, and therefore join will return an error. print only prints the value and does not return anything, yes it prints in your PyCharm IDE but nothing is being returned from it.



              If you want to use those values, I have slightly modified your code for it to return a new list after applying your logic by adding f_grades which is a list in the function.



              import os
              import sys

              #
              # Complete the gradingStudents function below.
              #
              def gradingStudents(grades):
              f_grade =
              for i in range(len(grades)):
              grade = grades[i]
              if grade > 38:
              for j in range(4):
              next_val = grade + j
              if ((next_val-grade) < 3) and (next_val%5 == 0):
              grade = next_val
              f_grade.append(grade)
              return f_grade

              if __name__ == '__main__':
              #f = open(os.environ['OUTPUT_PATH'], 'w')

              n = int(input())

              grades =

              for _ in range(n):
              grades_item = int(input())
              grades.append(grades_item)

              result = gradingStudents(grades)

              f.write('n'.join(map(str, result))) #<-- No more error!
              f.write('n')

              f.close()


              What it does instead, without rewriting the whole code, is that it adds those values in a new list after it passes the logic and returns that list. From there you will be able to apply functions to that list like join.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 17 '18 at 5:19









              BernardLBernardL

              2,42911232




              2,42911232













              • what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

                – Vaibhav Vishal
                Nov 17 '18 at 5:21








              • 1





                The list will be empty, it still is a list and therefore will print ''.

                – BernardL
                Nov 17 '18 at 5:27











              • but you should return grades of all students, you can't just skip some because no change in grade was necessary.

                – Vaibhav Vishal
                Nov 17 '18 at 5:29











              • I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

                – BernardL
                Nov 17 '18 at 5:32



















              • what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

                – Vaibhav Vishal
                Nov 17 '18 at 5:21








              • 1





                The list will be empty, it still is a list and therefore will print ''.

                – BernardL
                Nov 17 '18 at 5:27











              • but you should return grades of all students, you can't just skip some because no change in grade was necessary.

                – Vaibhav Vishal
                Nov 17 '18 at 5:29











              • I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

                – BernardL
                Nov 17 '18 at 5:32

















              what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

              – Vaibhav Vishal
              Nov 17 '18 at 5:21







              what happens if if ((next_val-grade) < 3) and (next_val%5 == 0): is never true.

              – Vaibhav Vishal
              Nov 17 '18 at 5:21






              1




              1





              The list will be empty, it still is a list and therefore will print ''.

              – BernardL
              Nov 17 '18 at 5:27





              The list will be empty, it still is a list and therefore will print ''.

              – BernardL
              Nov 17 '18 at 5:27













              but you should return grades of all students, you can't just skip some because no change in grade was necessary.

              – Vaibhav Vishal
              Nov 17 '18 at 5:29





              but you should return grades of all students, you can't just skip some because no change in grade was necessary.

              – Vaibhav Vishal
              Nov 17 '18 at 5:29













              I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

              – BernardL
              Nov 17 '18 at 5:32





              I did not assume what it should return or not, the issue was that the function returns nothing and now it returns items that pass the user logic. The user can explicitly add or remove the values they want the function to return.

              – BernardL
              Nov 17 '18 at 5:32











              1














              Here is a list-comprehension way of doing the same:



              def gradingStudents(grades):
              return [5 * (x // 5) + 5 if x > 38 and x % 5 > 2 else x for x in grades]

              print(gradingStudents([37, 39, 52, 83, 91]))
              # [37, 40, 52, 85, 91]


              This would be more efficient considering it's a comprehension and is also concise.






              share|improve this answer




























                1














                Here is a list-comprehension way of doing the same:



                def gradingStudents(grades):
                return [5 * (x // 5) + 5 if x > 38 and x % 5 > 2 else x for x in grades]

                print(gradingStudents([37, 39, 52, 83, 91]))
                # [37, 40, 52, 85, 91]


                This would be more efficient considering it's a comprehension and is also concise.






                share|improve this answer


























                  1












                  1








                  1







                  Here is a list-comprehension way of doing the same:



                  def gradingStudents(grades):
                  return [5 * (x // 5) + 5 if x > 38 and x % 5 > 2 else x for x in grades]

                  print(gradingStudents([37, 39, 52, 83, 91]))
                  # [37, 40, 52, 85, 91]


                  This would be more efficient considering it's a comprehension and is also concise.






                  share|improve this answer













                  Here is a list-comprehension way of doing the same:



                  def gradingStudents(grades):
                  return [5 * (x // 5) + 5 if x > 38 and x % 5 > 2 else x for x in grades]

                  print(gradingStudents([37, 39, 52, 83, 91]))
                  # [37, 40, 52, 85, 91]


                  This would be more efficient considering it's a comprehension and is also concise.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 '18 at 5:37









                  AustinAustin

                  13.5k31031




                  13.5k31031






























                      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%2f53348289%2fwhy-is-nonetype-object-not-iterable-in-hackerrank-but-not-pycharm%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

                      Bressuire

                      Vorschmack

                      Quarantine