[The code is not in a monospace font in the image; for the purposes of readability, I have placed it in one. The code reads as follows:]
def gerade():
zahl=int(input("Geben sie eine natürliche Zahl ein."))
if(isinstance(zahl/2,int) and zahl>0):
typ="gerade"
elif(zahl>0 and zahl!=isinstance(zahl/2,int)):
typ="ungerade"
else:
typ="keine natürliche Zahl, also sind die Anforderungen nicht erfüllt"
return print("Die Zahl ist {0} und ist {1}.".format(zahl,typ))
gerade()
#gerade zahl funktioniert nicht
def isEven():
num=int(input("Enter a natural number."))
if(isinstance(num/2,int) and num>0):
type="even"
elif(num>0 and num!=isinstance(num/2,int)):
type="odd"
else:
type="not a natural number, so the requirements are not fulfilled"
return print("The number {0} is {1}.".format(num,type))
isEven()
#isEven does not work
According to the string literals, input should be a natural number, so it may be just a mistake on the programmer's side using > where it should be >=.
140
u/TheBrainStone Mar 14 '22
That's what happens when mathematicians try to code
30
u/future_escapist Mar 14 '22 edited Mar 14 '22
Doesn't dividing a whole, even number also return a float? 8 / 2 = 4.0
Ich denke, dass er den modulus operator noch nicht gesehen hat.
2
u/LocalBall6447 Mar 15 '22
Man hätte einfach einen einzeiler draus machen können : return Zahl % 2 == 0. % ist der Restoperator
70
u/Knuffya Mar 14 '22
Ich glaube, ich muss mich gleich übergeben.
Das passiert, wenn Mathematiker kodieren.
38
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 14 '22
Image Transcription: Code
[The code is not in a monospace font in the image; for the purposes of readability, I have placed it in one. The code reads as follows:]
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
31
u/WasserTyp69 Mar 14 '22
#gerade zahl funktioniert nichtHmm. I wonder why.
41
u/alban228 Mar 14 '22
German making it harder to read lmao
15
u/dasmarcy Mar 14 '22
Fremdschämen
12
u/Schreibtisch69 Mar 14 '22
Siezing someone and writing sie with a small letter is certainly bad code.
4
u/mfb- Mar 14 '22
Is that comparing an integer with a boolean?
4
u/liquidmasl Mar 15 '22
as a german speaker myself, german variables make me all tingly, in a bad way haha
3
u/darkpanther1 Mar 14 '22
He should have written it in Teuton
3
u/walterbanana Mar 15 '22
This is just a high school project it seems. Of course it is bad.
2
u/ClariNerd617 Apr 13 '22
Oh man running flake8 against this might actually freeze the computer lol
2
u/keethraxmn Mar 14 '22 edited Mar 14 '22
Do the requirements not include 0 as a possible input? (Or negatives, but eliminating zero feels extra weird)
(Yes, I see the other stuff, but other people have addressed those things already)
1
u/ManiaRhythm Mar 15 '22
Just goes to show that code is a universal language.
1
u/IDestroySkids Jul 01 '22
uhm what
-13
u/[deleted] Mar 14 '22
[removed] — view removed comment