2011년 11월 9일 수요일

08 할인 가격 표시 하기

print('종료하려면 숫자 1을 입력하세요.')

n = 1

while p != n :

    p = int(input('가격 : '))

    if 20000 > p >= 10000 :

        print('10% 할인합니다!')

        f = int(p - (p * 0.1))

        print('할인 가격 : ', f, '\n')

    elif p >= 20000 :

        print('20% 할인합니다!')

        f = int(p - (p * 0.2))

        print('할인 가격 : ', f, '\n')

    elif 10000 > p >= 2 :

        print('할인 품목이 아닙니다!')

        print('가격 : ', p, '\n')

p = 0

print('이용해 주셔서 감사합니다~')




>>>

종료하려면 숫자 1을 입력하세요.

가격 : 2

할인 품목이 아닙니다!

가격 :  2



가격 : 9000

할인 품목이 아닙니다!

가격 :  9000



가격 : 90000

20% 할인합니다!

할인 가격 :  72000



가격 : 1

이용해 주셔서 감사합니다~


이 글은 스프링노트에서 작성되었습니다.

07 알파벳 맞추기

a = 'a'

print('종료하고 싶을 때 어떤 알파벳을 입력해야 할까요? 알아 맞추어 보세요.')

while a != 'q' and a != 'Q' :

    a = input('알파벳을 입력하세요 : ')

    if a == 'q' or a == 'Q' :

        print('맞추었습니다. 축하합니다!')

    else :

        print('다른 알파벳을 입력하세요!')

print('이만 종료합니다~')



>>>

종료하고 싶을 때 어떤 알파벳을 입력해야 할까요? 알아 맞추어 보세요.

알파벳을 입력하세요 : x

다른 알파벳을 입력하세요!

알파벳을 입력하세요 : Q

맞추었습니다. 축하합니다!

이만 종료합니다~

06 오늘의 영단어 5개 암기 하기

* 먼저 easygui를 설치하여야 합니다.


* 다음 프로그래밍은 파이썬 2.7에서 작성하였습니다.


 


import easygui



e = easygui.enterbox('영단어 : ')


k = easygui.enterbox('뜻 : ')

s = easygui.enterbox('예제 : ')



eks = e + '\n' + k + '\n' + s + '\n' + '\n'




easygui.msgbox(eks, '오늘의 영단어')




e1 = easygui.enterbox('영단어 : ')


k1 = easygui.enterbox('뜻 : ')

s1 = easygui.enterbox('예제 : ')



eks1 = e1 + '\n' + k1 + '\n' + s1 + '\n' + '\n'




easygui.msgbox(eks + eks1, '오늘의 영단어')




e2 = easygui.enterbox('영단어 : ')


k2 = easygui.enterbox('뜻 : ')

s2 = easygui.enterbox('예제 : ')



eks2 = e2 + '\n' + k2 + '\n' + s2 + '\n' + '\n'




easygui.msgbox(eks + eks1 + eks2, '오늘의 영단어')




e3 = easygui.enterbox('영단어 : ')


k3 = easygui.enterbox('뜻 : ')

s3 = easygui.enterbox('예제 : ')



eks3 = e3 + '\n' + k3 + '\n' + s3 + '\n' + '\n'




easygui.msgbox(eks + eks1 + eks2 + eks3, '오늘의 영단어')




e4 = easygui.enterbox('영단어 : ')


k4 = easygui.enterbox('뜻 : ')

s4 = easygui.enterbox('예제 : ')



eks4 = e4 + '\n' + k4 + '\n' + s4 + '\n' + '\n'




easygui.msgbox(eks + eks1 + eks2 + eks3 + eks4, '오늘의 영단어')


이 글은 스프링노트에서 작성되었습니다.

2011년 11월 8일 화요일

05 온도변환 윈도우 프로그래밍

* 먼저 easygui를 설치하여야 합니다.


* 다음 프로그래밍은 파이썬 2.7에서 작성하였습니다.




import easygui



easygui.msgbox("화씨를 섭씨로 변환하기")

f = float(easygui.enterbox("화씨 : "))

c = round(5.0/9*(f-32),1)

easygui.msgbox("섭씨 : " + str(c))


이 글은 스프링노트에서 작성되었습니다.

2011년 11월 7일 월요일

04 간단한 메모장 만들기

addline = input('wirte(if you exit, type x) : ')



def write() :

    fid = open('log1.txt', 'a')

    print(addline, file=fid)

    fid.close()

    fidr = open('log1.txt', 'r')

    line = fidr.readlines()

    print(line)

    fidr.close()

   

while addline != 'x' :   

    if addline != 'x' :

        write()

        addline = input('wirte(if you exit, type x) : ')



print('Good Job!')


>>>

wirte(if you exit, type x) : legitimate

['legitimate\n']

wirte(if you exit, type x) : 합법적인

['legitimate\n', '합법적인\n']

wirte(if you exit, type x) : x

Good Job!





  • 메모 후 파일을 닫을 때 자동으로 기록 날짜를 적으려면 다음과 같이 합니다.


import datetime



addline = input('wirte(if you exit, type x) : ')



def write() :

    fid = open('log1.txt', 'a')

    print(addline, file=fid)

    fid.close()

    fidr = open('log1.txt', 'r')

    line = fidr.readlines()

    print(line)

    fidr.close()



def x() :

    fid = open('log1.txt', 'a')

    when = datetime.datetime.now()

    print(when, file=fid)

    print('Good Job!!')

    fid.close()

   

while addline != 'x' :   

    if addline != 'x' :

        write()

        addline = input('wirte(if you exit, type x) : ')



x()


>>>

wirte(if you exit, type x) : instance

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n']

wirte(if you exit, type x) : 실례

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n']

wirte(if you exit, type x) : such an instance to exist

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n', 'such an instance to exist\n']

wirte(if you exit, type x) : x

Good Job!!

>>>

wirte(if you exit, type x) : imbue

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n', 'such an instance to exist\n', '2011-11-07 16:34:48.721262\n', 'imbue\n']

wirte(if you exit, type x) :


이 글은 스프링노트에서 작성되었습니다.

03 건물 평수 구하기

h = float(input("세로 길이(m) : "))

w = float(input("가로 길이(m) : "))

a = round(h * w,1)

print("평방미터 : ", a)

p = round(a * 0.302500011,1)

print("평 : ", p)




>>>

세로 길이(m) : 9.1

가로 길이(m) : 6.1

평방미터 :  55.5

평 :  16.8


이 글은 스프링노트에서 작성되었습니다.

자동차 운행 시간 구하기

d = input("Distance(km) : ")

d = int(d)

s = input("Speed(km per hour) : ")

s = int(s)

t = round(d/s,1)

print("Travel Time : ", t)




>>>

Distance(km) : 411

Speed(km per hour) : 80

Travel Time :  5.1


이 글은 스프링노트에서 작성되었습니다.