New to python NEED SIMPLE MATH CODE plz

Joined
Jan 11, 2023
Messages
2
Reaction score
0
an someone help me with a simple *for yous* lines of code..

I need to input a number of no more then 10 or 11 digits. say 01234567890

then need too add them #+#+#+#+#+#+#+#+#+# Then ##+##+##+##+##+## THen ###+###+###+### up too ############

then multiply the results by 8. like say 24 = 8, 23=7 22=6. I know its probly stupid easy but im still learning. and show the different multi's for eash group. i dunno if that explain enough but if you could make me a something too which you may think im needing that would greatful :)

so say the number was 392130 i want stuff like 39 would be 7, 21 would be 5 . minus from closest number from multi of 8.. IM not good at explaining any help with the codes too do it would be helpful.
Jesse.
 
Joined
Jan 8, 2023
Messages
27
Reaction score
2
Python:
number = "392130"


digit_sum = sum(int(digit) for digit in number)
print("Digit sum:", digit_sum)


group_size = 2
digit_groups = [int(number[i:i+group_size]) for i in range(0, len(number), group_size)]
group_sum = sum(group for group in digit_groups)
print("Group sum (size 2):", group_sum)

group_size = 3
digit_groups = [int(number[i:i+group_size]) for i in range(0, len(number), group_size)]
group_sum = sum(group for group in digit_groups)
print("Group sum (size 3):", group_sum)


group_size = 4
digit_groups = [int(number[i:i+group_size]) for i in range(0, len(number), group_size)]
group_sum = sum(group for group in digit_groups)
print("Group sum (size 4):", group_sum)


nums = [8,7,6,5,4,3,2,1]
for num in digit_groups:
  closest = min(nums, key=lambda x: abs(x-num))
  print(num," Closest multiple of 8 is :",closest)

like this?
 
Joined
Jan 11, 2023
Messages
2
Reaction score
0
i think i messed up i think i want the common denominator of the sums so like 12345 i want 1+2+3+4+5 = 15 so think of a clock that can't go past 8 .. 15 =7 where as 16=8 understand what im trying too do? so say 12+34+5 .. so 12 is 4(because 16 - 12 ), 34 is 2,cuz and 5 is 5. so it would be 11 11.. but on a clock only goes up too 8 would be 3... understand? ughmm im dumb. but i really need to figure this out.
i want 3 different outcomes, 1 for the single #+#+# ect, and ##+##+## and ###+###+###+ the outcome has to be somewhere between 1-8..

and i thank you SO MUCH FOR THE CODE AREADY! its what i want just needs that tweek :)

Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top