+ 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?

27th Aug 2021, 6:25 AM
Adi Purnomo
Adi Purnomo - avatar
16 ответов
+ 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
27th Aug 2021, 7:12 AM
Python Learner
Python Learner - avatar
+ 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
27th Aug 2021, 7:18 AM
Python Learner
Python Learner - avatar
+ 4
a = int(input()) b = int(input()) print(a + b) It's not difficult :)
28th Aug 2021, 8:18 PM
Rostyslaw Baidak
Rostyslaw Baidak - avatar
+ 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.
27th Aug 2021, 7:04 AM
Python Learner
Python Learner - avatar
+ 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.
27th Aug 2021, 7:13 AM
Adi Purnomo
Adi Purnomo - avatar
+ 2
Thanks everyone, you're amazing :)
27th Aug 2021, 7:16 AM
Adi Purnomo
Adi Purnomo - avatar
+ 1
Adi Purnomo share your code with us , we Will try to tell your mistakes
27th Aug 2021, 6:35 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
NO , u have to write only one code the output is correct
27th Aug 2021, 7:01 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
:/ theres an easy method #input: 2+4/(12/6+3) print(eval(input())) output: 2.8
28th Aug 2021, 7:17 PM
「 」
「 」 - avatar
0
a = 6 b = 3 print(a+b) In test case 1 i got right
27th Aug 2021, 6:36 AM
Adi Purnomo
Adi Purnomo - avatar
0
This question are in " 17 code project python "
27th Aug 2021, 6:38 AM
Adi Purnomo
Adi Purnomo - avatar
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 :(
27th Aug 2021, 7:04 AM
Adi Purnomo
Adi Purnomo - avatar
0
But thanks for replying my question
27th Aug 2021, 7:04 AM
Adi Purnomo
Adi Purnomo - avatar
0
But i use input() function, the code can't working. they don't give me the option of input() Sorry bad English
27th Aug 2021, 7:07 AM
Adi Purnomo
Adi Purnomo - avatar
0
Python learned : Yeah, before that. I try that code and still can't make 2 questions true
27th Aug 2021, 7:16 AM
Adi Purnomo
Adi Purnomo - avatar
- 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?
27th Aug 2021, 6:40 AM
Adi Purnomo
Adi Purnomo - avatar