Making simple calculation program in Python

while True: 
    # -- Get user input and make list --
    data = input("Asset(JPY),Amount of Trade,Loss-cut percentage/Exit(E)>>")
    if data == "E" or data == "e":
    list = data.split(",")

    # -- Check validity of the user input --
    if len(list) != 3:
        print("Arguments error. Please check the total number of arguments.")
    if all(float(s) for s in list) == False:
        print("Arguments error. Please input only numbers.")
    list = [float(x) for x in list]
    # -- Compute a result -- 
    #list[0] is totalAsset
    #list[1] is amount of trading
    #list[2] is loss cut percentage  
    losscut_jpy = list[0]*(list[2]*0.01)
    losscut_pips = float(losscut_jpy / list[1])*100

    print("Loss-cut is {0}pips or less.".format(losscut_pips))

I made very little Python program. This code outputs losscut point from an asset, the amount of trade, a percentage of loss-cut.

I thought three things, that is...

  • How to make a list from a data separated with "," a comma-separated data?
  • How to get length(size) of a list?
  • How to check if all conditions are True?
  • How to convert all item's type of a list?

How to make a list from a comma-separated data

string.split() is used to separate with any character. string.split() returns a list.

How to get length(size) of a list?

You can use len() for getting a length of a list. The format is len(list)

How to check if all conditions are True?

all() returns True if all elements of am iterator is True. In this case,
I use float() as an argument. float() will return if the function fail the process.
So I write

if all(float(s) for s in list) == False:

"all(float(s) for s in list" returns True if all the items of the list is a number.

How to convert all item's type of a list?

"List Comprehensions" can be used for this purpose.

[statement for x in list-object]

Try Python programming with Thonny!

Thonny is a simple Python IDE(Integrated Development Environment).


You can start coding immediately with Python after executing aan installer. 


Thonny's UI is simply composed of two text boxes space roughly. You can edit python file(.py) in the top text box. Also, you can input codes and execute codes directly in the bottom text box (shell).


immediately : 直ちに、すぐに


You can get more information here :  Thonny, Python IDE for beginners



「とりあえずここまで」The first time of the Python - Keywords「Pythonと英語の勉強」

Python reserved these words for keywords.


Python has 33 keywords.

All the keywords except True, False and None must be written in lowercase.

(S except A,B,......,C) 動詞 + ......


Below is all the keywords.


  • True, Flase : Truth values in Python. They are used for result of operations.
  • class : class is used to define a class.
  • is: This is used for testing object identify. is test if the two variables refere to a same object.
  • return : This keywords is used inside a function to return a value. If you don't return any value, None is returned automatically.
  • None : This is a constant that represents an absence of a value or null. You have to notice(You should be aware) that None is not equal to False, 0, or any empty list etc. Also(Also,) void functions will automatically return a None object automatically.

Should be aware : ~に注意してね

Must and Have to have strong meaning, You can use "Should" instead of Must and Have to in this situation.

  • continue, break : These keywords are used with looping. break ends looping. continue skip over current iteration of the loop.
  • for : for is used for looping. This statement is similar to For Each statement of VB.net. The format is shown below :

    for item in sequence:


    Each elemtent of sequence is stored in item. Also, sequence needs to be of an

    iterable type. (need to be of A = Aである必要がある)

    For example:

   str = "Nora Tyng"

   for c in str:


   The output is shown below:










  • lambda : You can create a function without name. The function doesn't contain a return keyword, but the function contains an expression which is evaluated and returned.

    The format is shown below :

    lambda args: expression

    You can specify more than one argment.

  • except, raise, try,finally : These are used with exceptions. try...except blocks are used to catch exceptions. raise keyword is used to raise an exception explicitly.

    finally is used with try...except block. finally block is executed absolutely. So you 

    can code for cleaning up.

  • def : def is used to define a function. The format is shown below:

    def name(parameters):

    name is name of the function, parameters is used in the function.

  • nonlocal : This keyword is very similar to global keyword. But nonlocal functions inside nested functions.
  • while : while is used for looping. while loop continue until a condition for the loop is  evaluated to False. Also 0 is equal to False.
  • and, or, not : They are the logical operators. and returns True if both operands are true. or returns True if at least one operand is True. not returns True if a operand is False. if the operands is True, not returns False.
  • del : You can delete a reference to an object. Also you can delete items from a list or a dictionary. It's useful!
  • global : This is used to  declare that a variable inside a function is global. If you want to modifiy the value of the global variable inside the function, you must use this keyword. But if you just read the value, you don't need this keyword.
  • with : with statement executes initializing method and finalizing method automatically. So if you use this statement, an object is needed to implement __enter__ and __exit__ methods. You can code simply with with statement I think.
  • as : as is used to give a another name to a module.
  • if, elif, else : You can use these keywords for conditional branching in if...else statement. 

    if expression :


    elif expression :


    else :


   expression is a condition. elif is used for multi conditional branching. Also, when

   any conditions are false, statements are executed in else block if you have the


  • yield : Think about a situation that when you create a function that reads a data neede big memory. You  can use return keyword to return the data. But a variable for the result is needed big size. You can choose yield keyword instead of return keyword. In a nutshell yield keyword is subdived return.
  • assert : assert is used for checking an internal state. You code a condition after this keyword. If the condition is true, nothing happens. But if the conditions are false, AssertionError is outputed. Also, you can specify an error message after the condition.
  • import,from : This is used to import modules. Also you can use from...import to import a specific attribute or function.
  • pass : When this statement is executed, nothing happens. So you can use it as a placeholder.
  • in : You can test if a sequence contains a value.





では今日は数日分get togetherして(にしては少ないかな?)いきます。


cold blooded



unfriendly to ~



 Keep up the good work!



Same here



rare for~


「rare for jp person」なら「日本人ではめずらしい」


check back on ~


I'll check back on your page to see how it goes!って言われたので、この場合は「また見に来るよ!」みたいな感じですね。


Always happy to help!

「お役に立ててうれしいです」 You're welcomeとかIt's my pleasure的な感じかな。


cold bloodedは冷え性って意味もあるみたいなのですが、そのつもりで使ったら相手が「血も涙もない」って言う意味で受け取っちゃってかみ合わなくなったので、冷え性はまた別の表現を使うのが吉、かも。


今日の虫食い「get together」は「集める、まとめる」でした。それでは!