Portál AbcLinuxu, 10. května 2025 08:20
x = ((z > 0) and (6 * z- 183.0) or 3.0) - _a3Nechapu co v tom vyrazu dela najednou logicka spojka a ">". Jak mohu prosim tento radek ekvivalntne prepsat do C?
x = ((z > 0) ? (6 * z- 183.0) : 3.0) - _a3
x if c else y
, je to zápis pomocí zkráceného vyhodnocování logických operátorů (a zneužití jejich chování pro nelogické typy).
Kód by šel opravit zahrnutím případu, kdy nastane 6*z = 183, do podmínky:
x = ((z > 0 && z != 30.5) ? (6*z - 183.0) : 3.0) - _a3
if (z > 0) then x = 6 * z - 183.0;
else x = 3.0;
x -= _a3;
Marek
if (z>0) z0 = 6 * z- 183.0; else z0 = 3.0; if (!z0) z0 = 3.0; // pro z = 30.5, netusim jestli to byl umysl x = z0 - _a3;
$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! >>>Zajímalo by mě co autor původního programu zamýšlel
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.