본문 바로가기

isdigit6

0210. Is it a number? Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not. Valid examples, should return true: isDigit("3") isDigit(" 3 ") isDigit("-3.23") should return false: isDigit("3-4") isDigit(" 3 5") isDigit("3 5") isDigit("zero") Solution: def isDigit(string: str) -> bool: return string.strip().lstrip("-").replace(".", "").isd.. 2023. 2. 10.
0204. Filter the number Filter the number Oh, no! The number has been mixed up with the text. Your goal is to retrieve the number from the text, can you return the number back to its original state? Task Your task is to return a number from a string. Details You will be given a string of numbers and letters mixed up, you have to return all the numbers in that string in the order they occur. Solution: def filter_string(.. 2023. 2. 4.
1212. String cleaning Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. Examples (input -> output) '! !' -> '! !' '123456789' -> '' 'This looks5 grea8t!' -> 'This looks great!' Your har.. 2022. 12. 12.
0831. Correct the mistakes of the character recognition software Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer. When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes. Your task is correct the errors in the digitised text. You only have to handle the following mistakes: S is misinterpreted.. 2022. 8. 31.
Regex validate PIN code Description: ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return true, else return false. Examples (Input --> Output) Solution: 1. 인자가 숫자인지 확인한다. 2. 인자의 길이가 4 혹은 6이라면 pin을 반환한다. def validate_pin(pin): return pin.isdigit() and len(pin) in (4, 6) 2022. 4. 16.
문자열 다루기 기본 문제 설명 문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요. 예를 들어 s가 "a234"이면 False를 리턴하고 "1234"라면 True를 리턴하면 됩니다. 제한 사항 s는 길이 1 이상, 길이 8 이하인 문자열입니다. 해결 방법 1. s를 숫자로 바꾸어 본다. 2. 만약 숫자로 바꿀 수 없는 문자열이라면 ValueError를 통해 False 를 반환한다. 3. 숫자로 바꿀 수 있다면 해당 문자열의 길이를 구한다. 4. 길이가 4 혹은 6이라면 True를 반환하고 아니라면 False 를 반환한다. def solution(s): try: int(s) length = len(s) answer = length == 4 or length == 6 exc.. 2022. 1. 31.