Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sunday 22 February 2015

Bahan-bahan / yang perlu disediakan:

1. Sebuah cerita, contoh seperti berikut:

Once upon a time there was a wizard called Carrie Anne. She and some friends found themselves in the magic land of Turingville. This land was ruled by Ben the wizard. All of sudden a mysterious voice spoke to them from high in the sky and said you must kiss Ben the wizard to lift the curse of not being able to use technology.

2. Sebuah nama pengguna
3. Sebuah gender pengguna
4. Sebuah kondisi untuk mendapatkan pronoun berdasarkan gender pengguna, apakah he/she/it.
4. Sebuah nama hari ini.
5. 4 buah list:
List pertama : peranan / role
List kedua : nama-nama teman yang ada disekitar / names
List ketiga : nama-nama tindakan / actions
List keempat : nama-nama tempat / places
6. Dan sebuah randomisasi

Start of making

Cerita diatas bisa dibuat sebagai berikut:

Once upon a time there was a ____ called ____ . ____ and some friends found themselves in the magic land of ____. This land was ruled by ____ the ____. All of sudden a mysterious voice spoken to them from high in the sky and said you must ____ ____ the ____ to lift the curse of not being able to use technology.

Yang pada akhirnya bisa dibuat sebagai berikut:

Once upon a time, there was a  actor_role called name. " pronoun and some friends found themselves in the magic land of magic_place. This land was ruled by actor_name the actor_role. All of a sudden a mysterious voice spoke to them from high in the sky and said you must quest actor_name the actor_role to lift the curse of not being able to use technology.

List

List yang dipakai:
roles = ["Knight", "Princess", "Prince", "Frog", "Wizard", "ogre"]
names = ["Ben", "Dave", "Liz", "Alex", "Rachel", "Clive", "Eben"]
actions = ["slay", "kiss", "save", "marry", "rescue", "eat"]
places = ["Computopia", "Turringville", "Digitopolis", "Bool city"]

Randomisasi

Randomisasi yang akan dipakai tapi sebelumnya harus mengimpor module random. Sebagai berikut:

import random

actor_name =  random.choice(names)
actor_role = random.choice(roles)
quest = random.choice(actions)
magic_place = random.choice(places)

Jika diperhatikan variabel hasil randomisasi inilah yang akan dipakaikan kedalam cerita dan taruh perintah import random di paling atas program.

Kondisi untuk mendapatkan pronoun

Tapi sebelumnya harus mendapatkan gender pengguna. Jadi langkah 3 dan 4 disatukan sebagai berikut:
gender = input ('Apakah kamu cowok atau cewek? ')
if gender == "girl":
    pronoun = "she"
elif gender == "boy":
    pronoun = "he"
else
    pronoun = "it"

Sebuah nama pengguna


Untuk mendapatkan nama pengguna sebagai berikut dan disimpan ke dalam variabel name.
name = input ('What is your name? ')

Merangkumkan program

name = input ('What is your name? ')
gender = input('Apakah kamu boy atau girl? ')
if gender == "girl":
    pronoun = "she"
elif gender == "boy"
    pronoun = "he"
else
    pronoun = "it"

 'List
roles = ["Knight", "Princess", "Prince", "Frog", "Wizard", "Ogre"]
names = ["Ben", "Dave", "Liz", "Alex", "Rachel", "Clive", "Eben"]
actions = ["slay", "kiss", "save", "marry", "rescue", "eat"]
places = ["Computopia", "Turringville", "Digitopolis", "Bool city"]

'Randomization
actor_name = random.choice(names)
actor_role = random.choice(roles)
quest = random.choice(actions)
magic_place = random.choice(places)

'Now, the story
Story = "Once upon a time, there was a " + actor_rule + "called " + name + ". " + pronoun + " and some friends found themselves in the magic land of " + magic_place + ". This land was ruled by " + actor_name + " the " + actor_role + ". All of sudden a mysterious voice spoke to them from high in the sky and said you must " + quest + " "  + actor_name + " the " + actor_role + " to lift the curse of not being able to use technology... "

The video to show:
 

Python Introduction

1. Printing
2. Variables
3. Basic math operator (add/tambah, subtract/kurang, multiply/kali)
4. Basic variable types(string, integers)
5. Concatenating string
6. Casting an integer to a string
7. Booleans (True/False)
8. Inequalities (Greater than / less than)
9. If/Else statements
10. Lists
11. List method
12. Adding list together with +
13. Sets
14. For loops
15. Indexing strings
16. Splitting strings
17. Tuples
18. Dictionaries


IDLE3 (Python Programming environment) mencakup:
1. Python shell window: to see result when you Run/F5 your code.
2. Python Editor Window: in which you can write, save and test your code.