#🔒 How does one convert a string input in print test into a variable in body?

23 messages · Page 1 of 1 (latest)

shrewd bobcat
#

I am trying to convert a string "hour:time:seconds" into total seconds. obviously math is straigthforward. I am not allowed to use import or anything just the content ive learned so far.

ruby gustBOT
#

@shrewd bobcat

Python help channel opened

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.

neat stirrup
shrewd bobcat
#

no

#

just not, in, and basic stuff thats taught in week 1 to 3

#

or and

neat stirrup
# shrewd bobcat no

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

shrewd bobcat
#

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

frail glacier
#

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'.

gritty veldt
#

try looking into the datetime module. it offers a lot of functionality for handling time & dates.

neat stirrup
#

I am not allowed to use import or anything just the content ive learned so far.

gritty veldt
#

well for simple logic - you could approach this in 2 ways.

  1. make use of string builtins, like .split(), .isdigit() or .join()
  2. iterate over the string - connecting/handling characters when a condition is satisfied (like when reaching a colon :)
#

@neat stirrup

neat stirrup
ruby gustBOT
#
Python help channel closed

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.