I dont understand what is wrong with my calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I dont understand what is wrong with my calculator

I created a calculator in python, its in my profile. Its in greek but you can easily recognize the operators.

1st May 2020, 9:07 PM
sofronis
sofronis - avatar
14 Answers
+ 3
Code Playground does not allow interactive input. All input must be given upfront, before running the code. See this code to understand how input is handled in Code Playground https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
1st May 2020, 9:34 PM
Ipang
+ 3
It is not an issue, there's nothing to fix. It is because your code requires input repetitively, until it reads "skata" which breaks the loop. So each operation requires 3 lines in input dialog. For example: sin 10 5 plin 10 5 skata This will sum 10 and 5, subtract 10 and 5 and exit. You really need to see the code I attached earlier to understand how input works.
1st May 2020, 11:07 PM
Ipang
+ 2
Move line 2 - 7 out of the loop if you want to see it only once. Don't forget to adjust the indentation proportionally.
2nd May 2020, 2:17 AM
Ipang
+ 1
Line 20, change num to num1. num is unknown. See the code I attached to understand how to give input 👍
1st May 2020, 9:46 PM
Ipang
+ 1
I don't see any problem at line 8, can you describe what error you get? I would assume it was EOFError which was triggered by your code's design, which requires user input interactively. There's a problem at line 31, because <result> is a float and not a string. I would recommend to use comma when printing output. No problem with different types when comma is used to print multiple stuffs. So instead of 👇 print("i apantisi einai" + result) Using + like this, <result> needs to be converted to a string first, But if you do print("i apantisi einai", result) Using comma like this, no conversion of <result> is necessary.
1st May 2020, 10:55 PM
Ipang
+ 1
num1=float(input("grapse arithmo:")) print(num1) num2=float(input("grapse akoma ena:")) print(num2) You only need to explicitly print the input in SoloLearn, it's not necessary if you run the code on console, as the input we type in is fed through by pressing Enter key, which inserts a new line.
2nd May 2020, 5:33 PM
Ipang
0
Ipang can you check out my code, cause i havent figured out what i did wrong, or what i should put in the input
1st May 2020, 9:40 PM
sofronis
sofronis - avatar
0
Ipang thanks for line20 , apparantly there is another problem in line 8 which i cant figure out
1st May 2020, 10:37 PM
sofronis
sofronis - avatar
0
Ipang thanks for the suggestion of comma. And yes, line 8 always brings an ELFError, can we fix that?
1st May 2020, 11:01 PM
sofronis
sofronis - avatar
0
Ipang aha. So i need to break my calculator with skata each time. Last question , why do the 4 sentences of (vale sin gia na prostheseis etc..) show up double? If you pay attention, there are 4 sentences, then my result, and then they get printed again
1st May 2020, 11:14 PM
sofronis
sofronis - avatar
0
Ipang i removed the spaces from 2-7 but there is an error in line 2
2nd May 2020, 2:02 PM
sofronis
sofronis - avatar
0
I meant to say that line 2 - 7 needs to be moved up, before the line `while True:`
2nd May 2020, 3:44 PM
Ipang
0
Ipang thanks it works. How do i put "grapse enan arithmo" "grapse akoma ena" in separate lines. Do i put \n ?
2nd May 2020, 5:22 PM
sofronis
sofronis - avatar
0
Line 20 is the error
3rd May 2020, 5:25 AM
Gowtham P