+ 2
Why does this not work?
4 ответов
+ 4
Here are some explanations why the code does not work properly in some cases.
This part of the code has some issues of program logic. Syntax is all ok.
But you should use a different sign for square root, e.g 'sqr', because it's difficult to guess how to input this sign.
...
if y!= "sqr" or y!="!": #(1)
z= int(input ("2. number: "))
if y not in 'sqr !':
z= int(input ("2. number: "))
if x!= 0 and z != 0 : #(2)
...
(1) if you have given an input of 'sqr', the expressions give the following result:
y!= "sqr" -> False
y!= "!" -> True
So we have for the complete expression:
if False or True: -> this results to True. In this case, the second number is asked for input.
To avoid this use 'if y!= "sqr" and y!="!": #(1)'.
(2) In case the above code is not executed, there is no variable z initialized. But z is used in:
if x!= 0 and z != 0 :
To avoid this, initialize a variable in the top of the code with z = 0. This is only a work around, and you should think about a way that is more clear and clean.
+ 5
Sauron24 , please give a clear description what is not working. Also put name of programming language in a tag. Thanks!
+ 2
It is Python, and the thing is that When I added a conditional for the z input It said it didnt work
Also thank you very much
+ 2
Thank you I finaly got it working
I know It is not the best way to do it, its just I am a bit noob😅😅😅