터틀 input 입력함수, write 사용
- Programming/Python
- · 2024. 1. 10.
import os command = input("명령을 입력하시오: ") if command == "shutdown": print("컴퓨터가 곧 종료됩니다. 엔터키를 누르세요") input() os.system("shutdown /s /t 1") elif command == "cwd": cwd = os.getcwd() print("Current working directory: ",cwd) else: print("알수없는 명령어입니다.") >> 명령을 입력하시오: cwd >> Current working directory: C:\Users\Admin\Desktop\ddah
x and y 둘 다 모두 참(True)이어야 참(True)이다. True and True >> True True and False >> False False and True >> False False and False >> False x or y 둘 중 하나만 참이면 참이다. True or True >> True True or False >> True False or True >> True False or False >> False not x x가 거짓이면 참이다. not True >> False not False >> True ex) not 1 is 1.o # False의 not -> True >> True 1 == 1.0 >> True 1 is 1.0 >> False 주의사항 True 와 t..
1. 조건문 한 눈에 보기 2. if문 명칭 if 조건식 : 행동 -> 조건식이 참일 때 실행. "then절" 이라고 함 행동 행동 -->> 행동이 2개 이상일 경우 "블럭"이라고 함 else: (그렇지 않으면) 행동 -> if 조건식이 참이 아닐 때 실행, "else절" 이라고 함. -->> else절은 "블럭" 아님(1개여서) 3. if 이중중첩문 - if문 안에 또 다른 if문 if 조건식 : if 조건식: elif 조건식: else: else: 예시 마지막 실행에서는 "로그인 실패!" 라는 문구가 출력 x 📍 각 조건문의 들여쓰기를 맞춰야 해당 조건문이 거짓일 때 else문을 실행할 수 있다. 결국 안쪽 if문 다음에 else문을 넣어 야한다.
인덱스 시작 숫자는 무조건 0이다. 어떤 언어에서든지 문자열/ 리스트의 인덱스는 0부터 시작한다. 0으로 시작하기때문에 거꾸로 마이너스(-)부터 시작할 때는 -1이 가장 마지막 인덱스로 간다. 변수 이름 [시작: 끝 +1] 주의할 점: 내가 나는 인덱스 7까지만 이용 할려고 할 때 +1 해서 8로 지정해야 한다. 마찬가지로 -일때도 hon이라는 문자열을 출력하려면 s[-3:0]이 되어야 한다.
정답 print("안녕하세요?") name = input("이름이 어떻게 되시나요?") print(f"만나서 반갑습니다. {name}씨") print(f"이름의 길이는 {len(name)}입니다.") age= int(input("나이가 어떻게 되시나요? ")) print(f"내년이면 {age+1}이 되시는군요")