Featured

Reusing Old Clock – DIY

Bought from KLCC

We bought this from KLCC many years back. Those days we used to drive to KL quite regularly. Anyway, after 2-3 years the clock did not work any more! So, when we drove to KL next time I bought a spare clock at KLCC again (I think I paid about 40 Ringgit for the spare clock) ! It worked for a number of years. But recently it stopped again and we can’t think of going to KL in pandemic times!

Couldn’t get the spare clock of the right diameter!

So, I bought this from Ali Express – spending only SGD 2.72!

Replacing the clockwork was not easy as the parts are too small. Halfway through the installation I actually thought of giving up! But finally, it is working now! I couldn’t fix the seconds-hand. But I think it doesn’t matter! Thanks to Ali Express for providing me the clockwork part!!

 

Input-routine Function in Python 3

Integer Inputs with Min and Max Values

Don’t develop the code from scratch!

Just use it for User-inputs in your program by changing the limits!

Python Codes

def int_input(a,b):
  valid=True
  print('Choose your option between ',a, 'and ',b )# a-lower limit, b-higher limit    
  while valid==True:
    try:       
       option = int(input("Please type in your option: "))
    except ValueError:
       option = -1
    if option >= a and option <= b:
        print("You chose option =",option)        
        global option1# Use global for variable outside the function
        option1=option
        valid=False
        break
    else:
        print("This is not a valid option")   
int_input(0,9)# Example 1
print('Proceeding with option:',option1)
print()
int_input(0,3)# Example 2
print('Proceeding with option:',option1)

The output is shown below after running the program on Spyder:

The code in Spyder is shown below [It is colour-coded, so easier to read]

English to Indonesian Python 3 Dictionary [Version-1.3]

Dictionary with Learning Utilities & Usage in the Same Python 3 Dictionary Structrure.

This version 1.3 is a significant upgrade with 208 entries. Now the menu program can access everything. Additionally, the same dictionary structure is used for storing ‘usages’. New usages can also be added by the user.

One may download these programs, and use, modify and distribute them as one pleases.

These programs are written in Python 3. The programs will be useful for those interested in learning how to develop a Python 3 Dictionary application.

The dictionary is in English –>> Indonesian format. The program can be used by those who are learning Indonesian at a beginner’s level. The Learning Dictionary can complement learning Bhasa Indonesia through the popular language learning program e.g. Duolingo.

The following table shows an example of the Python 3 dictionary structure including the usage, which is put in the same structure.

English/Indonesian (Keys)Indonesian/Usage (Values)Comments
book price-key, harga-valuebukubook-key,
buku-value
isaya, aku i-key, saya-value1,
aku-value2
ninesembilannine-key,
sembilan-value
pricehargaprice-key,
harga-value
bukusaya suka buku –
[i love books]
buku-usage

One only needs to use the menu_program.py to access everything in this Multi-featured Learning Dictionary.

Note:

  • All files should be put in the same directory.
  • Readme – which is this file giving you the explanations.
  • You need Python 3 program and Python Idle to run the Menu Program.
  • mypickle.pikle – folder containing the binary dictionary file (only machine readable).
  • The present version 1.3 is populated with 208 entries.
  • This program can be accessed by the accompanying menu_program.py, which drives all the utilities.
  • The following options are availble in the menu program as shown below:

The menu program has the following options:

  1. Start your Indonesian Vocabulary practice here
  2. Continue to the next word – avoid this option when starting
  3. Translate an English Word [existing in Dictionary] to Indonesian
  4. Translate an Indonesian Word [existing in Dictionary] to English
  5. View the tabulated English-Indonesian Dictionary …need to double-click to see the Squeezed Tabulation
  6. Update Dictionary with new entries – [English – Indonesian] or Usage [Indonesian – Usage]
  7. Update Dictionary with multiple values of Indonesian words for an English word
  8. Delete an entry from the English-Indonesian Dictionary
  9. Print numbers 1-21 English–>Indonesian
  10. Exit the program. Show your score and where (index) you stopped.

These programs have the following learning points in Python 3:

