0

how do i subtract from numbers that are greater than 9 but print the whole list including the subtracted values

subtract nine from all values that are greater than 9: if x > 9: x - 9 print the subtracted values including the rest of the list

20th Jul 2024, 3:59 PM
Tantoluwa Dairo
Tantoluwa Dairo - avatar
3 odpowiedzi
+ 4
Tantoluwa Dairo There are multiple ways to do this Smallest one is by list comprehension [x if (x < 9) else (x - 9) for x in list] I think you are solving credit card validater Hope this helps you ✨
21st Jul 2024, 2:59 AM
Hacker Badshah
Hacker Badshah - avatar
+ 4
Tantoluwa Dairo , the expression `x - 9` will be executed but not saved in the variable `x`. the most simple way to achieve this is: x = x - 1
20th Jul 2024, 5:58 PM
Lothar
Lothar - avatar
+ 2
Read the lessons before this question. They explain it.
20th Jul 2024, 4:16 PM
Wilbur Jaywright
Wilbur Jaywright - avatar