Python 3.11.5 (main, Sep 11 2023, 08:31:25) [Clang 14.0.6 ]
Type "copyright", "credits" or "license" for more information.
IPython 8.15.0 -- An enhanced Interactive Python.
In [1]: runfile('/Users/py4cs/Desktop/odeintexample1.py', wdir='/Users/py4cs/Desktop')
Important |
Figures are displayed in the Plots pane by default. To make them also appear inline in the console, you need to uncheck "Mute inline plotting" under the options menu of Plots. |
In [2]: sol
Out[2]:
message: The solver successfully reached the end of the integration interval.
success: True
status: 0
t: [ 0.000e+00 1.000e-01 ... 1.900e+00 2.000e+00]
y: [[ 1.700e+01 1.392e+01 ... 3.811e-01 3.120e-01]]
sol: None
t_events: None
y_events: None
nfev: 38
njev: 0
nlu: 0
In [3]: sol.t
Out[3]:
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2,
1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. ])
In [4]: sol.y[0]
Out[4]:
array([17. , 13.91803459, 11.39009556, 9.32278191, 7.63617431,
6.25746971, 5.12334884, 4.19316704, 3.43317972, 2.81244906,
2.30338172, 1.88520903, 1.54320601, 1.26397497, 1.0354715 ,
0.84761959, 0.69375028, 0.56808723, 0.46540526, 0.38112148,
0.31203619])
In [5]: runfile('/Users/py4cs/Desktop/odeintexample1.py', wdir='/Users/py4cs/Desktop')
In [6]: runfile('/Users/py4cs/Desktop/odeintexample2.py', wdir='/Users/py4cs/Desktop')
In [7]: runfile('/Users/py4cs/Desktop/odeintexample1dHO.py', wdir='/Users/py4cs/Desktop')
In [8]: runfile('/Users/py4cs/Desktop/odeintexample1dHO.py', wdir='/Users/py4cs/Desktop')
In [9]: runfile('/Users/py4cs/Desktop/odeintexample1dHO.py', wdir='/Users/py4cs/Desktop')
In [10]: runfile('/Users/py4cs/Desktop/odeintexample1dHO.py', wdir='/Users/py4cs/Desktop')
In [11]: runfile('/Users/py4cs/Desktop/odeintexample1dHO.py', wdir='/Users/py4cs/Desktop')
In [12]: runfile('/Users/py4cs/Desktop/odeintexample1.py', wdir='/Users/py4cs/Desktop')
In [13]: runfile('/Users/py4cs/Desktop/odeintexample1.py', wdir='/Users/py4cs/Desktop')
In [14]: sol
Out[14]:
message: The solver successfully reached the end of the integration interval.
success: True
status: 0
t: [ 0.000e+00 4.082e-02 ... 1.959e+00 2.000e+00]
y: [[ 1.000e+01 9.216e+00 ... 1.992e-01 1.836e-01]]
sol: None
t_events: None
y_events: None
nfev: 38
njev: 0
nlu: 0
In [15]: runfile('/Users/py4cs/Desktop/mixstrings.py', wdir='/Users/py4cs/Desktop')
In [16]: mixstrings("One", "Two")
Out[16]: 'OTnweo'
In [17]: t = ["This", "is", "a", "test"]
In [18]: t
Out[18]: ['This', 'is', 'a', 'test']
In [19]: "-".join(t)
Out[19]: 'This-is-a-test'
In [20]: " ".join(t)
Out[20]: 'This is a test'
In [21]: " ".join(t)
Out[21]: 'This is a test'
In [22]: "".join(t)
Out[22]: 'Thisisatest'
In [23]: test_mixstrings_basic()
Traceback (most recent call last):
Cell In[23], line 1
test_mixstrings_basic()
NameError: name 'test_mixstrings_basic' is not defined
In [24]: test_mixstrings_basics()
In [25]: runfile('/Users/py4cs/Desktop/mixstrings.py', wdir='/Users/py4cs/Desktop')
Traceback (most recent call last):
File ~/anaconda3/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)
File ~/Desktop/mixstrings.py:40
test_mixstrings_basics()
File ~/Desktop/mixstrings.py:26 in test_mixstrings_basics
assert mixstrings("hello", "world") == "hweolrllod"
AssertionError
In [26]: mixstrings("One", "Two")
Out[26]: 'OTnweoX'
In [27]: test_mixstrings_basics()
Traceback (most recent call last):
Cell In[27], line 1
test_mixstrings_basics()
File ~/Desktop/mixstrings.py:26 in test_mixstrings_basics
assert mixstrings("hello", "world") == "hweolrllod"
AssertionError
In [28]: mixstrings("hello", "world")
Out[28]: 'hweolrllodX'
In [29]: mixstrings("hello", "world") == "hweolrllod"
Out[29]: False
In [30]: runfile('/Users/py4cs/Desktop/mixstrings.py', wdir='/Users/py4cs/Desktop')
In [31]: isinstance?
Signature: isinstance(obj, class_or_tuple, /)
Docstring:
Return whether an object is an instance of a class or of a subclass thereof.
A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
or ...`` etc.
Type: builtin_function_or_method
In [32]: isinstance(4, int)
Out[32]: True
In [33]: runfile('/Users/py4cs/Desktop/factorial.py', wdir='/Users/py4cs/Desktop')
============================= test session starts ==============================
platform darwin -- Python 3.11.5, pytest-7.4.0, pluggy-1.0.0 -- /Users/py4cs/anaconda3/bin/python
cachedir: .pytest_cache
rootdir: /Users/py4cs/Desktop
plugins: anyio-3.5.0
collected 4 items
factorial.py::test_basics PASSED [ 25%]
factorial.py::test_against_standard_lib PASSED [ 50%]
factorial.py::test_negative_number_raises_error PASSED [ 75%]
factorial.py::test_noninteger_number_raises_error PASSED [100%]
============================== 4 passed in 0.01s ===============================
In [34]: factorial(3)
Out[34]: 6
In [35]: factorial(-1)
Traceback (most recent call last):
Cell In[35], line 1
factorial(-1)
File ~/Desktop/factorial.py:15 in factorial
raise ValueError(f"n should be > 0 but n={n}")
ValueError: n should be > 0 but n=-1
In [36]: factorial(0.1)
Traceback (most recent call last):
Cell In[36], line 1
factorial(0.1)
File ~/Desktop/factorial.py:20 in factorial
raise TypeError(f"n must be integer but is {type(n)}.")
TypeError: n must be integer but is <class 'float'>.
In [37]: raise ValueError("XXXXXXXXX")
Traceback (most recent call last):
Cell In[37], line 1
raise ValueError("XXXXXXXXX")
ValueError: XXXXXXXXX
In [38]: factorial(-100)
Traceback (most recent call last):
Cell In[38], line 1
factorial(-100)
File ~/Desktop/factorial.py:15 in factorial
raise ValueError(f"n should be > 0 but n={n}")
ValueError: n should be > 0 but n=-100
In [39]: runfile('/Users/py4cs/Desktop/factorial.py', wdir='/Users/py4cs/Desktop')
Reloaded modules: factorial
============================= test session starts ==============================
platform darwin -- Python 3.11.5, pytest-7.4.0, pluggy-1.0.0 -- /Users/py4cs/anaconda3/bin/python
cachedir: .pytest_cache
rootdir: /Users/py4cs/Desktop
plugins: anyio-3.5.0
collected 4 items
factorial.py::test_basics PASSED [ 25%]
factorial.py::test_against_standard_lib PASSED [ 50%]
factorial.py::test_negative_number_raises_error PASSED [ 75%]
factorial.py::test_noninteger_number_raises_error PASSED [100%]
============================== 4 passed in 0.01s ===============================
In [40]: runcell(0, '/Users/py4cs/Desktop/Time.py')
In [41]: Time
Out[41]: __main__.Time
In [42]: Time()
Traceback (most recent call last):
Cell In[42], line 1
Time()
TypeError: Time.__init__() missing 2 required positional arguments: 'hour' and 'min'
In [43]: Time(10, 29)
Out[43]: <__main__.Time at 0x1090b29d0>
In [44]: t = Time(10, 29)
In [45]: type(t)
Out[45]: __main__.Time
In [46]: t.hour
Out[46]: 10
In [47]: t.min
Out[47]: 29
In [48]: t.print12h
Out[48]: <bound method Time.print12h of <__main__.Time object at 0x1094fa250>>
In [49]: t.print12h()
10:29 am
In [50]: t.print24h()
10:29
In [51]: c = 3 + 10j
In [52]: c.imag
Out[52]: 10.0
In [53]: c.real
Out[53]: 3.0
In [54]: c.conjugate()
Out[54]: (3-10j)
In [55]: t.print24h()
10:29
In [56]: runfile('/Users/py4cs/Desktop/Time.py', wdir='/Users/py4cs/Desktop')
Reloaded modules: factorial
print as 24h:
Traceback (most recent call last):
File ~/anaconda3/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)
File ~/Desktop/Time.py:24
t.print24h()
File ~/Desktop/Time.py:7 in print24h
print(f"{self.hour:2}:{self.min_:2}")
AttributeError: 'Time' object has no attribute 'min_'
In [57]: runfile('/Users/py4cs/Desktop/Time.py', wdir='/Users/py4cs/Desktop')
print as 24h:
15:45
print as 12h:
3:45 pm
The time is 15 hours and 45 minutes.
In [58]: complex?
Init signature: complex(real=0, imag=0)
Docstring:
Create a complex number from a real part and an optional imaginary part.
This is equivalent to (real + imag*1j) where imag defaults to 0.
Type: type
Subclasses: complex128
In [59]: complex(1, 3)
Out[59]: (1+3j)
In [60]: runcell(0, '/Users/py4cs/Desktop/Time.py')
In [61]: Time(10, 29)
Out[61]: <__main__.Time at 0x1090b2c50>
In [62]: runcell(0, '/Users/py4cs/Desktop/Time.py')
In [63]: Time(10, 29)
Traceback (most recent call last):
Cell In[63], line 1
Time(10, 29)
TypeError: Time.__init__() missing 1 required positional argument: 'name'
In [64]: runfile('/Users/py4cs/Desktop/Time.py', wdir='/Users/py4cs/Desktop')
Traceback (most recent call last):
File ~/anaconda3/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)
File ~/Desktop/Time.py:22
t = Time(15, 45)
TypeError: Time.__init__() missing 1 required positional argument: 'name'
In [65]: t Time(10, 29, 'local')
Cell In[65], line 1
t Time(10, 29, 'local')
^
SyntaxError: invalid syntax
In [66]: t = Time(10, 29, 'local')
In [67]: t.print24h()
local 10:29
In [68]: t.print12h()
10:29 am
In [69]: t.hour > 12
Out[69]: False
In [70]: runcell(0, '/Users/py4cs/Desktop/Time.py')
In [71]: 12 % 10
Out[71]: 2
In [72]: 22 % 12
Out[72]: 10
In [73]: 9 % 12
Out[73]: 9
In [74]: t.min_
Out[74]: 29
In [75]: t.print24h()
local 10:29
In [76]: t.min_ = 31
In [77]: t.print24h()
local 10:31
In [78]: runcell(0, '/Users/py4cs/Desktop/Time3.py')
In [79]: t = Time(22, 30)
In [80]: repr(t)
Out[80]: 'Time(22, 30)'
In [81]: str(t)
Out[81]: '[ 22:30 ]'
In [82]: Time(22, 30)
Out[82]: Time(22, 30)
In [83]: print(t)
[ 22:30 ]
In [84]: runcell(1, '/Users/py4cs/Desktop/Time3.py')
Informal string representation of the object t1: [ 15:45 ]
Representation of object = Time(15, 45)
compare t1 and t2:
t1 is greater than t2
In [85]: t1
Out[85]: Time(15, 45)
In [86]: t2
Out[86]: Time(10, 55)
In [87]: t1 > t2
Out[87]: True
In [88]: runfile('/Users/py4cs/Desktop/Time3a.py', wdir='/Users/py4cs/Desktop')
TimeUK object = [ 3:45 pm]
Time object = [ 16:15 ]
compare t3 and t4:
t3 is not greater than t4
In [89]: runfile('/Users/py4cs/Desktop/Time3a.py', wdir='/Users/py4cs/Desktop')
TimeUK object = [ 3:45 pm]
Time object = [ 16:15 ]
compare t3 and t4:
t3 is not greater than t4
In [90]: runfile('/Users/py4cs/Desktop/Time3a.py', wdir='/Users/py4cs/Desktop')
TimeUK object = [ 3:45 pm]
Time object = [ 16:15 ]
compare t3 and t4:
t3 is not greater than t4
In [91]: import Time3a
In [92]: