Python Forum
create a 20 digit string, and cast to a list then add all the digits as integers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create a 20 digit string, and cast to a list then add all the digits as integers
#1
my question here
create a 20 digit string, and cast to a list
then add all the digits as integers
print the equation and answer
Hint: use cast to sum the digits, and .join() to create the equation (1+2+3+...)
new_digit="20,10,70,30,20"
print(list(new_digit))
sum_of_digits=0
new_digit=int(new_digit)
for digits in new_digit:
   #digits=int(digits)
   sum_of_digits+=digits
print("+".join(new_digit))
But I am getting ValueError: invalid literal for int() with base 10: '20,10,70,30,20'
Reply


Messages In This Thread
create a 20 digit string, and cast to a list then add all the digits as integers - by nikhilkumar - Jul-18-2017, 06:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  list digit into number Voldyy 2 1,596 Jul-10-2022, 06:13 PM
Last Post: deanhystad
Question How can I create a linked list that contains each folder with its files? noahverner1995 8 2,516 Dec-25-2021, 10:46 PM
Last Post: noahverner1995
  TypeError: string indices must be integers, not str hanieh 4 98,500 Jan-04-2021, 05:13 AM
Last Post: delonbest
  Frequency in first digit from csv file, NO IMPORT bryan0901 6 2,910 May-28-2020, 09:50 AM
Last Post: bryan0901
  Sorting digits in a mixed string snorri 1 1,685 Apr-22-2020, 11:04 AM
Last Post: buran
  Convert a list of integers to strings? Cornelis 3 2,315 Nov-15-2019, 12:13 PM
Last Post: perfringo
  TypeError: string indices must be integers thecoziest 3 6,299 Sep-29-2019, 05:34 PM
Last Post: ichabod801
  Four-digit number text translation. soz 3 2,728 May-13-2019, 03:02 PM
Last Post: buran
  create three digit numbers Krszt 4 4,561 Dec-09-2018, 03:12 PM
Last Post: ThePhi
  Sum of digit in a string MEH012 1 9,539 Apr-20-2018, 02:13 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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