+ 1
Can you help me with a simple solution for my homework in python?
I have to generate X_NNNN_YY as “X” have to be the letter “P” “ _ “ have to be space “NNNN” have to be four numbers between (0,9) and the whole 4-digit number can be divided by 6 “_” must be space “YY” have to be two letters between this list [‘A’, ‘B’, ‘C’, ‘E’] JUST DID THIS BUT IT’S NOT EXACTLY WHAT I AM LOOKING FOR: alphabets=[‘A’, ‘B’, ‘C’, ‘E’] Numbers = [chr(i) for i in range(org(‘0’), ord(‘9’)+1)] Combinations=[one + two + three + four + five + six for one in Numbers for two in Numbers for three in Numbers for four in Numbers for five in alphabets for six in alphabets] print(Combinations) I’m new at python and I will be very grateful If you suggest some ideas 😇
2 Answers
+ 1
from itertools import combinations_with_replacement as cwr
lst = ['P '+str(n).zfill(4) for n in range(0,10000,6)]
cmb = [*cwr('ABCDE',2)]
cmb = [s+' '+a+b for s in lst for a,b in cmb]
print('\n'.join(cmb))
# reach timeout limit before print ends in code playground ^^
0
give it a try first, then ask for help.
https://www.sololearn.com/discuss/1316935/?ref=app