Ad
Code
Diff
  • _=([]!=["[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]"])
    f=lambda:[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]
    • function returnhundred() {
    • return 10 ** 2;
    • }
    • _=([]!=["[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]"])
    • f=lambda:[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]
Code
Diff
  • anagrams=lambda a,b:sorted(a)==sorted(b)
    • def anagrams(s1, s2):
    • return sorted(s1) == sorted(s2)
    • anagrams=lambda a,b:sorted(a)==sorted(b)
Code
Diff
  • f=lambda _:"EOvdedn"[_&1::2]
    • def even_or_odd(n):
    • return "Even" if n% 2 == 0 else "Odd"
    • f=lambda _:"EOvdedn"[_&1::2]
Code
Diff
  • f=lambda _:'EOvdedn'[_&1::2]
    • def even_or_odd(n):
    • return 'EOvdedn'[n & 1:: 2]
    • f=lambda _:'EOvdedn'[_&1::2]

Exam results:

90% = 9

80% = 8

70% = 7

Anything else is a "fail".

Code
Diff
  • def result(p):return "fail" if p<70 else p//10
    • def result(perc):
    • if perc >= 90:
    • return 9
    • elif perc >= 80:
    • return 8
    • elif perc >= 70:
    • return 7
    • else:
    • return "fail"
    • def result(p):return "fail" if p<70 else p//10
Code
Diff
  • even_or_odd = lambda n:'Even' if n%2==0 else 'Odd'
    • even_or_odd = lambda n:'Even' if n % 2 == 0 else 'Odd'
    • even_or_odd = lambda n:'Even' if n%2==0 else 'Odd'
Fundamentals
Algebra

Your task

Write a programm that takes number as an input, and returns "Even" if number is even; "Odd" if number is odd and "Zero" if number is zero.

Note: numbers can be negative. You will need to treat negativer numbers like positive: -2 is even; -1 or -5 is odd

Code
Diff
  • def even_or_odd(n):  
        if n == 0:        # If number is zero, return zero
            return "Zero"
        elif n % 2 == 0:  # If remainder of division by 2 is 0, number is even
            return "Even"
        else:             # Else the number is odd
            return "Odd"
    • def even_or_odd(n):
    • return 'Even' if n % 2 == 0 else 'Odd'
    • if n == 0: # If number is zero, return zero
    • return "Zero"
    • elif n % 2 == 0: # If remainder of division by 2 is 0, number is even
    • return "Even"
    • else: # Else the number is odd
    • return "Odd"