-1

E.g task8(61) should return '1 hour, 1 minute' exactly

def task8(x):
    hours_total = x // 60
    minutes_total = x % 60
    
    if minutes_total == 1:
        minutes = "minute"
    else :
        minutes = "minutes"
    if hours_total == 1:
        hours = "hour,"
    else :
        hours = "hours,"
    print (hours_total,hours,minutes_total,minutes)
task8(61)
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
  • 1
    According to your post, your function is supposed to _return_, not _print_. – AKX Oct 13 '22 at 17:49
  • 1
    Use a string formatting method, such as `.format()`, `%` or f-string. – Barmar Oct 13 '22 at 17:49
  • 1
    see e.g. [what is the purpose of the return statement? how is it different from printing?](https://stackoverflow.com/questions/7129285/what-is-the-purpose-of-the-return-statement-how-is-it-different-from-printing) – Michael Delgado Oct 13 '22 at 17:52
  • You seem to have confused printing and returning so I've closed your question as a duplicate. You'll want to use string formatting as well, like Barmar said. If you need tips on that, you could check out the official tutorial: [Fancier Output Formatting](https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting) – wjandrea Oct 13 '22 at 18:20

2 Answers2

0

Why not making a string to print? Like this...

print(f"'{hours_total} {hours}, {minutes_total} {minutes}'")

This way you can even remove the ',' from the HOURS and MINUTES.

To understand more about f in a string.

Raphael Frei
  • 361
  • 1
  • 10
  • In your case, just return the string... **return (f"'{hours_total} {hours}, {minutes_total} {minutes}'")** – Raphael Frei Oct 13 '22 at 17:53
  • Thanks for the answer! If you have more to add to your answer, it's best to [edit](https://stackoverflow.com/posts/74059892/edit) it to improve/clarify rather than appending to your answer in comments. no need to highlight changes to your original post - just edit the text directly to make it as clear/informative as possible. see the guide to [answer]. – Michael Delgado Oct 13 '22 at 17:57
0

Simply just format the outputs. Convert integer to string and add "'" at start and end.

def task8(x): 
    hours_total = x // 60 
    minutes_total = x % 60
    if minutes_total == 1:
        minutes = " minute"
    else :
        minutes = " minutes"
    if hours_total == 1:
        hours = " hour,"
    else :
        hours = " hours,"
    print("'"+str(hours_total)+hours+str(minutes_total)+minutes+"'")

task8(61)
Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
Atri
  • 26
  • 3