14.Numbers to words /Functions
number_of_nums = int(input()) import math def lettersize(number): if int(number) < 0: minus_number = number number = abs(int(number)) number = str(number) elif int(number) >= 0: minus_number = number num_in_letters = "" hundreds = "" desetici = "" edinici = "" operator = "minus" if int(number) == 1 or 20 < int(number) < 100 and number[1] == "1" or (100 < int(number) <= 999 and (number[2] == "1" and number[1] != 1)): num_in_letters = "one" desetici = "one" elif int(number) == 2 or 20 < int(number) < 100 and number[1] == "2" or 100 < int(number) <= 999 and number[2] == "2" and number[1] != 1: num_in_letters = "two" desetici = "two" elif int(number) == 3 or 20 < int(number) < 100 and number[1] == "3" or 100 < int(number) <= 999 and number[2] == "3" and number[1] != 1: num_in_letters = "three" desetici = "three" elif int(number) == 4 or 20 < int(number) < 100 and number[1] == "4" or 100 < int(number) <= 999 and number[2] == "4" and number[1] != 1: num_in_letters = "four" desetici = "four" elif int(number) == 5 or 20 < int(number) < 100 and number[1] == "5" or 100 < int(number) <= 999 and number[2] == "5" and number[1] != 1: num_in_letters = "five" desetici = "five" elif int(number) == 6 or 20 < int(number) < 100 and number[1] == "6" or 100 < int(number) <= 999 and number[2] == "6" and number[1] != 1: num_in_letters = "six" desetici = "six" elif int(number) == 7 or 20 < int(number) < 100 and number[1] == "7" or 100 < int(number) <= 999 and number[2] == "7" and number[1] != 1: num_in_letters = "seven" desetici = "seven" elif int(number) == 8 or 20 < int(number) < 100 and number[1] == "8" or 100 < int(number) <= 999 and number[2] == "8" and number[1] != 1: num_in_letters = "eight" desetici = "eight" elif int(number) == 9 or 20 < int(number) < 100 and number[1] == "9" or 100 < int(number) <= 999 and number[2] == "9" and number[1] != 1: num_in_letters = "nine" desetici = "nine" if int(number) == 10 or 100 < int(number) < 999 and number[1] + number[2] == "10": num_in_letters = "ten" desetici = "ten" elif int(number) == 11 or 100 < int(number) < 999 and number[1] + number[2] == "11": num_in_letters = "eleven" desetici = "eleven" elif int(number) == 12 or 100 < int(number) < 999 and number[1] + number[2] == "12": num_in_letters = "twelve" desetici = "twelve" elif int(number) == 13 or 100 < int(number) < 999 and number[1] + number[2] == "13": num_in_letters = "thirteen" desetici = "thirteen" elif int(number) == 15 or 100 < int(number) < 999 and number[1] + number[2] == "15": num_in_letters = "fifteen" desetici = "fifteen" elif int(number) == 16 or 100 < int(number) < 999 and number[1] + number[2] == "16": num_in_letters = "sixteen" desetici = "sixteen" elif int(number) == 17 or 100 < int(number) < 999 and number[1] + number[2] == "17": num_in_letters = "seventeen" desetici = "seventeen" elif int(number) == 18 or 100 < int(number) < 999 and number[1] + number[2] == "18": num_in_letters = "eighteen" desetici = "eighteen" elif int(number) == 19 or 100 < int(number) < 999 and number[1] + number[2] == "19": num_in_letters = "nineteen" desetici = "nineteen" elif int(number) == 14 or 100 < int(number) < 999 and number[1] + number[2] == "14": num_in_letters = "fourteen" desetici = "fourteen" elif int(number) == 0: num_in_letters = "zero" if 19 < int(number) <= 999: # + desetici 20 30 40 50 if number[1] == "2" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "2": desetici = "twenty" elif number[1] == "3" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "3": desetici = "thirty" elif number[1] == "4" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "4": desetici = "fourty" elif number[1] == "5" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "5": desetici = "fifty" elif number[1] == "6" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "6": desetici = "sixty" elif number[1] == "7" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "7": desetici = "seventy" elif number[1] == "8" and 100 < int(number) < 999 or 0 < int(number) < 100 and number[0] == "8": desetici = "eighty" elif number[1] == "9" and 100 < int(number) <= 999 or 0 < int(number) < 100 and number[0] == "9": desetici = "ninety" if number[0] == "1" and 99 < int(number) < 999: hundreds = "one-hundred" elif number[0] == "2" and 99 < int(number) < 999: hundreds = "two-hundred" elif number[0] == "3" and 99 < int(number) < 999: hundreds = "three-hundred" elif number[0] == "4" and 99 < int(number) < 999: hundreds = "four-hundred" elif number[0] == "5" and 99 < int(number) < 999: hundreds = "five-hundred" elif number[0] == "6" and 99 < int(number) < 999: hundreds = "six-hundred" elif number[0] == "7" and 99 < int(number) < 999: hundreds = "seven-hundred" elif number[0] == "8" and 99 < int(number) < 999: hundreds = "eight-hundred" elif number[0] == "9" and 99 < int(number) <= 999: hundreds = "nine-hundred" if 1000 > int(minus_number) >= 0: if 0 <= int(minus_number) <= 19: print(num_in_letters) if 20 <= int(minus_number) <= 99: print(f"{desetici} {num_in_letters}") if 100 <= int(minus_number) <= 999 and number[1] != "1" and number[1] != "0": print(f"{hundreds} and {desetici } {num_in_letters}") if 100 <= int(minus_number) <= 999 and number[1] == "1": print(f"{hundreds} and {desetici}") if 100 <= int(minus_number) <= 999 and number[1] == "0": if number[2] != "0": print(f"{hundreds} and {desetici}") if number[2] == "0": print(f"{hundreds}") elif -1000 < int(minus_number) < 0: if 0 <= abs(int(minus_number)) <= 19: print(f"minus {num_in_letters}") if 20 <= abs(int(minus_number)) <= 99: print(f"minus {desetici} {num_in_letters}") if 100 <= abs(int(minus_number)) <= 999 and number[1] != "1" and number[1] != "0": print(f"minus {hundreds} and {desetici} {num_in_letters}") if 100 <= abs(int(minus_number)) <= 999 and number[1] == "1": print(f"minus {hundreds} and {desetici}") if 100 <= abs(int(minus_number)) <= 999 and number[1] == "0": if number[2] != "0": print(f"{hundreds} and {desetici}") if number[2] == "0": print(f"minus {hundreds}") elif int(minus_number) < -999: print("too small") elif int(minus_number) > 999: print("too large") for i in range(number_of_nums): lettersize(input())
Привет, с този код judge ми дава 70/100
единстената грешка, която ми "подсказва" е при ZeroTest 2
input 2, 15, 350
на мен си ми излиза отговора, само че според мен в джъдж теста е грешен
Дали някой може да погледне и да ми даде съвет какво ми се губи, Благодаря
УСЛОВИЕ
Задача: числа към думи Да се напише функция letterize(number), която прочита цяло число и го разпечатва с думи на английски език според условията по-долу: • Да се отпечатат с думи стотиците, десетиците и единиците (и евентуални минус) според правилата на английския език. • Ако числото е по-голямо от 999, трябва да се принтира "too large". • Ако числото е по-малко от -999, трябва да се принтира "too small". • Ако числото е отрицателно, трябва да се принтира "minus" преди него. • Ако числото не е съставено от три цифри, не трябва да се принтира.