Last active
May 24, 2018 02:33
-
-
Save seven0525/aced70777fbb1fb3c087984f31b156d7 to your computer and use it in GitHub Desktop.
「自作Python100本ノック」3日目(11本〜15本目) ref: https://qiita.com/ahpjop/items/023cb561d7a2081ad606
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort_text(text): | |
text = open(text).read().split() | |
aws = text.sort() | |
print(aws) | |
sort_text("number.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_lite(text,target): | |
print(open(text).read().count(target)) | |
count_lite("python.txt","by") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = open("alpha.txt").read().split() | |
a.sort() | |
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(open("python.txt").read().count("by")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert(text): | |
if text[-1] == "C": | |
cel = int(text[:-1])#文字列の最後の文字を取り出す | |
aws = cel * (9/5) + 32 | |
elif text[-1] == "F": | |
fah = int(text[:-1])#文字列の最後以外の文字を取り出す | |
aws = (fah -32) / (9/5) | |
else: | |
aws = "正しく入力してください" | |
return aws | |
convert("45C") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten(ls): | |
r = [] | |
for i in ls: | |
if type(i) is list: | |
r.extend(flatten(i))#appendではない。 | |
else: | |
r.append(i) | |
return r | |
lis_a = [[1,2],3,4,5,[6,[7,[8,9]]]] | |
print(flatten(lis_a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("現在の時刻を「18:45」のように入力してください") | |
current_time = input(">>") | |
print("定時を「17:00」のように入力してください") | |
out_time = input(">>") | |
print("1時間あたりの残業代(円)を「1500」のように入力してください") | |
hour_money = float(input(">>")) | |
current_h = float(current_time[0:2]) | |
current_m = float(current_time[3:5]) | |
current_time_min = (60 * current_h) + current_m #分単位に統一 | |
out_h = float(out_time[0:2]) | |
out_m = float(out_time[3:5]) | |
out_time_min = 60 * out_h + out_m | |
leave_time_min = current_time_min - out_time_min | |
leave_time_h = round((leave_time_min/60),2) | |
cal_money = leave_time_h * hour_money | |
print("あなたの残業時間は{0}時間です。残業代金は{1}円になります。".format(leave_time_h,cal_money)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment