About 359,000 results
Open links in new tab
  1. python - LeetCode - 2. Add Two Numbers - Stack Overflow

    Dec 13, 2023 · Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.

  2. How can I perform math operations on binary numbers?

    May 17, 2023 · The operations add, subtract, and compare operate on numbers - 101 base 2 == 5 base 10 and addition is the same logical operation no matter what base you're working in. The fact that your python interpreter may store things as binary internally doesn't affect how you work with it - if you have an integer type, just use +, -, etc.

  3. python - how to sum two numbers in a list? - Stack Overflow

    The main problem with solutions testing all possible couples (with imbricated loops or itertools.combinations) is that that are O(n^2), as you basically test all possible combinations of two elements among n (there are n*(n-1)/2 such combinations) until you find a valid one.

  4. Python not summing (add) numbers, just sticking them together

    Oct 23, 2017 · In python (and a lot of other languages), the + operator serves a dual purpose. It can be used to get the sum of two numbers (number + number), or concatenate strings (string + string). Concatenate here means join together. When you use raw_input, you get back the user's input in the form of a string.

  5. Using recursion to sum two numbers (python) - Stack Overflow

    May 2, 2010 · I need to write a recursive function that can add two numbers (x, y), assuming y is not negative. I need to do it using two functions which return x-1 and x+1, and I can't use + or - anywhere in th...

  6. sum of two numbers coming from the command line

    import sys try: a, b = sys.argv[1:3] print "sum is ", float(a) + float(b) except ValueError: print "please give me two numbers to sum" Beware that floating points are different from real numbers, so that you could obtain seemingly "strange" results about which there is a wealth of documentation on the web.

  7. python - Function to sum multiple numbers - Stack Overflow

    Apr 26, 2018 · I'm new to python and I started learning to execute function. And I started adding numbers but I could only sum two numbers and if I wanted to sum more, it would require I edit the program. Here's my code. def sum(num1,num2): return num1+num2 a=5 b=7 c=sum(a,b) print (c)

  8. class - python classes adding numbers - Stack Overflow

    Dec 8, 2011 · I need to write a class, Numbers, with methods addNumbers and currentSum, that prints the current sum. Eg.: numbers = Numbers() numbers.addNumber(3) numbers.addNumber(2) print numbers.currentSum()

  9. adding two value in a class in python - Stack Overflow

    Nov 3, 2016 · I am knew at this and not sure the exact syntax to use to add x,y in python using this class definition class Add(values): def __init__(self, x, y): values.__init__(self, [x, y]) ...

  10. How can I concatenate two integers in Python? - Stack Overflow

    Oct 11, 2012 · The best way to do this in python was given in the accepted answer - but if you want to do this in jinja2 templates - the concatenation operator ~ gives you a neat way of doing this since it looks for the unicode representation of all …

Refresh