How to serialize and de-serialize a Python dictionary using ‘pickle’ – which is the storage and retrieval of machine-readable data?
How to create a menu in Python and accept user inputs with error mqnagement?
How to use while-loop to branch actions as per user options?
How to use a flag to detect the path of the program flow?
How to make a quiz from a large python dictionary and keep track of user’s progress?
How to provide translation of English words as per user’s requirements?
How to provide a tabulated dictionary for scrolling through.
How to provide facility for updating data in a python dictionary?
How to delete a dictionary entry?
How to provide ‘multiple values’ for a ‘key’ in a python dictionary?
How to show specific key-value pairs and present them in a table?
How to keep a score for a user while doing the vocabulary quiz?

List of Files:

TabulatedEnglishIndonesianDictionary.py – Program for tabulated output

idlecolors.py – Program for coloured outputs [only works on Idle IDE]

menu_program.py – Main program for accessing the Learning Dictionary

mypickle.pickle – File storing the dictionary data in machine-readable format also includes the usage entries

README.md – this file

All the above files can be accessed from here: Link to Files

If you have any questions, please write to me at kalyan.chatterjea@yahoo.com.sg
Thanks for using these programs.

Kalyan Chatterjea
Singapore
Wednesday, 27th April 2022

Thirty Percent Wholemeal Bread with Sourdough Starter

Sourdough Bread 30% Wholemeal
Sourdough Bread 30% Wholemeal

I used two types of sourdough starters made of – 1) plain bread flour & 2) dark rye flour

1 cup sourdough 50% Rye & 50% Plain Flour

I add a cup of the sourdough starter as shown in the above picture. This surely enhances the taste of the loaf.

For this bread, I used a Mayer 1kg breadmaker (8-dough cycle taking 1.5 hours)

Mayer 1kg Breadmaker

Ingredients

  • Water – 340 g
  • Olive oil – 2.5 tablespoons
  • Salt – 1.5 teaspoons
  • Brown sugar – 2 tablespoons
  • Plain bread flour – 400 g
  • Swiss Muesli – 160g (finely grounded)
  • Gluten flour – 2 tablespoons
  • Sunflower seeds – 8 tablespoons
  • Baker’s yeast – 0.75 teaspoon
  • 1 cup sourdough (50% plain flour + 50% rye flour)
Gluten Flour
Swiss Muesli

Put all the ingredients in the breadmaker and run the dough cycle (1.5 hours)

After the 1st rise

