Python Forum

Full Version: Need help with code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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)
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.
Maybe line 3 merits attention.
"from 1 to n" how many python loops are that?

Paul