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
1

4 Answers 4

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().

Sign up to request clarification or add additional context in comments.

4 Comments

also input() evaluates to int automatically so you could remove that to just num1=input()
@depperm: Are you sure about that? The return value of input() is always a Type 'str'. docs.python.org/3/library/functions.html#input
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!
0

in fact you need just:

num1 = int(input())
num2 = int(input())
num3 = num1+num2
print(num3)

Comments

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.

Comments

0
person_name = input()
person_age = int(input())

1 Comment

Please add some explanation to your answer. It does not contain any code to perform a calculation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.