Learning Circle : python #7 : Initial Commit

This commit is contained in:
youngjin.han 2020-06-01 21:17:04 +09:00
parent 4ce6bd3bc2
commit 0b9adfd8f3

View file

@ -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 * 2020-05-29
*** Python #6: *** Python #6:
**** DONE Lecture content **** DONE Lecture content