import math
n=0
while n < 20:
print(n)
import math
sin(0)
my_list = [3,76,2,395,492,49]
my_list[-1]
my_list.reverse()
my_list[0]
my_list.pop(len(my_list)-1)
my_list
n=0
while n < 20:
print(n)
n += 1
math.sin(0)
def Divisors(num): # Define divisors function with positive integer input
list_of_divisors = [] # Define a list variable to store the divisors
for div in range(1,num+1): # loop through all possible divisors
if num%div == 0: # check if div is a divisor
list_of_divisors.append(div) # if it is, add it to the list of divisors
return list_of_divisors # return the list of divisors as output
For long comments or multi-line comments use triple quotes.
"""This is a long comment that can be
entered onto a new line and continued
for as long as you would like"""
def IsPrime(num): # define function IsPrime with integer input num
for div in range(2,int(math.sqrt(num)) +1): # loop through possible divisors of num, up to the square root
if num%div == 0: # check if the loop variable is a divisor
return False # if it is, then num is not prime and False is returned
return True # if we get through the loop, then no divisors and num is prime
Your target audience is just an average person. You should always be asking yourself, "What am I trying to tell the reader?"
Everything that did not come out of your own gray matter needs to be cited in the text with a full reference listed here.
matplotlib.pyplot
¶import matplotlib.pyplot as plt
horiz = [n for n in range(11)]
horiz
# This is the same as the above
horiz = []
for n in range(11):
horiz.append(n)
horiz
vert = [h**2 - 3*h+7 for h in horiz]
vert
vert = []
for h in horiz:
vert.append(h**2 - 3*h+7)
vert
plt.plot(horiz,vert,'r-.')
plt.show()
x = [i for i in range(20)]
y = [i**3 - 7*i**2 + 32 for i in x]
plt.plot(x,y,'go')
plt.title('Graph of $ y= x^3-7x^2+32 $')
plt.xlabel('$x$ axis')
plt.ylabel('$y$ axis')
plt.xlim([-1,16])
plt.ylim([-100,2000])
plt.show()
import math
x_vals = [math.pi*n/25 - 2*math.pi for n in range(101)]
y_vals = [math.cos(x) for x in x_vals]
plt.plot(x_vals,y_vals)
plt.title('Graph of $ y = \cos(x) $ on $ [-2\pi,2\pi] $')
plt.xlabel('$x$ values in radians')
plt.ylabel('$y$ values')
xticklocs = [math.pi*n/2 - 2*math.pi for n in range(9)]
xticklabs = ['$-2\pi$','$\\frac{-3\pi}{2}$','$-\pi$','$\\frac{-\pi}{2}$','0',
'$\\frac{\pi}{2}$','$\pi$','$\\frac{3\pi}{2}$','$2\pi$']
plt.xticks(xticklocs,xticklabs)
plt.show()