How to write an Armstrong number program using python in 2 lines? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How to write an Armstrong number program using python in 2 lines?

7th Sep 2020, 1:41 PM
Karanam Deepika
Karanam Deepika - avatar
4 ответов
+ 1
a=input() print("Armstrong") if (sum(int(i)**3 for i in a))==int(a) else print("not an armstrong number") You can do something like this using ternary operator ,list comprehension for evaluating cube of each digit and then applying sum function ,ignore my previous answer ,that's wasn't evaluating as expected , lambda is an anonymous function which is created when the program runs and destroyed after that
7th Sep 2020, 2:28 PM
Abhay
Abhay - avatar
0
Ok tq
7th Sep 2020, 1:48 PM
Karanam Deepika
Karanam Deepika - avatar
0
May I know what is the use of lambda there....
7th Sep 2020, 2:20 PM
Karanam Deepika
Karanam Deepika - avatar
0
Ok tq
7th Sep 2020, 2:29 PM
Karanam Deepika
Karanam Deepika - avatar