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?
8/27/2021 6:25:09 AM
Adi Purnomo16 Answers
New AnswerThat'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
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
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.
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.
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 :(
But i use input() function, the code can't working. they don't give me the option of input() Sorry bad English
Python learned : Yeah, before that. I try that code and still can't make 2 questions true
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?
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message