3-1/Python 과제&실습

7주차-실습&과제

Donghun Kang 2024. 5. 21. 16:57

dan=[]
for x in range(2,10):
    for y in range(1,10):
        dan.append("{}*{}={}".format(x,y,x*y))
print(dan)
print()

dan = ["{}*{}={}".format(x,y,x*y) for x in range(2,10) for y in range(1,10)]
print(dan)

#더하기 사이클
print("(0~99) 의 정수를 입력하세요!")
n= int(input("Input:"))
ans = n
cnt = 0
while True:
    cnt+=1
    a = n//10
    b = n%10
    c = a+b
    d = c%10
    n = 10*b+d
    if n==ans:
        break
print("Output:",cnt)


initial=int(input())
initial=1
count=0
target=initial
while True:
    a=target//10
    b=target%10
    c=(a+b)%10
    target=(b*10)+c
    count+=1
    if target==initial:
        break

print("Output:{}".format(count))

#오늘은
month_list = [31,29,31,30,31,30,31,31,30,31,30,31]
week_list = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
target = input("Month Day:")
m,d = target.split(" ")
m=int(m)
d=int(d)
if m<1 or m>12:
    print("ERROR(month)")
elif d<1 or d>month_list[m-1]:
    print("ERROR(day)")
else:
    current = 0
    for i in range(m-1):
        current = current + month_list[i]
    current = current + d
    remain = current % 7
    print(week_list[remain])

#크로아티아 알파벳
target = input("Write word:")
croatia_ab = ['c=','c-','dz=','d-','lj','nj','s=','z=']
pivot=0
count=0
while True:
    if pivot>=len(target):
        break
    is_croatia = False
    for cab in croatia_ab:
        l_cab = len(cab)
        if target[pivot:pivot+l_cab]:
            count+=1
            pivot+=l_cab
            is_croatia = True
            break
    if not is_croatia:
        count+=1
        pivot+=1
    print("length of word is:{}".format(count))
    

word = input("Write word:")
str=list(word)
cnt=len(str)
for i in range(len(str)):
    if str[i]=='c':
        if str[i+1]=='=' or str[i+1]=='-':
            cnt-=1
    if str[i]=='d':
        if str[i+1]=='z' and str[i+2]=='=' or str[i+1]=='-':
            cnt-=1
    if str[i]=='l':
        if str[i+1]=='j':
            cnt-=1
    if str[i]=='n':
        if str[i+1]=='j':
            cnt-=1
    if str[i]=='s':
        if str[i+1]=='=':
            cnt-=1
    if str[i]=='z':
        if str[i+1]=='=':
            cnt-=1
print("length of word is:",cnt)

winning_numbers = [15, 23, 29, 34, 40, 44]
bonus_number = 20

user_numbers = []
for i in range(1, 7):
    user_number = int(input("Lottery Number({}) : ".format(i)))
    user_numbers.append(user_number)

number_match = 0
for number in user_numbers:
    if number in winning_numbers:
        number_match += 1

if number_match == 6:
    print("Your numbers:", user_numbers)
    print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
    print("1st prize: 3,000,000,000 won")
elif number_match == 5:
    if bonus_number in user_numbers:
        print("Your numbers:", user_numbers)
        print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
        print("2nd prize: 50,000,000 won")
    else:
        print("Your numbers:", user_numbers)
        print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
        print("3rd prize: 1,500,000 won")
elif number_match == 4:
        print("Your numbers:", user_numbers)
        print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
        print("4th prize: 50,000 won")
elif number_match == 3:
        print("Your numbers:", user_numbers)
        print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
        print("5th prize: 5,000 won")
else:
        print("Your numbers:", user_numbers)
        print("Winning numbers:", [15, 23, 29, 34, 40, 44], "+ 20")
        print("No prize")

'3-1 > Python 과제&실습' 카테고리의 다른 글

10주차-실습&과제  (0) 2024.05.21
9주차-실습&과제  (0) 2024.05.21
6주차-실습&과제  (0) 2024.05.19
5주차-실습&과제  (0) 2024.05.19
4주차-실습&과제  (0) 2024.05.19