Comments (4)
#리스트를 이용한 과제 1번 코드
def solution(n):
answer = 0
n = list(str(n))
for i in n:
answer += int(i)
return answer
print(solution(987)) #24
print(solution(123)) #6
from 2021-spring-python-tutoring.
이건 코듭니다.
def fastmult2(m,n):
ans = 0
while n > 0:
if n % 2==0:
return fastmult2((m*n)//(n/2),n//2)
else:
return m + fastmult2(m, n-1)
n, ans = n-1, ans
return ans
이건 실행값과 결과입니다.
print( fastmult2(3,0))
print( fastmult2(3,1))
print( fastmult2(3,2))
print( fastmult2(3,5))
0
3
6.0
15.0
해당 결과에서 0 3 6 15 이렇게 소수점을 없애고 싶습니다 어떤 조건을 추가해야 합니까?
from 2021-spring-python-tutoring.
과제 1번 코드
저는 처음에 이렇게 풀었습니다.
def solution(n):
answer = 0
digit = 10
remainder = 0
isEnd = False
while isEnd == False:
remainder = n % digit
answer += remainder // (digit // 10)
if n // digit == 0:
isEnd = True
digit *= 10
return answer
ex)
n = 123
remainder = 123 % 10 (== 3)
answer += remainder(3) // (digit(10) // 10) (== 3(3 // 1))
digit = 10 * 10
remainder = 123 % 100 (== 23)
answer += remainder(23) // (digit(100) // 10) (== 3 + 2(23 // 10))
digit = 100 * 10
remainder = 123 % 1000 (== 123)
answer += remainder(123) // (digit(1000) // 10) (== 3 + 2 + 1(123 // 100))
(n // digit == 0) == True(123 // 1000 == 0)
isEnd = True
return answer
from 2021-spring-python-tutoring.
안녕하세요. 질문 자세하게 잘 적어주셨네요.
혹시 문제를 해결하기 위해서 어떤 것을 시도해보셨는지 알 수 있을까요?
지금은 나눗셈을 하는 과정에서 정수형 변수가 실수형 변수로 변하는 파이썬의 나눗셈 특성 때문에 원하는 결과를 얻지 못한 것 같습니다.
혹시 파이썬 정수로 나누기, 파이썬 소수점 없애기 등 검색을 통해서 해결해볼 수 있을까요?
from 2021-spring-python-tutoring.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 2021-spring-python-tutoring.