It is a program that displays a message with fortune (bad to Daikichi) when the program is executed.
python.qiita.rb
import random
fortunes = {
    1: 'Bad'
    2: 'Sueyoshi'
    3: 'Kokichi'
    4: 'Nakayoshi'
    5: 'Kichi'
    6: 'Daikichi'
}
#Omikuji number(1~6)Randomly determined
number = random.randint(1.6)
#Get the fortune corresponding to the number from the dictionary fortunes
fortune = fortunes[number]
#Create a read file name
file_name = 'input/fortune_' + str(number) + '.txt'
#Read the file and get it as a random one-line message
with open(file_name.encoding='utf-8') as f:
    messages = f.readline()
    message 0 random.choice(messages)
print('Your fortune...')
#Show fortune
print(fortune)
#Show message
print(message)
Recommended Posts