I had a productive day yesterday, and I learned that a python program is normally called a script, as python is a scripting language. I'm still sticking with 2.7, but realize that I need to get into python 3 if it's going to be useful for me. Yesterday I produced several scripts, I made another pass at the Norwegian edition of my "liturgic lexicon", and I hope to be able to make that into something lasting, and potentially useful.
Another old idea that I picked up was a program generating random numbers for use with lotto games. The improvement was that in the new script one may also choose the number of digits to play on, thus the script can be used both with VikingLotto and ordinary Lotto, and even football and horse betting. I think I might want to explore further gambling games maybe using graphics.
The greatest achievement though was the program that supplies a test of the lower multiplication tables, from 1 to 12, potentially something that my son can use while learning how to work out multiplication maths.
mandag 6. desember 2010
søndag 5. desember 2010
Vidar's Calculator!
Vidars data blog is going to be updated a little more often from now on. Slowly I'm learning ways to work python scripts.
I have now made a menu-driven calculator script, a piece of work done almost entirely without consulting books. It handles 6 different types of maths.For accounting addition I will have to set up another script, so only up to four numbers may be added at one time. Forcing the division to present the answer as a floating point number(i.e. with decimals) was also a challenge, that finally could be overcome. Python 2.7 prefers to give you answers in integers, thus applying the "remainder"-function in division, which for everyday calculations have little practical use.
I was fairly satisfied with this latest calculator script, I hope that the next time I deal with a maths script, it may even be with some graphics, either a program that draws graphs from number input, or even a calculator that looks like a calculator, but that will have to wait until I've learned more.
I have now made a menu-driven calculator script, a piece of work done almost entirely without consulting books. It handles 6 different types of maths.For accounting addition I will have to set up another script, so only up to four numbers may be added at one time. Forcing the division to present the answer as a floating point number(i.e. with decimals) was also a challenge, that finally could be overcome. Python 2.7 prefers to give you answers in integers, thus applying the "remainder"-function in division, which for everyday calculations have little practical use.
I was fairly satisfied with this latest calculator script, I hope that the next time I deal with a maths script, it may even be with some graphics, either a program that draws graphs from number input, or even a calculator that looks like a calculator, but that will have to wait until I've learned more.
onsdag 15. september 2010
Pythonlogg 1
1.1 Python versjon 2.7 on win32
1.2 first i had to look up the math operators that python uses. the easiest way proved to be to use the import math command, and then the math-specific operators like pi could be used. once these operators and how to produce them on the keyboard was clear, it was simply to enter the number given. I stored the given number, 1.5 as a numeric string, and called it back when setting up the equation. I also did this with pi; i first set up a stringname called pinumber, and used the command math.pi to get the number, this being possible after having imported the math prefunction. the word pinumber then stored the value of pi, and was later called in to enter the equation. I used A as a string label denoting the result of the calculation, and then asked python to print the value of A. This gave me the number 7.06858347058 which i believe is the correct one, the area of a circle with a given radius of 1.5. This was confirmed on an online calculator. i discovered that to use the math function "raised to the power of" i could use double asterisk in python.
1.3 i wrote a program that worked out the area of a circle with a radius of 1.5
using mostly the strategy from 1.2, i just stacked the commands together in a program, describing by use of # every step taken. i added a raw_input command to end the program, and saved it as circle.py
i then ran the program from the GUI, and it produced the right result. It then appeared to me that i was not to run it directly from the GUI but, directly from the prompt using the command import. what i learned by mistake here was the the extension py after a python module does not go together with the prompt and the import command, so i had to alter the prompt to only circle (leaving out the extension) but not the program.this worked fine.
1.4 math execises in python. i couldn't solve this first question, why 2+2 is 4, while 3.1 + 5.6 is not exactely 8.7. the reason for this is that the python version i have do the trunkation for me, so frankly i didn't know that 3.1 + 5.6 was not 8.7
the second question was easier: by assigning string names to the numbers, the numbers can be handeled more efficiently in a program, and may for one thing be used several times.
1.5 i encountered the same problems here, and i think this has to do with a change in the python source code, where numbers are no longer trunkated
the question: i think f stands for float (to show it is an floating number), and the .1 suffix tells us that the answer should be printed with one decimal, and accordingly as the number increases.
1.6 question a:
the right answer is: all orders except b. are possible to get 10 as a result
question b:
adding a bracket into a pluss or minus equation has the effect that whatever is inside the brackets are worked out prior to the equation as a whole.
1.7 multiplication /division
question a: multiplication is worked out by using the *
question b: in an equation where both addition and multiplication are used the latter is done before the former.
question c: a person who had not learned about decimals, would give the answer 2 and 1 as remainder on asked 7/3
question d: if you wanted python to supply answer to 7/3 without decimal you would have to first give it 7/3, written without decimals, and then ask for the remainder by using 7%3. this to operators could easily be combined in a written coherennt answer.
question e: in order to get python to give a floating point number as the answer the equation would have to be listed like this 7.0/3.0
1.2 first i had to look up the math operators that python uses. the easiest way proved to be to use the import math command, and then the math-specific operators like pi could be used. once these operators and how to produce them on the keyboard was clear, it was simply to enter the number given. I stored the given number, 1.5 as a numeric string, and called it back when setting up the equation. I also did this with pi; i first set up a stringname called pinumber, and used the command math.pi to get the number, this being possible after having imported the math prefunction. the word pinumber then stored the value of pi, and was later called in to enter the equation. I used A as a string label denoting the result of the calculation, and then asked python to print the value of A. This gave me the number 7.06858347058 which i believe is the correct one, the area of a circle with a given radius of 1.5. This was confirmed on an online calculator. i discovered that to use the math function "raised to the power of" i could use double asterisk in python.
1.3 i wrote a program that worked out the area of a circle with a radius of 1.5
using mostly the strategy from 1.2, i just stacked the commands together in a program, describing by use of # every step taken. i added a raw_input command to end the program, and saved it as circle.py
i then ran the program from the GUI, and it produced the right result. It then appeared to me that i was not to run it directly from the GUI but, directly from the prompt using the command import. what i learned by mistake here was the the extension py after a python module does not go together with the prompt and the import command, so i had to alter the prompt to only circle (leaving out the extension) but not the program.this worked fine.
1.4 math execises in python. i couldn't solve this first question, why 2+2 is 4, while 3.1 + 5.6 is not exactely 8.7. the reason for this is that the python version i have do the trunkation for me, so frankly i didn't know that 3.1 + 5.6 was not 8.7
the second question was easier: by assigning string names to the numbers, the numbers can be handeled more efficiently in a program, and may for one thing be used several times.
1.5 i encountered the same problems here, and i think this has to do with a change in the python source code, where numbers are no longer trunkated
the question: i think f stands for float (to show it is an floating number), and the .1 suffix tells us that the answer should be printed with one decimal, and accordingly as the number increases.
1.6 question a:
the right answer is: all orders except b. are possible to get 10 as a result
question b:
adding a bracket into a pluss or minus equation has the effect that whatever is inside the brackets are worked out prior to the equation as a whole.
1.7 multiplication /division
question a: multiplication is worked out by using the *
question b: in an equation where both addition and multiplication are used the latter is done before the former.
question c: a person who had not learned about decimals, would give the answer 2 and 1 as remainder on asked 7/3
question d: if you wanted python to supply answer to 7/3 without decimal you would have to first give it 7/3, written without decimals, and then ask for the remainder by using 7%3. this to operators could easily be combined in a written coherennt answer.
question e: in order to get python to give a floating point number as the answer the equation would have to be listed like this 7.0/3.0
Abonner på:
Innlegg (Atom)