The below code prints none at the end

0 votes
def twoSum(nums, target):
    if len(nums) <= 1:
        return False
    for i in range(len(nums)):
        print(i)

var1 = [2, 7, 11, 15]
var2 = 9
print(twoSum(var1, var2))


problem: works but prints none at the end. anyone know? i tried to change len(nums) in the for i in range line to a number like 1 and still?

Nov 15, 2020 in Python by Rajiv
• 8,880 points
52 views

1 answer to this question.

0 votes

the code after return does not execute. Your IDE should have shown you a warning about it.

Because you're printing the value of twoSum() which doesn't have one, it returns nothing.

answered Nov 15, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How to solve indentation in the below code?

Python does not use brackets, it uses ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,130 points
150 views
0 votes
1 answer

i write this python to read dataset into panda data frame but im getting NameError: name 'true' is not defined. Below is the code:

change  def parse(path):   g = gz ...READ MORE

answered Mar 14, 2020 in Python by Abhishek Shingadiya
1,201 views
0 votes
2 answers

Help me solve the code

The fetchone() method fetches the result of ...READ MORE

answered Jan 9, 2019 in Python by Omkar
• 69,130 points
133 views
0 votes
2 answers

How to add a certain time delay to the code using Python?

You can use time.sleep(duration in second) READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
240 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,033 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,556 views
0 votes
1 answer

What will be the output of below code and why? x=[1,2,3,4,5] print(x.insert(2,3))

If you write x.insert(2,3) and then print x ...READ MORE

answered Oct 14, 2020 in Python by Gitika
• 65,870 points
944 views