第1週目の作業(rayco)
7189 ワード
rayco第1週作業
1回目-授業後の練習問題
2回目-文字列練習問題
一、文字列変数の定義
1.3つの文字列a,b,cの値をそれぞれI,like,pythonと定義してください.
2.上の3つの変数を結合して出力してください'I like python'
二、変数s='sdghHhf'を定義する
1.変数sの空白文字を削除して新しい変数s 1に出力を印刷してください
2.それぞれs 1をすべて大文字(s 2と命名)、小文字(s 3と命名)、印刷出力s 2,s 3に変更してください
3.s 1でhが最初に現れる位置を探してs 4印刷出力に値を割り当ててください
三、変数x='I{}pyhonを定義する
xの文字列{}をlikeに変更し、2つの変数x 1,x 2の印刷出力にそれぞれ値を付けてください.
四、変数capital='人民元100万元を定義する.
1.capitalの長さを印刷してください
2.capitalが数字かどうかpython言語で判断してください
第3回リスト、メタグループ、集合練習問題
一、定義リスト:list 1=['life','is','short'],
list2 = ['you','need','python']
次の要件を満たします.
1)pythonとその下付き文字を出力する
2)list 2後に'!','short'の後に'を追加します.'
3)2つの文字列を結合した後、並べ替えて出力する
4)'python'を'python 3'に変更
4)前に追加した'!'を削除します.と','
二、自分でタプルを定義し、よく使う方法を練習する(タプルの長さを出力し、位置要素を指定するなど)
三、定義リスト:
list1 = ['life','is','short'],
list2 = ['you','need','python']
list3 = [1,2,3,4,5,3,4,2,1,5,7,9]
次の操作を行います.
1)構築集合リスト_set1
2)リストt 1とリストt 2を結合して集合リストを構築する.set2
3)2つのセットの長さを出力する
4)2つのコレクションをマージして「python」を除去する
5)集計後の新しいリストに「python 3」を追加
第4回辞書jsonタイプ練習問題
1.jsonモジュールのインポート
2.空の辞書dict_を定義するa,空の辞書dict_b
3.dict_へa 3 key a 1,a 2,a 3のそれぞれに対応する値をb 1,b 2,b 3とする
4.dict_を取得aすべてのkey、命名変数ks、印刷出力ksおよびksのデータ型
5.dict_を印刷aすべてのvalue命名変数vs,印刷出力vsおよびvsのデータ型
6.実行コードprint(dict_a.items()観察出力結果
7.a 1とa 3の対応する値を入れ替える
8.印刷出力dict_a
9.ディクショナリdict_を削除aにおけるa 1に対応する値
10.印刷出力dict_a
11.このときのdict_をaデータをdict_に更新b
12.dict_の印刷b a 1およびa 4がdict_にあるかどうかを観察するb中
13.a 1が存在しない場合dict_bに、以下のコードa 1=dict_を入力するb.get('a 1')変数a 1を印刷
14.13題変数a 1をdict_に追加bにおいてkeyは'a 1'である
15.a 4 dict_が存在しない場合bでは、a 4に対応する値をデフォルトで「null」としてdict_に追加するbにおいてkeyは'a 4'である
16.dict_を印刷するb及びそのデータ型
17.dict_b jsonタイプに変換変数json_と命名c
18.json_の印刷cとそのデータ型観察16題印刷結果と18題結果が異なる点を示す
19.json_c辞書タイプに変換dict_と命名c印刷出力dict_c及びそのデータ型
5.第5回文字列分割、インデックスとスライス練習問題
1.索引を理解するこれは後でよく使われる
2.str 1='などの文字列の定義http://www.jianshu.com/u/a987b338c373'文字列の内容は自分のトップページ接続であり、自分のid(u/その後の内容--a 987 b 338 c 373)を出力する.
3.s=「abcdefg」とすると、以下の値は
s[3] s[2:4]
s[:5] s[3:]
s[::-1] s[::2]
d cd abcde defg gfedcba aceg
4.定義リスト:list 1=[1,2,3,4,5,6,7]の場合、以下の値は
list1[3] list1[2:4]
list1[:5] list1[3:]
list1[::-1] list1[::2]
5.メタグループの定義:touple 1=(1,2,3,4,5,6,7)の場合、次の値は
touple1[3] touple1[2:4]
touple1[:5] touple1[3:]
touple1[::-1] touple1[::2]
6.これまで学習した集中的な基本タイプとその方法を復習し、インデックスとスライスを理解することに重点を置く
6.第六回論理演算練習問題
次の式の論理演算の結果は?(できるだけ直接的に解答を考え、コードで結果をテストすることができます)
True
False
False
True
True
True
False
True
False
False
True
False
True
False
Trueが間違ってる
False
True
True
False
1回目-授業後の練習問題
a = 10
b = 3
c = a/b-a
print(c, type(c))
c = a/b*a
print(c, type(c))
c = 0.1*a//b-a
print(c, type(c))
c = a//b+a%b
print(c, type(c))
2回目-文字列練習問題
一、文字列変数の定義
1.3つの文字列a,b,cの値をそれぞれI,like,pythonと定義してください.
2.上の3つの変数を結合して出力してください'I like python'
a = 'I'
b = 'like'
c = 'python'
d = a+' '+b+' '+c
print(d)
二、変数s='sdghHhf'を定義する
1.変数sの空白文字を削除して新しい変数s 1に出力を印刷してください
2.それぞれs 1をすべて大文字(s 2と命名)、小文字(s 3と命名)、印刷出力s 2,s 3に変更してください
3.s 1でhが最初に現れる位置を探してs 4印刷出力に値を割り当ててください
s = ' sdghHhf '
s1 = str.strip(s)
print('s1=', s1)
s2 = str.upper(s1)
s3 = str.lower(s1)
print('s2=', s2)
print('s3=', s3)
s4 = s1.find('h')
print('s4=', s4)
三、変数x='I{}pyhonを定義する
xの文字列{}をlikeに変更し、2つの変数x 1,x 2の印刷出力にそれぞれ値を付けてください.
x = 'I {} pyhon'
x1 = x.replace('{}', 'like')
x2 = x.format('like')
print(x1)
print(x2)
四、変数capital='人民元100万元を定義する.
1.capitalの長さを印刷してください
2.capitalが数字かどうかpython言語で判断してください
capital = ' 100 '
print(len(capital))
print(capital.isdigit())
第3回リスト、メタグループ、集合練習問題
一、定義リスト:list 1=['life','is','short'],
list2 = ['you','need','python']
次の要件を満たします.
1)pythonとその下付き文字を出力する
2)list 2後に'!','short'の後に'を追加します.'
3)2つの文字列を結合した後、並べ替えて出力する
4)'python'を'python 3'に変更
4)前に追加した'!'を削除します.と','
list1 = ['life', 'is', 'short']
list2 = ['you', 'need', 'python']
print(list2[2],list2.index('python'))
list2.append('!')
list1.append(',')
list3 = list1 + list2
list3.sort()
print(list3, len(list3))
list3[list3.index('python')]=('python3')
list3.remove('!')
list3.remove(',')
二、自分でタプルを定義し、よく使う方法を練習する(タプルの長さを出力し、位置要素を指定するなど)
tuple1 = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June')
print(len(tuple1))
print(tuple1[5])
三、定義リスト:
list1 = ['life','is','short'],
list2 = ['you','need','python']
list3 = [1,2,3,4,5,3,4,2,1,5,7,9]
次の操作を行います.
1)構築集合リスト_set1
2)リストt 1とリストt 2を結合して集合リストを構築する.set2
3)2つのセットの長さを出力する
4)2つのコレクションをマージして「python」を除去する
5)集計後の新しいリストに「python 3」を追加
list1 = ['life', 'is', 'short']
list2 = ['you', 'need', 'python']
list3 = [1, 2, 3, 4, 5, 3, 4, 2, 1, 5, 7, 9]
list_set1 = set(list1)
list_set2 = set(list1 + list2)
print(len(list_set1), len(list_set2))
list_set1.update(list_set2)
list_set1.remove('python')
list_set1.add('python3')
第4回辞書jsonタイプ練習問題
1.jsonモジュールのインポート
import json
2.空の辞書dict_を定義するa,空の辞書dict_b
dict_a = {}
dict_b = {}
3.dict_へa 3 key a 1,a 2,a 3のそれぞれに対応する値をb 1,b 2,b 3とする
dict_a = {'a1': 'b1', 'a2': 'b2', 'a3': 'b3'}
4.dict_を取得aすべてのkey、命名変数ks、印刷出力ksおよびksのデータ型
ks = dict_a.keys()
print(ks, type(ks))
5.dict_を印刷aすべてのvalue命名変数vs,印刷出力vsおよびvsのデータ型
vs = dict_a.values()
print(vs, type(vs))
6.実行コードprint(dict_a.items()観察出力結果
print(dict_a.items())
7.a 1とa 3の対応する値を入れ替える
dict_a['a1'] = 'b3'
dict_b['a3'] = 'b1'
8.印刷出力dict_a
print(dict_a)
9.ディクショナリdict_を削除aにおけるa 1に対応する値
dict_a.pop('a1')
10.印刷出力dict_a
print(dict_a)
11.このときのdict_をaデータをdict_に更新b
dict_b.update(dict_a)
12.dict_の印刷b a 1およびa 4がdict_にあるかどうかを観察するb中
print(dict_b)
13.a 1が存在しない場合dict_bに、以下のコードa 1=dict_を入力するb.get('a 1')変数a 1を印刷
a1 = dict_b.get('a1')
print(a1)
14.13題変数a 1をdict_に追加bにおいてkeyは'a 1'である
dict_b['a1'] = a1
15.a 4 dict_が存在しない場合bでは、a 4に対応する値をデフォルトで「null」としてdict_に追加するbにおいてkeyは'a 4'である
a4 = 'null'
dict_b['a4'] = a4
16.dict_を印刷するb及びそのデータ型
print(dict_b, type(dict_b))
17.dict_b jsonタイプに変換変数json_と命名c
json_c = json.dumps(dict_b)
18.json_の印刷cとそのデータ型観察16題印刷結果と18題結果が異なる点を示す
print(json_c, type(json_c))
19.json_c辞書タイプに変換dict_と命名c印刷出力dict_c及びそのデータ型
dict_c = json.loads(json_c)
print(dict_c, type(dict_c))
5.第5回文字列分割、インデックスとスライス練習問題
1.索引を理解するこれは後でよく使われる
2.str 1='などの文字列の定義http://www.jianshu.com/u/a987b338c373'文字列の内容は自分のトップページ接続であり、自分のid(u/その後の内容--a 987 b 338 c 373)を出力する.
str1 = 'http://www.jianshu.com/u/d8d31a69dcf8'
print(str1[str1.find('u/')+2:])
3.s=「abcdefg」とすると、以下の値は
s[3] s[2:4]
s[:5] s[3:]
s[::-1] s[::2]
s = 'abcdefg'
print(s[3], s[2:4], s[:5], s[3:], s[::-1], s[::2])
d cd abcde defg gfedcba aceg
4.定義リスト:list 1=[1,2,3,4,5,6,7]の場合、以下の値は
list1[3] list1[2:4]
list1[:5] list1[3:]
list1[::-1] list1[::2]
list1 = [1, 2, 3, 4, 5, 6, 7]
print(list1[3], list1[2:4], list1[:5], list1[3:], list1[::-1], list1[::2])
5.メタグループの定義:touple 1=(1,2,3,4,5,6,7)の場合、次の値は
touple1[3] touple1[2:4]
touple1[:5] touple1[3:]
touple1[::-1] touple1[::2]
touple1 = (1, 2, 3, 4, 5, 6, 7)
print(touple1[3], touple1[2:4], touple1[:5], touple1[3:], touple1[::-1], touple1[::2])
6.これまで学習した集中的な基本タイプとその方法を復習し、インデックスとスライスを理解することに重点を置く
6.第六回論理演算練習問題
次の式の論理演算の結果は?(できるだけ直接的に解答を考え、コードで結果をテストすることができます)
print(True and True)
True
print(False and True)
False
print(1 == 1 and 2 == 1)
False
print("test" == "test")
True
print(1 == 1 or 2 != 1)
True
print(True and 1 == 1)
True
print(False and 0 != 0)
False
print(True or 1 == 1)
True
print("test" == "testing")
False
print(1 != 0 and 2 == 1)
False
print("test" != "testing")
True
print("test" == 1)
False
print(not (True and False))
True
print(not (1 == 1 and 0 != 1))
False
print(not (10 == 1 or 1000 == 1000))
Trueが間違ってる
print(not (1 != 10 or 3 == 4))
False
print(not ("testing" == "testing" and "Zed" == "Cool Guy"))
True
print(1 == 1 and not ("testing" == 1 or 1 == 0))
True
print(3 == 3 and not ("testing" == "testing" or "Python" == "Fun"))
False