+ 1
Simple calculator
Maaf sebelumnya, tapi bagaimana cara menyelesaikan kasus simple calculator secara keseluruhan? Saya bisa menyelesaikan kasus 1, Tapi Di kasus 2 saya mendapatkan nilai salah. Jika saya tulis kode untuk kasus no 2, yang nomor 1 jadi salah yang no 2 benar. Gimana ya biar benar keduanya? #English Sorry in advance, but how to solve the whole simple calculator case? I can solve case 1, But In case 2 I get an incorrect value. If I write code for case number 2, number 1 is wrong and number 2 is correct. How do you get both right?
16 odpowiedzi
+ 6
That's because input() is string by default. So, you have to use int() function to convert it to integer. I believe you know that adding two strings and two integers are different things.
For example,
a = int(input()) -> integer
a = input() -> string
+ 5
a = int(input())
b = int(input())
print(a+b)
This is the proper way to do it. I think you missed something in that time.
You're welcome
+ 4
a = int(input())
b = int(input())
print(a + b)
It's not difficult :)
+ 2
Hi Adi!
Hard code solution always gives you a certain output.
For that, you have to use input() function to check all test cases. The required section is available on Sololearn under taking inputs lesson. You can refer that to solve your problem.
+ 2
Hey, thanks for answering my questions Delicate Cat.
I think, I need to enter numbers to solve the problem. turned out to be unnecessary. and your code managed to answer both questions.
+ 2
Thanks everyone, you're amazing :)
+ 1
Adi Purnomo share your code with us , we Will try to tell your mistakes
+ 1
NO ,
u have to write only one code
the output is correct
+ 1
:/ theres an easy method
#input: 2+4/(12/6+3)
print(eval(input()))
output: 2.8
0
a = 6
b = 3
print(a+b)
In test case 1 i got right
0
This question are in " 17 code project python "
0
Yes, but the question number 2 got me wrong answer.
I think this is bug from the app.
So i can't complete 17 code project from python :(
0
But thanks for replying my question
0
But i use input() function, the code can't working. they don't give me the option of input()
Sorry bad English
0
Python learned :
Yeah, before that. I try that code and still can't make 2 questions true
- 1
In case 1 the question are :
Input
6
3
Output
9
In case 2:
Input
11
22
Output
33
Can i wrote 2 code in same time for 2 questions?