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

3 Answers

+ 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 âš

+ 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

+ 2

Read the lessons before this question. They explain it.