+ 2

I need to be able to make a function that return how many fives, twos and ones in pence (p). Can anyone help?

I have a quiz on Udacity I need to pass, and I need to be better with Algorithmic scripting. And I haven't touched this class in a few weeks.

3rd May 2018, 5:47 PM
Michele Rene Machado
Michele Rene Machado - avatar
2 Respuestas
+ 1
I will try this, thank you.
4th May 2018, 12:57 PM
Michele Rene Machado
Michele Rene Machado - avatar
0
try for loops: def for1_2_5(x): x1 = [] x2 = [] x5 = [] for B in x: if str(x[B]) == "5": x5.append("5") elif str(x[B]) == "2": x2.append("2") elif str(x[B]) == "1": x1.append("1") x1_2_5 = ("amount of 1 = " + str(len(x1)) + "\namount of 2 = " str(len(x2)) + "\namount of 5 = " + str(len(x5))) return x1_2_5 print(for1_2_5([1, 1, 1, 1, 2, 2, 5, 5, 5, 10, 20, 100])) >>>>> amount of 1 = 4 amount of 2 = 2 amount of 5 = 3 >>>>>
4th May 2018, 7:15 AM
Seb TheS
Seb TheS - avatar