0
0

曜日の判定 Python3編

Posted at

X = int(input())

if X % 7 == 1:
    print('Sun')
elif X % 7 == 2:
    print('Mon')
elif X % 7 == 3:
    print('Tue')
elif X % 7 == 4:
    print('Wed')
elif X % 7 == 5:
    print('Thu')
elif X % 7 == 6:
    print('Fri')
elif X % 7 == 0:
    print('Sat')

たしか、もっと簡単にできたはず。。。
ヒントは配列


x = int(input())
week = ["Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"]

print(week[x % 7])

きれいだなぁ。。。
はじめからやっておけば(汗)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0