Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code
#1
I have an assignement to make app that list songs lenght in seconds and then in minutes, but i don't know how to do it.
Here is what i have but obviously it doesn't work:
n=int(Input('Enter number of songs: '))
sum=0
for i in range(1,n):
  t=int(Input('Enter song lenght: '))
  sum=sum+t
print(sum//60)
print(sum%60)
Any help is appreciated.
buran write Jan-21-2021, 10:05 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

And please, fix the indentation
Reply
#2
Is the below what you are after? Run the script and let me know!

This isn't hard stuff really, you should try and learn it because it's really useful, they wouldn't set you stuff like this if it wasn't important to your learning.

n = int(input('Enter number of songs: '))  # Quantity of Songs

songs = []

for i in range(1, n + 1):
    t = int(input('Enter song length: '))  # Song time in seconds
    print(f"Song {i} ->", "Minutes:", t // 60, "Seconds:", t % 60)
Reply
#3
Thank you, but with your code no matter how many songs I input it calculates after first input, it doesn't allow me to input lenght for number of songs I input.
Reply
#4
Maybe line 3 merits attention.
"from 1 to n" how many python loops are that?

Paul
Reply


Forum Jump:

User Panel Messages

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