print('hello world')
hello world
print('안녕')
안녕
print('こんにちは')
こんにちは
print('안녕 こんにちは')
안녕 こんにちは
def to_f(c):
print (c* 9/5 + 32)
to_f(0)
32.0
#how can I add ℉ in the result? also, how can I multiply 10 to get rid of .0?
def to_c(f):
print ((f - 32)* 5/9)
to_c(32)
0.0
to_f(to_c(25))
-3.888888888888889
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_7672/3415340868.py in <module> ----> 1 to_f(to_c(25)) /tmp/ipykernel_7672/3211986611.py in to_f(c) 1 def to_f(c): ----> 2 print (c* 9/5 + 32) TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
to_c(to_f(90))
194.0
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_7672/2722568589.py in <module> ----> 1 to_c(to_f(90)) /tmp/ipykernel_7672/243915947.py in to_c(f) 1 def to_c(f): ----> 2 print ((f - 32)* 5/9) TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
# don't know how to fix line 66, 67
def to_f(c):
if c < -273.15:
raise ValueError("Temperature value is below absolute zero.")
return ((9/5)*c) + 32
to_f(-277)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ipykernel_7672/855616593.py in <module> ----> 1 to_f(-277) /tmp/ipykernel_7672/83324594.py in to_f(c) 1 def to_f(c): 2 if c < -273.15: ----> 3 raise ValueError("Temperature value is below absolute zero.") 4 return ((9/5)*c) + 32 ValueError: Temperature value is below absolute zero.
to_f(32)
89.6
def sign(num):
answer = '?'
if num > 0:
answer = '+'
if num < 0:
answer = '-'
if num == 0:
answer = ''
return answer
sign(4)
'+'
sign(-20)
'-'
sign(0)
''
sign(1)
'+'
def sign(num):
answer = '?'
if num > 0:
answer = '+'
elif num < 0:
answer = '-'
else:
answer = ''
return answer
name = 'Chae'
name [-1]
'e'
name[-2]
'a'
name[3]
'e'
name[-4]
'C'
name[0]
'C'
def gender(name):
if name[-1] == '돌':
return 'more likely to be male but if not, cool name!'
if name[-1] == '순':
return 'more likely to be female but if not, cool name!'
gender('빵돌')
'more likely to be male but if not, cool name!'
gender('철수')
gender('빵순')
'more likely to be female but if not, cool name!'
gender('영희')
def gender(name): if name[-1] == '수' or '돌': return 'more likely to be male but if not, cool name!' if name[-1] == '순' or '희': return 'more likely to be female but if not, cool name!'
수이거나 돌일 때 둘다 'more likely to be male but if not, cool name!를 리턴하게 하고 싶은데, 그 방법은 무엇인가? 질문!!
def gender(name):
genderanswer = 'maybe try different name!?'
if name[-1] == '돌':
genderanswer = 'more likely to be male..?'
if name[-1] == '순':
genderanswer = 'more likely to be female..?'
return genderanswer
gender('빵야')
'maybe try different name!?'
gender('빵돌')
'more likely to be male..?'
gender('빵순')
'more likely to be female..?'
def to_m(hour):
return hour*60
to_m(2)
120
to_m(2.5)
150.0
def video(minute):
runningtime = 'YOU decide whether you will watch it or not.'
if minute > 30:
runningtime = 'If you are in hurry, maybe you can watch it later..?'
elif minute < 30:
runningtime = 'Ahhh, totally watchable.'
else:
runningtime = 'Tbh this is the maximum length of video that I can watch.'
return runningtime
video(100)
'If you are in hurry, maybe you can watch it later..?'
video(20)
'Ahhh, totally watchable.'
video(30)
'Tbh this is the maximum length of video that I can watch.'
list(range(5))
[0, 1, 2, 3, 4]
list(range(0, 5))
[0, 1, 2, 3, 4]
list(range(1, 6))
[1, 2, 3, 4, 5]
list(range(15, 18))
[15, 16, 17]
n = number
n = 5
list(range(1, n+1))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_7672/3677463180.py in <module> ----> 1 n = number 2 n = 5 3 list(range(1, n+1)) NameError: name 'number' is not defined
answer = 1
for num in range (1, 6):
answer = answer * num
print(answer) #Display the current value
answer
1 2 6 24 120
120
def factorial(n):
answer = 1
for num in range (1, n+1):
answer = answer * num
return answer
factorial(5)
120
factorial(0)
1
def factorial(n):
answer = 1
if n == 0:
return 0
else for num in range (1, n+1):
answer = answer * num
return answer
File "/tmp/ipykernel_7672/3939558402.py", line 5 else for num in range (1, n+1): ^ SyntaxError: invalid syntax
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
fact(2)
2
fact(0)
1
fact(1)
1
fact(3)
6
fact(5)
120
#the functions in line 175 and line 167, basically do the same job but line 175 is better and compact
fact(-4)
--------------------------------------------------------------------------- RecursionError Traceback (most recent call last) /tmp/ipykernel_7672/211583457.py in <module> ----> 1 fact(-4) /tmp/ipykernel_7672/3422927878.py in fact(n) 3 return 1 4 else: ----> 5 return n * fact(n-1) ... last 1 frames repeated, from the frame below ... /tmp/ipykernel_7672/3422927878.py in fact(n) 3 return 1 4 else: ----> 5 return n * fact(n-1) RecursionError: maximum recursion depth exceeded in comparison
fact(4)
24
def factfail(n):
return n * factfail(n-1)
factfail(3)
--------------------------------------------------------------------------- RecursionError Traceback (most recent call last) /tmp/ipykernel_7672/2206540228.py in <module> ----> 1 factfail(3) /tmp/ipykernel_7672/1101104101.py in factfail(n) 1 def factfail(n): ----> 2 return n * factfail(n-1) ... last 1 frames repeated, from the frame below ... /tmp/ipykernel_7672/1101104101.py in factfail(n) 1 def factfail(n): ----> 2 return n * factfail(n-1) RecursionError: maximum recursion depth exceeded
factfail(5)