0
Can this be done in less lines
def test_func(x,y,z): total = int(x+y+z) if total == int(22): return "Correct: " + str(total) else: if total < int(22): incorrect = int(22) - total print("Answer off by the integer of " + str(incorrect)) elif total > int(22): incorrect2 = total - int(22) print("Answer off by the integer of " + str(incorrect2))
10 Respostas
+ 5
2 lines
total=lambda x,y,z:'correct'+ str(x+y+z) if x+y+z==22 else "Answer off by the integer "+str(abs(22-(x+y+z)))
print(total(10,10,7))
+ 3
Diego 1line
print(((lambda x,y,z:'correct'+ str(x+y+z) if x+y+z==22 else "Answer off by the integer "+str(abs(22-(x+y+z)))))(10,10,5))
+ 2
def test_func(x,y,z):
total = int(x+y+z)
if total == int(22):
print("Correct: " + str(total))
elif total < 22:
print("Answer off by the integer of " + str(22 - total))
else:
print("Answer off by the integer of " + str(total - 22))
+ 2
Thank you Mr. Böhler for your time. i will study this.
+ 2
total=lambda x,y,z:'correct'+ str(x+y+z) if x+y+z==22 else "Answer off by the integer "+str(abs(22-(x+y+z)))
print(f'1:{total(10,10,7)}\n2:{total(12,8,2)}\n3:{total(5,15,5)}')
+ 1
Three line version. You can even make it a oneliner.
def test_func(x,y,z):
total = int(x+y+z)
return "Correct: "+str(total) if total==22 else "Answer off by the integer "+str(abs(22-total))
+ 1
abderrahim sallami
f=lambda t:t==22and"Correct: 22"or f"Answer off by integer {abs(22-t)}"
[print(f(sum(i)))for i in([1,1,20],[42,4,2],[10,10,5])]
0
Diego this gives no output for me
0
Paras finn
print(test_func(1,1,20))
print(test_func(42,4,2))
0
abderrahim sallami Your code is a oneliner. Only the function itself is counted.
PS: You can make it shorter.