#๐ round
73 messages ยท Page 1 of 1 (latest)
@mighty rune
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
This is called padding, not rounding
oh
!e ```py
print(f"{0:02d}")
second. ill try it
@kindred pewter :white_check_mark: Your 3.12 eval job has completed with return code 0.
00
using :2d will print " 0"
.02f actually gives you 2 digits of percision after the decimal point
!d format
format(value, format_spec='')```
Convert a *value* to a โformattedโ representation, as controlled by *format\_spec*. The interpretation of *format\_spec* will depend on the type of the *value* argument; however, there is a standard formatting syntax that is used by most built-in types: [Format Specification Mini-Language](https://docs.python.org/3/library/string.html#formatspec).
The default *format\_spec* is an empty string which usually gives the same effect as calling [`str(value)`](https://docs.python.org/3/library/stdtypes.html#str).
A call to `format(value, format_spec)` is translated to `type(value).__format__(value, format_spec)` which bypasses the instance dictionary when searching for the valueโs [`__format__()`](https://docs.python.org/3/reference/datamodel.html#object.__format__) method. A [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError) exception is raised if the method search reaches [`object`](https://docs.python.org/3/library/functions.html#object) and the *format\_spec* is non-empty, or if either the *format\_spec* or the return value are not strings.
!d str.format
str.format(*args, **kwargs)```
Perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces `{}`. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of the string where each replacement field is replaced with the string value of the corresponding argument.
```py
>>> "The sum of 1 + 2 is {0}".format(1+2)
'The sum of 1 + 2 is 3'
``` See [Format String Syntax](https://docs.python.org/3/library/string.html#formatstrings) for a description of the various formatting options that can be specified in format strings.
thanks!
oh god that is long
sooo, a second issue popped up
print(f'{abs(remaining_time_early):02d} minutes before the start')```
Maybe you want this? {x if x := abs(remaining_time_early) else "00"}
immm not sure
i started programming this week
i think i can just
have an outcome if its 00
abs(remaining_time_early) or "00"
else
that will use 00 if the time is 0
oh
but wouldnt that make it
ah i need a second to explain it but i think it wouldnt work?
hmm
i need an if for <10 since they all need a 0 behind
i think
and that would fix it
like same print just a 0 behind it
yeahhhh i used some other method @kindred pewter
if remaining_time_early<10:
print("On time")
print(f'{abs(remaining_time_early)} minutes before the start')
else:
print("On time")
print(f'{abs(remaining_time_early):02d} minutes before the start')```
and it worked!
ty for the help
i just shouldnt :02d when i dont want a zero behind it
and in every other case i do :02d
these do the same thing.
the only way remainint_time_early will be > 2 chars is if it's > 100
well i had issues with minutes
oh
sooo remaining_time_early and remaining_time_late
abs them before if
alright, thanks, noted
!e ```py
for remaining_time_early in range(-11, 12):
print(f"On time {abs(remaining_time_early)} minutes before the start")
@kindred pewter :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | On time
002 | 11 minutes before the start
003 | On time
004 | 10 minutes before the start
005 | On time
006 | 9 minutes before the start
007 | On time
008 | 8 minutes before the start
009 | On time
010 | 7 minutes before the start
011 | On time
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/6SSLZNFQWJZJAKDUYULLNB4VM4
Was that what you wanted?
well overall the exercise is :
input is the hours + mins when a test started
and then input the hours + mins when a person arrived
says if u are late, on time or early
and by how much
So if it's over an hour, include the minutes with 2 decimals
yeah
i meann
2 decimals = everything besides only minutes < 10
since hours arent 03:18, they are 3:18 for example
You should make a function that converts minutes to a duration string
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.