Python Forum
I dont think that this i hard, but I dont understand!
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I dont think that this i hard, but I dont understand!
#11
Do the tutorial in the python documents.
Reply
#12
(Nov-29-2016, 07:52 PM)Linamellannamn Wrote: No I haven't! This is our first "task" :( By commands I mean: How do I write a loop and what does a loop mean? I think that you use + when you add, * when you multiply and / when you divide!

A loop is  as sequence of instructions which is executed several times. It either executed a fixed number of times:

for i in range(5):
   print i
Or executed while some condition is true

i=0
while i<5:
   print i
   i+=1
I'm surprised you are told to write this kind of code without being shown the basics...


Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#13
(Nov-28-2016, 09:32 PM)Ofnuts Wrote:
(Nov-28-2016, 06:33 PM)Linamellannamn Wrote: I understand! I found something similar online, would this be something? 
def ctrapezoidal(f,a,b,n):
   h=(b-a)/n
   s=(f(a)+f(b))*0.5*h;
   for i in xrange(1,n):
       s+=h*f(a+h*i)
   return s

Something like this. However, this is well optimized code, absolutely not the kind of code your teacher would expect from you at this point. So be prepared to be able to explain in excruciating detail how/why this code works (hint: this has more to do with math than with Python, actually).

This response made me laugh so hard..... and while I couldn't reproduce this kind of code on my own either, I understand the math behind what I'm looking at.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  This is Very Hard! Harshil 13 4,613 Aug-16-2020, 05:09 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020