2 분 소요

간단 피보나치 수열 출력 프로그램

lst=[0,1]

loop = int(input("count loop (only num) : "))

for i in range(loop):
    print(lst)
    lst.append(lst[-1]+lst[-2])
count loop (only num) : 10
[0, 1]
[0, 1, 1]
[0, 1, 1, 2]
[0, 1, 1, 2, 3]
[0, 1, 1, 2, 3, 5]
[0, 1, 1, 2, 3, 5, 8]
[0, 1, 1, 2, 3, 5, 8, 13]
[0, 1, 1, 2, 3, 5, 8, 13, 21]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

간이 로그인 프로그램

id = "master"
pw = "free1234"

def LoginFailCheck(cd):
    if(cd <= 0): # 카운트다운이 0 또는 음수 값에 도달하면 아래 명령문을 실행합니다.
        print("Login failed!")
    else:
        print(f"\n{cd} Login attemps remaining!") # 남은 로그인 시도 횟수 표시

countdown = 5 # 올바른 id, 암호를 입력하기 위해 남은 시도 횟수를 추적하는 변수 만들기
        
# 중첩되는 흐름 제어의 예(서로 내부에 배치), 이 예제 루프는 중지하기 전에 6번의 실행을 허용합니다.
for i in range(6):
    in_id = str(input("enter your id: ")) # id 입력...
    
    if( id == in_id ):
        in_pw = str(input("enter your password: ")) # 다양한 입력을 시도하고 어떤 일이 발생하는지 확인하십시오!
        
        if(pw == in_pw):                  # 실제 비밀번호
            print("Success! Welcome! fos online!")
            break                               # break는 루프를 빠져나갈 때 사용합니다.
        else:
            LoginFailCheck(countdown)
    else:
        LoginFailCheck(countdown)
    
    countdown -= 1 # 실행할 때마다 카운트다운 수를 1씩 감소합니다.
enter your id: mas

5 Login attemps remaining!
enter your id: master
enter your password: fsdjkaflsdjflkfl

4 Login attemps remaining!
enter your id: free1234

3 Login attemps remaining!
enter your id: master
enter your password: free1234
Success! Welcome! fos online!

화씨 » 섭씨 변환

print(str((lambda c : (c * 1.8) + 32)(int(input("변환할 섭씨 온도(num only, C) : ")))) + " f")
변환할 섭씨 온도(num only, C) : 10
50.0 f

섭씨 » 화씨 변환

print(str(round((lambda f : (f - 32) / 1.8)(int(input("변환할 화씨 온도(num only, F) : "))), 2)) + " c")
변환할 화씨 온도(num only, F) : 20
-6.67 c
솔직.. 위처럼 쓸 수 있긴한데.. 역시 보기가 어렵…;;

숫자입력 계산하는 간단 프로그램

# 필요한 경우 변경 또는 기능 추가

import re

# myCalculator는 사용자 입력(Your Keyboard)에서 전달된 인수(inputString)를 사용합니다.
# 예제 입력은 '1+2' 또는 '3-2' 등의 형식입니다.


def myCalculator(inputString):
  # inputString에서 숫자와 연산자 추출

    #++++++코드를 작성해 주세요!-------
    #Hint: 슬라이싱을 사용하여 숫자와 연산자를 얻으세요! 그런 다음 유형 변환을 사용하여 숫자와 문자를 얻습니다!
    nums = re.findall(r'\d+', inputString)
    operator = re.findall(r'[\+\-\*\/]', inputString)
    
#    inputString = (3 < len(inputString)) ?  : 
    
    if( 0 < len(operator) and 2 <= len(nums) ):
        num1 = nums[0]
        num2 = nums[1]
        
         # 이 예제의 함수 인수는 위의 입력 문자열을 나누어서 하여 파생되어야 합니다!! 
        printCalculation(num1,operator[0],num2)   # 이것은 어떤 값이 함수에 들어가는지 보여주는 예입니다! printCalculation(1,'+',2)
    else:
        print("wrong input.;;")

# printCalculation은 문자열의 첫 번째 숫자, 연산자, 두 번째 숫자의 인수를 취합니다.
def printCalculation(num1, operator, num2):
    ans = 0
    if(operator == '+'): # elif로 다른 연산자를 추가하십시오!
        ans = int(num1) + int(num2)
    elif( '-' == operator ):
        ans = int(num1) - int(num2)
    elif( '*' == operator ):
        ans = int(num1) * int(num2)
    elif( '/' == operator ):
        ans = int(num1) / int(num2)
    else:
        operator = 'E'
    
    if ( 'E' != operator ):
        print(num1,' ',operator, ' ', num2, ' = ', ans)
    else:
        print("Error!") # 이것은 입력을 올바르게 입력했는지 확인합니다!!
# 입력
inputString = input("EG.'1+2' ")

myCalculator(inputString)
EG.'1+2' 1004/10
1004   /   10  =  100.4

주의사항

본 포트폴리오는 인텔 AI 저작권에 따라 그대로 사용하기에 상업적으로 사용하기 어려움을 말씀드립니다.

댓글남기기