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
Ingen kommentarer:
Legg inn en kommentar