print('hello world')
hello world
python hi.py
File "/tmp/ipykernel_5601/20599173.py", line 1 python hi.py ^ SyntaxError: invalid syntax
python 'hi.py'
File "/tmp/ipykernel_5601/1010579365.py", line 1 python 'hi.py' ^ SyntaxError: invalid syntax
path
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_5601/177386211.py in <module> ----> 1 path NameError: name 'path' is not defined
def to_f(c):
return c * (9/5) + 32
to_f(100)
212.0
to_f(0)
32.0
def to_c(f):
if f < -459.67:
raise ValueError("Temperature value is below absolute zero and itss freezing")
return (5/9) * (f-32)
to_c(32)
0.0
def to_f(c):
if c < -273.15:
raise ValueError("Temperature value is below absolute zero and itss freezing")
return c * (9/5) + 32
to_f(-400)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ipykernel_5601/3754567286.py in <module> ----> 1 to_f(-400) /tmp/ipykernel_5601/1986318497.py in to_f(c) 1 def to_f(c): 2 if c < -273.15: ----> 3 raise ValueError("Temperature value is below absolute zero and itss freezing") 4 return c * (9/5) + 32 ValueError: Temperature value is below absolute zero and itss freezing
#oke
def sign(num):
answer = '?'
if num > 0:
answer = '+'
if num < 0:
answer = '-'
if num == 0:
answer = ''
return answer
sign(12340)
'+'
sign('asbds')
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_5601/4263612129.py in <module> ----> 1 sign('asbds') /tmp/ipykernel_5601/310610186.py in sign(num) 1 def sign(num): 2 answer = '?' ----> 3 if num > 0: 4 answer = '+' 5 if num < 0: TypeError: '>' not supported between instances of 'str' and 'int'
sign(-123123)
'-'
sign(0)
''
def sign(num):
answer = ''
if num > 0:
answer = '+'
if num < 0:
answer = '-'
return answer
sign(0)
''
# 7-1
def gender(name):
indicated = '?'
if name[-1] == 'a':
indicated = 'female'
if name[-1] == 'o':
indicated = 'male'
return indicated
gender('sumo')
'male'
gender('fish+chips')
'?'
gender('chickpea')
'female'
# 7-2
# tatami to egg-cartons
# (if your jap flat needs to be soundproof)
# tatami 910×1820 mm
# egg-carton:100x295 mm (12 eggs)
# total size
tatami = 910 * 1820
egg_carton = 100 *295
# ratio between the tatami and the egg carton
# 56.14
ratio = tatami / egg_carton
def to_eggs(tatami):
return tatami * 56.14 * 12
def to_tatami(eggs):
return (eggs / 12) / 56.14
to_tatami(12324)
18.29277864992151
# lot of eggsss ahah
# 7-3
# sphynx algorithm
# it classifies animal by the number of their legs
# 0 → something that swim or sneak
# 1 → some strange bird
# 2 → something that walk or run
# 3 → maybe an elder one ?
# 4 → not a snake for sure
# >4 → pests and insects
def how_many(legs):
animal = '???'
if legs == 0:
animal = 'Something that swim or sneak'
elif legs == 1:
animal = 'Some strange bird'
elif legs == 2:
animal = 'something that walk or run'
elif legs == 3:
animal = 'maybe an elder one ?'
elif legs == 4:
animal = 'not a snake for sure'
elif legs > 4:
animal = 'little insect or spidey'
return animal
how_many(5324)
'little insect or spidey'
# 7.6 The Factorial
list(range(5))
[0, 1, 2, 3, 4]
range(5)
range(0, 5)
list(range(5))
[0, 1, 2, 3, 4]
range(5,10)
range(5, 10)
list(range(5,10))
[5, 6, 7, 8, 9]
def fact(n):
if n==0:
return 1
elif n<0:
raise(ValueError('Insert a positive number'))
else:
return n * fact(n-1)
fact(4)
24
# fan dei fan
def factorial(n):
if n < 0:
raise(ValueError('Insert a positive number'))
answer = 1
for num in range(1, n+1):
answer = answer * num
return answer
factorial(5)
120
fact(5)
120
# nice
factorial(-1)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-56-5aae425d6a8b> in <module> ----> 1 factorial(-1) <ipython-input-52-52488708d6ad> in factorial(n) 1 def factorial(n): 2 if n < 0: ----> 3 raise(ValueError('Insert a positive number')) 4 answer = 1 5 for num in range(1, n+1): ValueError: Insert a positive number
fact(-1)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-57-0d859b47dc0b> in <module> ----> 1 fact(-1) <ipython-input-49-e6a4ffcd222c> in fact(n) 3 return 1 4 elif n<0: ----> 5 raise(ValueError('Insert a positive number')) 6 else: 7 return n * fact(n-1) ValueError: Insert a positive number
# Free Project 7-3 tomorrow now im tired