![]() It goes a little bit wonky in the teens ( "12nd"), but like I said, it isn't a super straightforward problem, and I don't want to sidetrack the review. This can be optimized using a dictionary acting as a case, but I think it's fine as-is besides some minor duplication: def format_number(n: int) -> str: In their place, I'm going to use a simple function. For the sake of simplicity, I'm going to ignore the numeric words, because producing those is non-trivial and a whole project on its own unless you use an existing library. Loops would be the perfect tool here to reduce duplication although getting it exactly as you have will be difficult due to you currently spelling out numbers ("first", "second", "third".). Print("The calculator handles 5 numbers maximum!") V = float(input("Enter the fifth number: ")) W = float(input("Enter the forth number: ")) Z = float(input("Enter the third number: ")) 10 Answers Sorted by: 5 You can use some datetime trickery to get a guaranteed correct result: starthour 3 startminute 48 length 172 start datetime.datetime (100, 1, 1, starthour, startminute, 0) end start datetime.timedelta (minuteslength) result str (end. Y = float(input("Enter the second number: "))įunc = int(input('''What do you want to do? X = float(input("Enter the first number: ")) ![]() # v = float(input("Enter the fifth number: ")) # w = float(input("Enter the forth number: ")) # z = float(input("Enter the third number: ")) Ill assume you have a text editor, have python installed, and know python (ev. # y = float(input("Enter the second number: ")) In this tutorial you will learn how to make a python console-based calculator. # x = float(input("Enter the first number: ")) Which one is best, very much depends on the context. Nums = int(input("How many numbers you want to calculate?\n")) However, in the case of writing a simple calculator program, there are many different ways to do it. ![]() I am new to python, I made a calculator but I need to make it calculating unlimited numbers and to shorten the code more, how can I improve it?
0 Comments
Leave a Reply. |