Output File ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Output File ? (/thread-39934.html) Pages:
1
2
|
Output File ? - Kessie1971 - May-06-2023 Hello I try to find the top 10 albums in the chinook database 18 RE: Output File ? - deanhystad - May-06-2023 Don't print row[3], print something else. Is there a way to get a loop counter? RE: Output File ? - Kessie1971 - May-10-2023 i try to create a counter loop Clearwater Revival tracks 18 RE: Output File ? - buran - May-10-2023 # Print the results for n, (albumid, album, artist, tracks) in enumerate(result, start=1): print(f'{n}. {album} by {artist} - tracks: {tracks}')Note, code not tested RE: Output File ? - Kessie1971 - May-10-2023 I have found the solution result = cur.fetchall() count = 0 # Print the results for row in result: count += 1 print(count, row[1], 'by', row[2], '-', row[3]) RE: Output File ? - Kessie1971 - May-10-2023 Last question eedence Clearwater Revival 18[/output] RE: Output File ? - deanhystad - May-10-2023 Formatting the print statement. While you are looking up how to format print commands in python you should also read about the enumerate command. RE: Output File ? - Kessie1971 - May-10-2023 Thanks i try the Formatting the print statement but can you please give a tip how i can do it RE: Output File ? - deanhystad - May-10-2023 (May-10-2023, 02:02 PM)Kessie1971 Wrote: Thanks i try the Formatting the print statement but can you please give a tip how i can do itGoogle "python print formatting"? RE: Output File ? - Larz60+ - May-11-2023 couldn't you just replace rows 26 and 27 from post 1 with: for n, row in enumerate(result): print(f"row {n}: {row[n]}") |