0

please help me... "Read in two numbers from user input without a prompt, add them, and print the result. Hint: Use int() to convert the numbers to integers.

Note: These activities may test code with different test values. This activity will perform two tests: the first with num1 = 5 and num2 = 10, the second with num1 = 6 and num2 = 3. "

I tried just doing one and it didn't work but I can't wrap my head around how to do two tests let alone one... I tried this so far and it came out with 510..noob please help

num1=int(input(5)) 
num2=int(input(10))
num3=num1 + num2
dazedandconfused
  • 33
  • 2
  • 2
  • 7
  • Possible duplicate of [Python: user input and commandline arguments](http://stackoverflow.com/questions/70797/python-user-input-and-commandline-arguments) – Keiwan Jul 18 '16 at 19:40

4 Answers4

4

The argument to the input() function is the string to display as a prompt.

In your case, you'd want that to be simply input().

  • also `input()` evaluates to `int` automatically so you could remove that to just `num1=input()` – depperm Jul 18 '16 at 19:40
  • @depperm: Are you sure about that? The return value of input() is always a Type 'str'. https://docs.python.org/3/library/functions.html#input – sir_snoopalot Jul 18 '16 at 19:48
  • 1
    it evaluates it, see http://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers-in-python – depperm Jul 18 '16 at 19:50
  • Ahh I see, the input() function in Python2.x has different behavior. My answer is only valid for Python3.x where raw_input and input are the same. Learnt something new today. Cheers! – sir_snoopalot Jul 18 '16 at 19:55
0

Don't pass parameters into input. You're asking the user for input.

I don't think the assignment is asking you to write your own tests. I think it's saying that whatever code you give it will be tested.

Athena
  • 3,200
  • 3
  • 27
  • 35
0

in fact you need just:

num1 = int(input())
num2 = int(input())
num3 = num1+num2
print(num3)
Nik P
  • 89
  • 7
0
person_name = input()
person_age = int(input())
AFM
  • 1