After the first rise, split the dough into two equal portions and then do the folding routines. The process is known as ‘Stretch and Fold bread dough‘ See it here in a YouTube post. (https://www.youtube.com/watch?v=kN1fpqlSleE)

Then put in the oven at 200C for 30 minutes.

Soft brown bread – good for an enjoyable breakfast!

The result is a very soft fluffy bread … enjoy!!

Very soft texture!

Indonesian Dictionary – Searching A Multivalue Python Dictionary

Language dictionaries will normally have many synonyms (e.g. ‘have’ could be translated as ‘ada’ or ‘punya’). With many synonyms, a language dictionary will have to be a multivalue dictionary in python.

In this post, I shall illustrate how to search for ‘values’ in such a multivalue dictionary, given a particular key (or the English word in this context). Remember, in a python dictionary, there are keys and keys have corresponding values. [e.g. default_dict = {key1: value1, key2: value2 etc}]. This searching routine could be used to develop a learning quiz based on the words from the dictionary. A simple sample dictionary is used for illustration.

Search routine for a python multivalue dictionary.

The search output is shown below:

A successful search output

Python 3 Programming – Indonesian Dictionary: Adding, Editing & Updating

This program will be useful for anyone learning Bhasa Indonesia. You need to put in, say, three new words every day. So, in a month, you will have added ninety new words to your Indonesian dictionary. My next post will provide a quiz program to test your memory using the dictionary.

Flow charts for these tasks are given below:

Program flow for the various tasks

Program 1 code is given below:

import pickle # pickle must be imported first
ind_dict={“I”:”Saya”} # first pair entered for the dictionary
print(” “,ind_dict) # print the first entry
with open (‘mypickle.pickle’ , ‘wb’) as default_ind_dict:
pickle.dump(ind_dict, default_ind_dict) # binary pickle file written to the disk

Once the above code is run the default dictionary is created with one entry [I : Saya] as a binary file in the mypickle.pickle folder.

Program 2 code is given below:

import pickle
with open (‘mypickle.pickle’, ‘rb’) as default_dict:
b_dict=pickle.load(default_dict)
print(‘The retrieved dict is ‘, b_dict)
print(‘Update your Dictionary with new words.’)
print (“=================================”)

ans=’y’

while(ans==’y’):
k=input(‘Enter key [new English word]: ‘)
v=input(‘Enter value [equivalent Indonesian word]: ‘)
c_dict={k:v}
print(c_dict)

b_dict.update(c_dict)

ans=input(‘Any more update y/n: ‘)
if (ans==’n’):
break

print(c_dict)

print(b_dict)

d_dict = dict(sorted(b_dict.items(), key=lambda item: item[0]))

Print the names of the columns.

print (“=================================”)
print (‘Your new Dictionary [sorted]’)
print (‘ ‘)
print(“{:<20} {:<30} “.format(‘ENGLISH’,’INDONESIAN’))
for k, v in d_dict.items():
indonesian = v
print(“{:<20} {:<30}”.format(k, indonesian))

with open (‘mypickle.pickle’ , ‘wb’) as default_dict:
pickle.dump(d_dict, default_dict)

The output of the program is shown above.

Python 3 Programming – Making a Quiz from a Dictionary

The last entry was about making a Python dictionary for learning new words in German. Once you have the dictionary, you could create a quiz to test your vocabulary. I created a quiz program in this blog entry! The program is given below, which is created using IDLE.

Quiz Code Part I
Quiz Code Part II
Quiz Code Part III
Quiz Part IV
User Interface of the Code

Python 3 Programming – Storing, Retrieving & Updating a Dictionary

This would be a very useful skill e.g. while learning a new language. However, this is just an example of pairs of associated information, which could be used e.g. for vocabulary learning in any subject. The example shown is a growing English-German dictionary as one learns German. The codes can be run easily on your handphone!

This blog entry will show the basic skills of:

  • Storing a Python Dictionary using Pickle
  • Opening a stored Pickled content (Unpickling) as a new Dictionary
  • Append the Unpickled Dictionary with new added entries in the Dictionary
  • Sorting the updated Dictionary
  • Update the default Dictionary with the updated version.

The flow chart below shows the sequences to be programmed.

Flowchart for the sequences

Program 1 Codes in Python 3

import pickle # pickle is used to produce a byte stream for storage and retrieval
a_dict={“evening”:”der Abend”}
print(” “,a_dict)
with open (‘mypickle.pickle’ , ‘wb’) as default_dict: #mypickle.pickle is the pickle folder
pickle.dump(a_dict, default_dict) # This where the default dictionary is pickled.

Program 2 Codes in Python 3

Python 3 Codes for Program 2

The output of Program 2

Program 2 Output

Let me know if you have any issues with the coding.

Python Programming Learning Articles in German

Using ‘Dictionary’ in Python I wrote the codes using PyCharm.

But you can easily run this on your Android phone! Just download and use Pydroid 3

Let me know if you have any comments!

v1 = “””Hotel
a. das Hotel
b. die Hotel
c. der Hotel
“”” # “”” will ensure the info is given in three lines

v2 = “””Airport
a. das Flughafen
b. der Flughafen
c. die Flughafen
“””

v3 = “””Railway Station
a. das Bahnhof
b. der Bahnhof
c. die Bahnhof
“””

v4 = “””Railway Platform
a. das Bahnsteig
b. der Bahnsteig
c. die Bahnsteig
“””

v5 = “””Train
a. das Zug
b. der Zug
c. die Zug
“””

v6 = “””Customs
a. das Zoll
b. der Zoll
c. die Zoll
“””

v7 = “””Immigration
a. das Einwanderung
b. der Einwanderung
c. die Einwanderung
“””

v8 = “””Taxi
a. das Taxi
b. der Taxi
c. die Taxi
“””

v9 = “””Downtown
a. das Innenstadt
b. der Innenstadt
c. die Innenstadt
“””

v10= “””Street
a. das Straße
b. der Straße
c. die Straße
“””

articles={v1:”a”, v2:”b”, v3:”b”, v4:”b”, v5:”b”, v6:”b”, v7:”c”, v8:”a”, v9:”c”, v10:”c”}

name=input(“What is your name? : “)

print(“Hello “, name, “, Select the correct article for the given word!”)

score=0
for i in articles:
print(i)
flag1=input(“Do you want to skip (y/n): “)

print(name, “, Your Final Score = “,score)

while flag1 != "y" and flag1 != "n": #!= means 'not equal to'
    print("Wrong input you can only type y or n")
    print(i)
    flag1=input("Do you want to skip (y/n): ")
if flag1=="y":
    continue
ans = input ("Choose the correct article (a/b/c): ") 
if ans == articles[i]:
    print("Good, you got it right! +1 point ")
    score = score + 1
    print (name,"your current score is: ",score)
    print("Now try the next!")
    print("\n")# line gap
else:
    print("Sorry wrong answer, you lost 1 point ")
    score = score - 1
    print (name,"your current score is: ",score)
    print("Now try the next!")
flag2=input("Do you want to quit? (y/n): ")
if flag2=="y":
    break
    print("\n")# line gap

Vocabulary Learning in Python

I am using Pycharm to do the coding. This is available for Windows, Mac and Linux and is also open source. You can develop and run the Python codes using this.

I am uploading a simple set of codes to learn vocabulary in any subject. The example is on learning German – 10 words related to Family. One can modify to cover any subject.

If you have any comments do let me know!

import random
answer = input(“Play game – Names of Family Members? (‘y’ to continue – answer with appropriate article”
“) “)
print(” “)
while answer == “y”:
vocabDictionary = { # dictionary/key pairs for definitions
“Uncle”: “der Onkel”, “Aunt”: “die Tante”, “Nephew”: “der Neffe”, “Niece”: “die Nichte”,
“Daughter”: “die Tochter”, “Son”: “der Sohn”,
“Grand Father”: “der Grossvater”, “Grand Mother”: “die Grossmutter”, “Cousin Brother”: “der Cousin Bruder”, “Cousin Sister”: “die Cousin Schwester”
}
keyword_list = list(vocabDictionary.keys()) # turns words into a list
random.shuffle(keyword_list) # shuffle keywords
correct = 0
wrong = 0
for keyword in keyword_list:
display = “{}”
print(display.format(keyword))
userInputAnswer = input(“ANSWER: “)
print(vocabDictionary[keyword])
print(” “)
if userInputAnswer == (vocabDictionary[keyword]):
print(“CORRECT”)
correct += 1
else:
print(“WRONG”)
wrong += 1
print(‘_’ * 25) # line separator
display = “SCORE: {} correct and {} wrong”
print(display.format(correct, wrong))
answer = input(“Play again? (‘y’ to continue) “)
print(” “)
print(“Thanks for playing”)

Reviving A 12-Year Old MacBook Air!

My daughter’s old MacBook Air probably bought in 2010!

My daughter’s old MacBook Air was bought before she went to Cambridge in 2010. It was kept as junk in her cupboard as it was not in good working order! The hard disk was sluggish. So I thought of changing the 256GB ssd with a fast ssd compatible with this computer. The Apple hardware is still very good!

I did a lot of research to select the right ssd from Ali Express! These are not so easily available in Singapore.

A much faster ssd than the original Apple ssd.

One has to choose the correct year of manufacture as the connections of these ssds are different from year to year! I chose 256GB as I don’t need a lot of storage with all my working files in Dropbox! One can choose up to 1TB. The ssd comes with MacBook opening tools as well as Mac OS.

Just open the 10 screws at back using the tool provided!
Left is the battery, right is the ssd slot

The back cover has 10 screws, which can be easily opened with the special screwdrivers provided. Once the back cover is open, one can access the ssd. It has to be pulled out slowly after unscrewing the single screw on the right side. But before this, the battery must be deactivated by pulling out the battery tab.

Now push in the new ssd and screw in the single holding screw. Reactivate the battery.

Next, fit back the cover with the 10 holding screws. That’s all.

Now start the computer. Mac OS is already on the ssd. So, if one has an Apple ID, it will be easy to sign in. But in my case, I was putting Manjaro Linux on the system. So, I put the USB based Manjaro OS and started the system by pressing the option key while starting. Once installed, the Manjaro Linux worked flawlessly! Must thank Ali Express and the ssd manufacturer in China for the wonderful service! The cost of the whole upgrade was less than 60 SGD (cost of ssd). Amazing!

Manjaro Linux on MacBook Air
Signing into a sleek Manjaro Linux