+ 2

python

# its did not show else statement "You didn\'t pass anything" its showing op [] def ex1(num,*args): return [i**num if args else 'You didn\'t pass anything' for i in args] nu=[1,2,3] print(ex1(4))

16th Sep 2022, 6:38 AM
Amol Bhandekar
Amol Bhandekar - avatar
7 odpowiedzi
+ 7
Your syntax is not correct. See if this helps def ex1(num,*args): return [i**num for i in args] if args else 'You didn\'t pass anything' nu=[1,2,3] print(ex1(4)) print() print(ex1(4,*nu))
16th Sep 2022, 8:26 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
Thanks Rik Wittkopp :) Its working ....
16th Sep 2022, 9:27 AM
Amol Bhandekar
Amol Bhandekar - avatar
+ 3
If that's the way you've written the code it won't work. Python is all about the format you write and pay attention to indentation. E.g. if statement print("statement is true") else print("other statement")
16th Sep 2022, 6:53 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Thanks @Ausgrindtube :) But I have used list comprehension... I want to do in one line statement..
16th Sep 2022, 7:09 AM
Amol Bhandekar
Amol Bhandekar - avatar
+ 2
Amol Bhandekar I have just proved that I'm a beginner 🤣 Sorry
16th Sep 2022, 9:04 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Ausgrindtube For a beginner, you have excellent knowledge. Learners like us stick together
16th Sep 2022, 9:25 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Fill in the blanks to iterate over the string "str" and output each character. x str print( )
17th Sep 2022, 1:56 PM
Aryan joshi