Python 練習實例31

python 練習實例31

python 編程100例python 編程100例

題目:請輸入星期幾的第一個字母來判斷一下是星期幾,如果第一個字母一樣,則繼續(xù)判斷第二個字母。

程序分析:用情況語句比較好,如果第一個字母一樣,則判斷用情況語句或if語句判斷第二個字母。。

程序源代碼:

實例(python2.x):

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
letter = raw_input("please input:")
#while letter  != 'y':
if letter == 's':
    print ('please input second letter:')
    letter = raw_input("please input:")
    if letter == 'a':
        print ('saturday')
    elif letter  == 'u':
        print ('sunday')
    else:
        print ('data error')
    
elif letter == 'f':
    print ('friday')
    
elif letter == 'm':
    print ('monday')
    
elif letter == 't':
    print ('please input second letter')
    letter = raw_input("please input:")
 
    if letter  == 'u':
        print ('tuesday')
    elif letter  == 'h':
        print ('thursday')
    else:
        print ('data error')
        
elif letter == 'w':
    print ('wednesday')
else:
    print ('data error')

實例(python3.x):

#!/usr/bin/python3
 
letter = input("please input:")
#while letter  != 'y':
if letter == 's':
    print ('please input second letter:')
    letter = input("please input:")
    if letter == 'a':
        print ('saturday')
    elif letter  == 'u':
        print ('sunday')
    else:
        print ('data error')
    
elif letter == 'f':
    print ('friday')
    
elif letter == 'm':
    print ('monday')
    
elif letter == 't':
    print ('please input second letter')
    letter = input("please input:")
 
    if letter  == 'u':
        print ('tuesday')
    elif letter  == 'h':
        print ('thursday')
    else:
        print ('data error')
        
elif letter == 'w':
    print ('wednesday')
else:
    print ('data error')

以上實例輸出結(jié)果為:

please input:s
please input second letter:
please input:a
saturday

python 編程100例python 編程100例

下一節(jié):python 練習實例32

python 編程100例

相關(guān)文章
亚洲国产精品第一区二区,久久免费视频77,99V久久综合狠狠综合久久,国产免费久久九九免费视频