[:5]
is the five included? - ANS-NOPE
is going from 0-four
Can you multiple tuples? - ANS-nope
def add1(x):
if x + 1 < 10:
return x + 1
else:
return 'Too big!'
print(add1(1), add1(24)) - ANS-2 Too big!
Don't forget: the coma automatically creates a space
def Estellemail():
'''This funtion will explain how to write an email'''
print("Good Afternoon, nnPlease find attached...")
help(Estellemail)
Estellemail() - ANS-This funtion will explain how to write an email
Good Afternoon,
Please find attached...
First prints the help because we ask for it in the code
then prints the rest of the function bc we call it
def myfunction(a, b=2, c):
return a * b * c
print(myfunction(1, 2, 3)) - ANS-will print ERRRRROOOORR
to fix it:
def myfunction(a, b=2, c=2):
return a * b * c
print(myfunction(1, 2, 3))
#everything after the first thing you change has to change in the parameters
#maria's clear explanation: "a non default parameter can't follow a default parameter
#be better Estelle
def plus1_3(x):
return (x + 1, x + 3)
print(plus1_3(2)[0]) - ANS-3
Apparently tuples are kinda like list but you can't change them so they have indexes
, tuples = lame list
Errors:
syntax:
run-time: - ANS-using incorrect syntax --> syper will trap
code will no longer run at all maximum of the time
mistakes that manifest at the runtime
- user's fault
- infinite loop
- 0 division
common sense mistakes:
code will run but wrong output
regularly supply of trojan horse
import numpy as np
import matplotlib.Pyplot as plt
x = np.Linspace(-2, 2, 25)
y1 = x
y2 = x ** 2
plt.Plot(x, y1, 'g', linewidth = three)
plt.Plot(x, y2, 'k', marker = 'o', markerfacecolor = 'b')
plt.Axis([-2, 2, -2, 4])
plt.Xlabel('x')
plt.Ylabel('f(x)')
plt.Title('Plots for two polynomials')
plt.Legend(['straight', 'curved'], loc = 'higher middle')
plt.Display() - ANS-it is a completely high-quality graph, agree with me
<3
import numpy as np
mygrid = np.Arange(9).Reshape(3, 3)
print(mygrid)
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Ashley96. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.99. You're not tied to anything after your purchase.