개인적인 공부/Python
day 2-3 python (data tpyes exercise)
karatejin
2023. 2. 20. 22:09
Instructions
Write a program that adds the digits in a 2 digit number. e.g. if the input was 35, then the output should be 3 + 5 = 8
Warning. Do not change the code on lines 1-3. Your program should work for different inputs. e.g. any two-digit number.
Example Input
39
Example Output
3 + 9 = 12
12
e.g. When you hit run, this is what should happen:
두자리 숫자를 넣으면 10의자리 숫자와 1의 자리 숫자를 + 연산하여 결과 값을 내어라.
# 🚨 Don't change the code below 👇
two_digit_number = input("Type a two digit number: ")
# 🚨 Don't change the code above 👆
####################################
#Write your code below this line 👇
new_two_digit_number = (int(two_digit_number[0])+int(two_digit_number[1]))
print(new_two_digit_number)
34의 각 숫자의 배열 0번째 자리와 1번째 자리를 정수형으로 변환하여 + 연산을 시켜준다.
그려면 3 + 4 = 7이된다.
다른스타일
# 다른 스타일로 하기
first_digit = two_digit_number[0]
second_digit = two_digit_number[1]
result = int(first_digit) + int(second_digit)
print(result)