May-06-2023, 03:04 PM
(This post was last modified: May-11-2023, 12:43 PM by Kessie1971.)
Hello I try to find the top 10 albums in the chinook database 18
Output File ?
|
May-06-2023, 03:04 PM
(This post was last modified: May-11-2023, 12:43 PM by Kessie1971.)
Hello I try to find the top 10 albums in the chinook database 18
May-06-2023, 08:12 PM
Don't print row[3], print something else. Is there a way to get a loop counter?
May-10-2023, 09:25 AM
(This post was last modified: May-11-2023, 12:41 PM by Kessie1971.)
i try to create a counter loop
Clearwater Revival tracks 18 # 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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
May-10-2023, 11:33 AM
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])
May-10-2023, 12:51 PM
(This post was last modified: May-11-2023, 12:41 PM by Kessie1971.)
Last question eedence Clearwater Revival 18[/output]
May-10-2023, 12:54 PM
(This post was last modified: May-10-2023, 02:03 PM by deanhystad.)
Formatting the print statement. While you are looking up how to format print commands in python you should also read about the enumerate command.
May-10-2023, 02:02 PM
Thanks i try the Formatting the print statement but can you please give a tip how i can do it
May-10-2023, 02:05 PM
May-11-2023, 02:30 AM
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]}") |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
reading text file and writing to an output file precedded by line numbers | kannan | 7 | 13,658 |
Dec-11-2018, 02:19 PM Last Post: ichabod801 |
|
Multiple XML file covert to CSV output file | krish143 | 1 | 4,070 |
Jul-27-2018, 06:55 PM Last Post: ichabod801 |
|
How to get output in a file? | BananaRekt | 3 | 4,000 |
May-06-2018, 06:04 PM Last Post: buran |