#🔒 How does one convert a string input in print test into a variable in body?
23 messages · Page 1 of 1 (latest)
@shrewd bobcat
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.
are you allowed to use the string split function?
well since your input is a string and you need to somehow convert each part to a number, i'm assuming you can use int()
in that case you can start from the beginning of the string, read in digits until you encounter a : character, convert that string into an integer, and repeat this 3 times for hours, minutes, and seconds
nvm. maybe its a week 4 thing. basically this is an assignment which is a series of questions for first half of this semester. but they test you things from week 1 to 5. this is just the first question. guess they just want me to manually do it
but ill try ur advice
thanks
hm. the strings always have the same format.
that should make things easier.
the task says, the input always has the format 'hh:dd:mm'.
try looking into the datetime module. it offers a lot of functionality for handling time & dates.
I am not allowed to use import or anything just the content ive learned so far.
well for simple logic - you could approach this in 2 ways.
- make use of string builtins, like
.split(),.isdigit()or.join() - iterate over the string - connecting/handling characters when a condition is satisfied (like when reaching a colon
:)
@neat stirrup
i'm not the op of this thread lol
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.