EDIT: my goal is to learn python well enough that I can eventually write tools/plugins useful for learning Japanese. I'm using this thread as if it were a Lang-8 journal for the Python language. So if you find something you could improve, please let me know!
I started learning python 2.7 after being inspired by this thread: http://forum.koohii.com/showthread.php?tid=9929
After doing some exercises online I decided to write a simple script that randomly picks what subjects I'll study each day. Here is the first draft:
EDIT: RawToast, just fixed the formatting with 2 'code' blocks.
I started learning python 2.7 after being inspired by this thread: http://forum.koohii.com/showthread.php?tid=9929
After doing some exercises online I decided to write a simple script that randomly picks what subjects I'll study each day. Here is the first draft:
EDIT: RawToast, just fixed the formatting with 2 'code' blocks.
Code:
# -*- coding: utf-8 -*-
#Import the specific function from the random.py module
#An alternative would be to just import the entire module
#using 'import random'
from random import randrange
#First the program asks how many slots I want to fill
#use input() to save the variable as a number
#or use raw_input() to save it as a string
slots = input ("How many slots do you want to fill today? (max. 10) ")
while (slots > 10):
slots = input ("Sorry, 10 slots is the maximum today. Please choose again. ")
print "Ok, %d it is then." % slots
#Here are my lists. Note that the first position is "0" not "1".
Subject_list = ['RSH', 'RTK', 'Guitar', 'Reading', 'Grammar', 'Programming'];
Order_list = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth']
#This loop chooses the subjects
count = 0Code:
j = 0
for count in range(0,slots): #to iterate between 0 to chosen number of slots to fill
if j < slots - 1:
subject = Subject_list[randrange(0,len(Subject_list))]
order = Order_list[j]
print "The %s subject is %s" % (order, subject)
count = count + 1
j = j + 1
print "The final subject will be %s" % subject
print "Done."
Edited: 2013-02-26, 9:22 pm
