def ratio(x, y):
"""The ratio of `x` to `y`."""
return x / ydef ratio(x, y):
"""The ratio of `x` to `y`.
return the result"""
result = x / y
return resulthelp(ratio)Help on function ratio in module __main__:
ratio(x, y)
The ratio of `x` to `y`.
return the result
ratio?? ratioratio ? Cell In[7], line 1
ratio ?
^
SyntaxError: invalid syntax
?ratio?printtype(ratio)functionratio(4 / 2)---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 1
----> 1 ratio(4 / 2)
TypeError: ratio() missing 1 required positional argument: 'y'ratio(4, 2)2.0ratio(4, 2)
print("I hope you liked your result")I hope you liked your result
def ratio2(x, y):
"""The ratio of `x` to `y`."""
print(x / y)ratio(4, 2)2.0def ratio(x, y):
"""The ratio of `x` to `y`."""
return x / yratio(4, 2)2.0result = ratio(4, 2)
print(result)2.0
result = ratio2(4, 2)
print(result)2.0
None
resultratio(10, 7)1.4285714285714286def answer_to_the_ultimate_question_of_life_the_universe_and_everything():
"""Simpler program than Deep Thought's, I bet."""
return 42answer_to_the_ultimate_question_of_life_the_universe_and_everything<function __main__.answer_to_the_ultimate_question_of_life_the_universe_and_everything()>answer_to_the_ultimate_question_of_life_the_universe_and_everything()42ratio<function __main__.ratio(x, y)>ratio(5, 3)1.6666666666666667answer_to_the_ultimate_question_of_life_the_universe_and_everything()42print('Hello world')Hello world
print()
pi = 3.14159pi = 22/7pi3.142857142857143def pi():
return 3.14159pi()3.14159def greet(name):
print('Hello', name)result = greet('Jonathan')Hello Jonathan
resultint = floatint('4')4.0int == __builtin__.intFalseint == __builtin__.floatTrueint = __builtin__.intint('4')4def int(name):
print('Hello', name)int('Peter')Hello Peter
int = __builtin__.intdef complement_base(base):
"""Returns the Watson-Crick complement of a base."""
if base in 'Aa':
return 'T'
elif base in 'Tt':
return 'A'
elif base in 'Gg':
return 'C'
elif base in 'Cc':
return 'G'
else:
return 'N'complement_base('N')'N'complement_base('c')'G'seq = 'GACAGACTCCATGNNNNNNNCACGTGGGUATCTGTC'
complement_base(seq)'N'def complement(seq):
"""Complement an entire sequence of DNA"""
complement_seq = ''
for base in seq:
complement_seq += complement_base(base)
return complement_seqcomplement(seq)'CTGTCTGAGGTACNNNNNNNGTGCACCCNTAGACAG'list(reversed(seq))['C',
'T',
'G',
'T',
'C',
'T',
'A',
'U',
'G',
'G',
'G',
'T',
'G',
'C',
'A',
'C',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'G',
'T',
'A',
'C',
'C',
'T',
'C',
'A',
'G',
'A',
'C',
'A',
'G']reversed(seq)<reversed at 0x7fda3860b970>next(reversed(seq))'C'seq[::-1]'CTGTCTAUGGGTGCACNNNNNNNGTACCTCAGACAG'def rev_complement(seq):
"""Reverse complement an entire sequence of DNA"""
complement_seq = ''
for base in reversed(seq):
complement_seq += complement_base(base)
return complement_seqseq'GACAGACTCCATGNNNNNNNCACGTGGGUATCTGTC'rev_complement(seq)'GACAGATNCCCACGTGNNNNNNNCATGGAGTCTGTC'seq = 'GATACCA'rev_complement(seq)'TGGTATC'complement_base()---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[63], line 1
----> 1 complement_base()
TypeError: complement_base() missing 1 required positional argument: 'base'def complement_base(base, moltype='DNA'):
"""Returns the Watson-Crick complement of a base.
base: str - a single character base
moltype: str - can be 'DNA' or 'RNA', the type of biomolecule
"""
print('moltype is', moltype)
if base in 'Aa':
if moltype == 'DNA':
return 'T'
elif moltype == 'RNA':
return 'U'
elif base in 'TtUu':
return 'A'
elif base in 'Gg':
return 'C'
elif base in 'Cc':
return 'G'
else:
return 'N'complement_base('U', moltype='RNA')moltype is RNA
'A'complement_base('A')moltype is DNA
'T'complement_base('A', moltype='DNA')moltype is DNA
'T'?printdef greet(*names):
print("names:", type(names))
greet('Peter')names: <class 'tuple'>
def greet(*names):
for name in names:
print('Hello', name)
greet('Peter')Hello Peter
greet('Peter', 'Thabo')Hello Peter
Hello Thabo