0

I was trying to play around with raw_input and dind't got any much of success. Basically the idea is to sum, minus, and multiply two different numbers.

if __name__ == '__main__':
    a = raw_input()
    b = raw_input()

print(a+b)

So it says that I need to define raw_input. I was wondering if there's any way to input from the console 2 numbers randomly. As far as I know raw_input stores the data in the system?

Z Kubota
  • 155
  • 1
  • 3
  • 11
  • 1
    What version of Python? – 001 Jan 06 '20 at 17:22
  • Was trying with 3.6.5, but seems it was removed in pyhton3 so I was wondering if there's any other way to do it. – bl4ckch4ins Jan 06 '20 at 17:24
  • 1
    @bl4ckch4ins I think you are misunderstanding a few things. `raw_input` in python 2, is nearly identical to `input` in python 3, I'm assuming that you are on python 3 and that's why you are getting it confused. Could you elaborate on what you mean by "to input from the console 2 numbers randomly" I'm not sure what would be random about console input. @Irfanuddin's answer would suffice if you simply are trying to convert console input into numbers then add them. – OsmosisJonesLoL Jan 06 '20 at 17:26
  • Python 3.x doesn't have a `raw_input()` function. Use `int(input())` or `float(input())` for numeric values. See [PEP 3111](https://www.python.org/dev/peps/pep-3111/). – martineau Jan 06 '20 at 17:27

2 Answers2

0

Try this :

if __name__ == '__main__':
    a = input()
    b = input()

print(a+b)
whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46
Vikas Sharma
  • 451
  • 2
  • 8
0

Python3 has no raw_input(). The input() function is equivalent of the previous one.

If you want to add the numbers or perform any other arithmetic operations, you have to convert to an Integer or float.

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print(a+b)

If you want the operation to happen endlessly, simply put it inside a while True loop.

Irfanuddin
  • 2,295
  • 1
  • 15
  • 29