Python Forum
First Day using Python. NEED Simple Math CODE HELP!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First Day using Python. NEED Simple Math CODE HELP!
#1
can 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 :)

Jesse.
Yoriz write Jan-11-2023, 08:48 PM:
Moved to homework:
https://python-forum.io/misc.php?action=help&hid=52 Wrote:Homework and No Effort Questions
This forum is focused on education. It exists to help people learn Python. We don’t exist to solve others' problems.
Reply
#2
What have you tried?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Please show your code and ask a specific question. Nobody is going to "make you something". This forum is for answering questions, not doing your homework.

Some parts of your description are confusing. I assume #+#+#+#+#+#+#+#+#+# should be 0+1+2+3+4+5+6+7+8+9+0 given your example input of 01234567890, but I have no idea what you mean by ##+##+##+##+##+##? Should that be 01+23+45+67+89+0? What about ###+###+###+###? Is that 012+345+678+90?

So you sum all these paired sums up and multiply by 8. That is clear, but I have no idea what you mean by this: like say 24 = 8, 23=7 22=6
Reply
#4
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)

(Jan-11-2023, 08:37 PM)menator01 Wrote: What have you tried?

im not asking for work but yea 12+34+56+78 123+456+789 but can't so past 8.. so like 12 would be 4 , turst me im very VERY new to this.. im trying to learn just for this simple but needful task...


so i can input a number up too 11 digits and willl count 1+2+3+4+5+6 12+34+56 and 123+456 .. so say 12+34+56 = 6 thats what i need.. UGH... sorry i know you code guys can be Fussy with instructions from a guy like me.. :(
Reply
#5
Indeed, you will find that computers need very specific instructions, and so do we if we are trying to help. So, to clarify:
In your first set of numbers (392130) the first part would be 3+9+2+1+3+0 = 18, correct? I don't understand where 1+2=4, so me that is 3.
Next calculation 39+21+30 = 90, correct? If not, how are you arriving at your "sums"?
Third sum similar, but what happens when you are grouping the digits 4 at a time? With six digist, how are you handing that there will not be 4 digits left for the second group - or more importantly, what do your instructions say you need to do?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my simple code wont work! help! simon12323121 2 2,028 Sep-05-2021, 09:06 AM
Last Post: naughtyCat
  reverse math in python, who will find the correct answer? Kakha 11 4,415 Jan-11-2021, 11:59 AM
Last Post: Gribouillis
  Math problem in Python - pyqt5 rwahdan 6 5,717 Jun-18-2019, 08:11 PM
Last Post: Gribouillis
  Can anyone please help with very simple code bee 6 4,887 Sep-29-2017, 02:26 PM
Last Post: ichabod801
  i need help with this simple code josephb401 12 12,765 Oct-18-2016, 10:25 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020