코드업 기초2. 입출력문 및 연산자 (3)

Tino-Kim·2022년 1월 19일
0
post-thumbnail

🥴 코드업 기초2. 입출력문 및 연산자 (3)

📌 조건에 맞는 숫자 출력하기.

  1. 함수를 이용하기.
A1.
a,b=map(int, input().split())
def compare(a,b):
    if a>=b:
        return 1
    else:
        return 0
  1. 조건문을 이용하기.
A2.
a,b=map(int, input().split())
if a>=b:
    print(1)
else:
    print(0)

📌 0,1을 반대로 출력하기.

  1. not 연산자로 반대로 출력 > 정수로 변환하기.
A1.
n=int(input())
print(int(not n))
  1. 함수를 이용하기.
A2.
n=int(input())
def compare(n):
    if n==0:
        return 1
    else:
        return 0
        
print(compare(n))

📌 비트 연산자

💛 Python Codeup 문제 풀이 참고한 블로그

  1. and 연산자
from sys import stdin
num1, num2=map(int, input().split())
print(num1&num2)
  1. or 연산자
from sys import stdin
num1, num2=map(int, input().split())
print(num1|num2)
  1. << 연산자
from sys import stdin
num1, num2=map(int, input().split())
print(num1<<num2)
  1. >> 연산자
from sys import stdin
num1, num2=map(int, input().split())
print(num1>>num2)

📌 세 숫자 중에서 가장 작은 수 구하기.

천천히 생각하면 된다. 두 정수 먼저 비교하고, 나머지 정수와 한번 더 비교하기~!

a,b,c=map(int, input().split())
def compare(a,b,c):
    if a>b:
        if b>c:
            return c
        else:
            return b
    else:
        if a>c:
            return c
        else:
            return a
            
print(compare(a,b,c))

💛 2022. 01. 19. 수요일.

😡 sys.stdin.readline()...

💛 Python 파이썬 입력 받기 sys.stdin.readline

import sys
T=int(input())
for ii in range(T):
    a,b=map(int, sys.stdin.readline().split())
    print(a,b)

Stack Overflow ValueError: invalid literal for int() with base 10

import sys
T=int(float(input()))
for ii in range(T):
    a,b=map(int, sys.stdin.readline().split())
    print(a,b)

from sys import stdin
a,b=map(int, sys.stdin.readline().split())

Stack Overflow ValueError: not enough values to unpack (expected 2, got 0)

profile
알고리즘과 데이터 과학과 웹 개발을 공부하는 대학생

0개의 댓글