Python Forum
Convert a list of integers to strings?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert a list of integers to strings?
#1
Is there any way to convert a list of integers to a list of strings?
Below is a program that asks the user how much he paid for the food and the program calculates the returned change.

I want the output to be for example [500 note, 200 note, 10 coin, 1 coin]. The notes and coins are in SWE if it seems unfamiliar ;)

 
price = int(input('What is the price for the food? '))
paid = int(input('How much did you pay for it? '))
change = paid - price
cash = [500, 200, 100, 50, 20, 10, 5, 2, 1]
changeReturned = []
for i in cash:
    while change >= i:
        changeReturned.append(i)
        change = change - i
print(changeReturned)
Reply


Messages In This Thread
Convert a list of integers to strings? - by Cornelis - Nov-14-2019, 07:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Removing all strings in a list that are of x length Bruizeh 5 6,631 Aug-27-2021, 03:11 AM
Last Post: naughtyCat
  How to convert every even number in a list to odd? Bruizeh 4 5,591 Aug-27-2021, 03:04 AM
Last Post: naughtyCat
  list of strings to list of float undoredo 3 4,153 Feb-19-2020, 08:51 AM
Last Post: undoredo
  how to convert list into string Shevach 3 3,409 May-14-2019, 09:51 AM
Last Post: perfringo
  please Help. TypeError: list indices must be integers, not str skamaaa01 1 4,955 Feb-04-2018, 12:33 PM
Last Post: Gribouillis
  List of Strings Problem jge047 3 4,451 Dec-19-2017, 04:06 AM
Last Post: dwiga
  Strings inside other strings - substrings OmarSinno 2 4,513 Oct-06-2017, 09:58 AM
Last Post: gruntfutuk
  create a 20 digit string, and cast to a list then add all the digits as integers nikhilkumar 2 7,311 Jul-19-2017, 04:53 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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