AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Software Zprint9/1/2023 ![]() If you pass an empty sequence or provide only even numbers, you will get a ValueError: > find_largest_odd(0) return max(filter(lambda x: x & 1, args)) return max(arg for arg in args if arg & 1) Return max(filter(lambda x: x & 1, args)) Return max(arg for arg in args if arg & 1) Using builtins like this is safer/more reliable because it is simpler to compose them, the code is well-tested, and the code executes mostly in C (rather than multiple byte code instructions). Use either generator or filter to find only the odd numbers. If x > y and x > z: #x is the biggest oddĮlif y > z and y > x: #y is the biggest oddĮlif z > x and z > y: #z is the biggest oddĮlse: #y,z are even and x is the biggest oddĪvoid using if-stmts to find maximum. With thkang post, I now have: # This program exmamines variables x, y, and z Print 'z is the largest odd among x, y, and z' Print 'y is the largest odd among x, y, and z' Print 'x is the largest odd among x, y, and z' ![]() # and prints the largest odd number among them Is this at least a decent start? # This program exmamines variables x, y, and z ![]() So the program will ask what x, y, and z is and then say "x,y,z is the largest odd" or the numbers are all even. ![]() How do I give the user an option to pick the values for x, y, and z? I am trying to make a simple program in Python that calculates the largest odd number out of the values x, y, z. ![]()
0 Comments
Read More
Leave a Reply. |