From 0b9adfd8f3e6bf14554fe6bf2b69b345d262ccbb Mon Sep 17 00:00:00 2001 From: Youngjin Han Date: Mon, 1 Jun 2020 21:17:04 +0900 Subject: [PATCH] Learning Circle : python #7 : Initial Commit --- youngjin.han/learning-node02-2020.org | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/youngjin.han/learning-node02-2020.org b/youngjin.han/learning-node02-2020.org index 2d97fd6..38bce79 100644 --- a/youngjin.han/learning-node02-2020.org +++ b/youngjin.han/learning-node02-2020.org @@ -1,3 +1,42 @@ +* 2020-06-01 +*** Python applying learnings from 1..6 +**** Lecture notes + - Previous topics covered: + - Printing + - Formatting + - Variables + - Escape Sequences + - Inputting text + - Reading arguments / using argv + - Reading files + - Defining methods + - Boolean logic + - Branching using if/else/elif + - Loops: for/while + - Today we write a calculator that saves results in a file in python + - How it works in general + You read the input until you read a line that only contains a + "q". Every input line consists of numbers separated by a + space. For instance "4 5 9". You will need to .split() the + input. + - Steps + - Create a python script named "calc.py" + - It takes 1 command line argument (argv), which is the filename + - We will store the calculations *and* results in this file + - Create a method named "input_and_calculate_one_line" + - It does not have any arguments + - It reads one line via *input* + - It splits the input (let's say "4 5 9" => [ "4", "5", "9") ]) + - It calculates the result (f.i. 4+5+9 = 18) and stores it in + a variable (use *sum* over the *list*) + - It returns a string of the format "4 + 5 + 9 = 18" + - If the line only contains a "q" it return "" (an empty string) + - Create a method named "editor" that takes a filename as an argument + - It opens the file for writing + - It uses input_and_calculate_one_line in a while loop + - while the return result is not "", we append the string to + the file + - When the return result is "", the function exits * 2020-05-29 *** Python #6: **** DONE Lecture content