Language/Python

두근두근 파이썬 CH5 연습문제

Return 2021. 6. 22. 19:28
import random

x=random.randint(1,100)     #1~100까지 랜덤 
y=random.randint(1,100)
print("{} - {} = ".format(x,y))
answer = int(input("당신의 답은 ?"))

if answer == x-y:           #정당,오답의 조건 
    print("맞았습니다.")

else:
    print("틀렷습니다.")

1번.

age =20

if age<20:
    print("20살 미만 ")
else:
    print("20살 이상 ")

##프로그램 출력 : 20살 이상

2번.

if age>=30 and age <=50:
    #30이상 , 50이하인 조건문을 추가해야된다. 

3번.

temper = int(input("현재 온도를 입력하시오 :"))  # 현재온도를 int 로 받아온다.

if temper >= 25:    #현재 온도의 대한 조건 
    print("반바지를 입으세요")
else:
    print("긴바지를 세요")

4번.

record = int(input("성적을 입력하시오 :"))  #record를 int로 받아온다. 

if record >= 90:             #성적에 대한 점수의 조건들 
    print("A학점 입니다. ")

elif record>=80 and record <90:
    print("B학점 입니다.")
elif record >=70 and record<80:
    print("C학점입니다.")
elif record>=60 and record <70:
    print("D학점입니다.")
else:
    print("F학점입니다.")

5번.

import random

x=random.randint(1,100)     #1~100까지 랜덤 
y=random.randint(1,100)
print("{} - {} = ".format(x,y))
answer = int(input("당신의 답은 ?"))

if answer == x-y:           #정당,오답의 조건 
    print("맞았습니다.")

else:
    print("틀렷습니다.")

6번.

"x = int(input("점수를 입력하세요"))  #점수를 int로 받아온다.

if x%2 == 0 and x%3 == 0 :       # and를 써서 2,3모두 나누어 떨어지는지 확인한다.
    print("2와 3으로 나누어 떨어집니다.")
else:
    print("2와 3으로 나누어 떨어지지 않습니다.")

7번.

import random
lotto = random.randint(1,100)     #lotto를 랜덤함수를 이용해 만든다.

num = int(input("복권번호를 입력해주세요 :")) #복권번호를 입력 받는다.
print("당첨번호는",lotto)# lotto값을 알려준다.(결과)


digit1 = lotto // 10  #lotto의 첫째자리값
digit2 = lotto % 10  #lotto의 둘째자리값

number1 = num // 10   #num의 첫째자리값
number2 = num % 10    #num의 둘째자리값

if lotto == num :      #lotto값과 num값이 같을때 (상금 100만원일때)
     print("상금 100만원")
elif digit1 == number1 or digit1 == number2 or digit2 == number1 or digit2== number2:
     print("상금 50만원")   #첫째자리,둘째자리값중 하나라도 같을때
else:   #그외
    print("no 상금")

8번.

import turtle as t    #import turtle 한다.

x1 = int(input("큰 원의 중심좌표 x1:"))  #중심좌표 받아온다.
y1 = int(input("큰 원의 중심좌표 y1:"))
r1 = int(input("큰 원의 반지름  r1:"))
x2 = int(input("작은원의 중심좌표 x2:"))  #중심좌표 받아온다.
y2 = int(input("작은원의 중심좌표 y2:"))
r2 = int(input("작은원의 반지름 r2:"))

t.shape("turtle")
t.up()
t.goto(x1,y1-r1)   #circle함수의 특성상 현재 위치에서 원을 그리므로 중심좌표가 x1,y1이라면 좌표(x1,y1-r1)으로 이동해야된다.
t.down()
t.circle(r1) 

t.up()
t.goto(x2,y2-r2) #circle함수의 특성상 현재 위치에서 원을 그리므로 중심좌표가 x2,y2이라면 좌표(x2,y2-r2)으로 이동해야된다.
t.down()
t.circle(r2)


d = ((x1-x2)**2 +(y1-y2)**2)**0.5 #중심좌표사이의 거리

if r1 - r2 > d: #원이 내부에 있을 조건
    t.write("원의 내부에 있습니다" ,False , "left" , ("",15,"")  )
else: #원이 외부에 있을조건
    t.write("원의 외부에 있습니다" ,False , "left" , ("",15,"")  )


t.exitonclick()  #파이참에서 터틀런화면을 꺼지지 않게한다.