Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
What does """ do?

Automate the Boring Stuff has a program that changes American dates to European dates. The first part of the code goes:

datePattern = re.compile(r"""\^(.\*?)

#one or two digits for the month

((0|1)?\\d)\-

#one or two dgits for the day

((0|1|2|3)?\\d)\-

#four digits for the year

((19|20)\\d\\d)

#all text after the date

(.\*?)$

""", re.VERBOSE)

I have a pretty vague idea of what everything does except for the r"""\^ part on the first line. what does """ do?

/r/Python
https://redd.it/8pghas
Double Pendulum Errors

So i was following a tutorial by The Coding Train and tried to make a double pendulum in python I looked up how to do it using tkinter and now my pendulum kinda works.The problems are that my angles are inverted and it works if i enter in a normal angle like 180° but if I try to give it an angle like 1° it works for 2 secs and then gets a math overload.If anyone knows what is going on pls help.Here's the code:

*from* math *import* sin,cos
*import* tkinter *as* tk
l1,l2,m1,m2=85,85,5,5
*#The gravity is is negative as an work around for the angles problem.*
g=-9.81
class DoublePendulum(tk.Tk):
def \_\_init\_\_(self):
tk.Tk.\_\_init\_\_(*self*)
*self*.title("Double Pendulum")
*self*.canvas=tk.Canvas(*self*,width=600,height=600,background="#343434")
*self*.canvas.grid(row=0,column=0)
*self*.a1\_v=0
*self*.a2\_v=0
*self*.a1=1
*self*.a2=1
*self*.speed=0.1
*self*.after(1,*self*.Calculate)
def Calculate(self):
*self*.canvas.delete("pendulum")
*#all the math is from https://www.myphysicslab.com/pendulum/double-pendulum-en.html*
num1=(-g\*(2\*m1+m2)\*sin(*self*.a1))
num2=-m2\*g\*sin(*self*.a1-2\**self*.a2)
num3=(-2\*sin(*self*.a1-*self*.a2)\*m2\*(*self*.a2\_v\*\*2\*l1\*cos(*self*.a1-*self*.a2)))
deno1=l1\*(2\*m1+m2-m2\*cos(2\**self*.a1-2\**self*.a2))
*self*.a1\_a=(num1+num2+num3)/deno1
num4 = 2\*sin(*self*.a1-*self*.a2)
num5=(*self*.a1\_v\*\*2\*l1\*(m1+m2))
num6=g\*(m1+m2)\*cos(*self*.a1)
num7=*self*.a2\_v\*\*2\*l2\*m2\*cos(*self*.a1-*self*.a2)
deno2=l2\*(2\*m1+m2-m2\*cos(2\**self*.a1-2\**self*.a2))
*self*.a2\_a=(num4\*(num5+num6+num7))/deno2


*self*.a1\_v+=*self*.a1\_a\**self*.speed
*self*.a2\_v+=*self*.a2\_a\**self*.speed
*self*.a1+=*self*.a1\_v\**self*.speed
*self*.a2+=*self*.a2\_v\**self*.speed

/r/Python
https://redd.it/d77wo7