日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python考试编程题

發布時間:2023/11/27 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python考试编程题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

3.

a:
while True:
??? s = raw_input('變量名為:')
??? if s == 'exit':
??????? print '退出'
??????? break
??? #判斷是否由字母或下劃線組成
??? if s[0].isalpha() or s[0] == '_':
??????? for i in s[1:]:
??????????? if not (i.isalnum() or i == '_'):
??????????????? print '%s變量名不合法 ' % s
??????????????? break
??????? else:
??????????? print '%s 變量名合法' % s
??? else:
??????? print '%s變量名不合法' % s

b:
count = 0
for i in range(1, 100):
??? if i % 2 == 0:
??????? count -= i
??? else:
??????? count += i
print count

?

c:
num = range(1, 13)
i = 1
while i < 13:
??? if (i == 6 or i == 10):
??????? print ' ',
??? else:
??????? print i,
??? i += 1

h:

li = ['frdgrfgdsHHJJ', 'cdfregHHHJDGF']
new_li = []
for i in li:
??? new_li.append(i.lower())

print(new_li)

7.

li=['happy','lucky','linux']
print len(li)
li.append('seven')
print li
li.insert(0,'Tony')
print li
li[1]='Kelly'
print li
print li.pop(1)
print li
li.pop(2)
print li
print li[::-1]
print li

8.

dic = {'k1': 'v1', 'k2': 'v2', 'k3': [11, 22, 33]}

# 1.

for i in dic:
???? print(i)

# 2.
?for v in dic.values():
???? print(v)

?# 3.
?for k in dic:
??? print(k, dic[k])



?# 4.
?dic['k1'] = 'harry'
?print(dic)

?# 5.
?dic['k3'].append('44')
?print(dic)

# 6.
dic['k3'].insert(0, 18)
print(dic)

9.

s = raw_input('請輸入英文句子:')
s_new = s.split()

dict = {}

for item in s_new:
??? if item not in dict:
??????? dict[item] = 1
??? else:
??????? dict[item] += 1
print dict

10.

def fun(set):
??? bigger = []
??? smaller = []
??? for i in set:
??????? if i < 66:
??????????? smaller.append(i)
??????? else:
??????????? bigger.append(i)
??? dic = {'k2': smaller, 'k1': bigger, 'k2': smaller}
??? print(dic)


list = [11, 22, 33, 44, 55, 66, 77, 88, 99, 90]
fun(list)

12.

i=1
while i<=9:
??? j=1
??? while j<=i:
??????? print '%d*%d=%d\t'%(i,j,i*j),
??????? j+=1
??? print ''
??? i+=1

13.


num1 = int(raw_input('請輸入第一個數:'))
num2 = int(raw_input('請輸入第二個數:'))
min_num = min(num1, num2)
for i in range(1, min_num + 1):
??? if num1 % i == 0 and num2 % i == 0:
??????? biger_count = i
smaller_count = (num1 * num2) / biger_count

print '最大公約數為:%d' % biger_count
print '最小公倍數為:%d' % smaller_count

21.

class People(object):
??? __name = 'luffy'
??? __age = 18


pl = People()
print(pl.__name, pl.__name)

# 出現報錯,因為私有屬性不允許直接訪問

22.

class Parent(object):
??? x = 1


class Child1(Parent):
??? pass


class Child2(Parent):
??? pass


print(Parent.x, Child1.x, Child2.x)
Child1.x = 2
print(Parent.x, Child1.x, Child2.x)
Parent.x = 3
print(Parent.x, Child1.x, Child2.x)

23.


class Person(object):
??? def __init__(self, name):
??????? self.name = name

??? def buy_car(self, car):
??????? print '%s 寶馬BMW 4s店買%s' % (self.name, car)


joker = Person('joker')
joker.buy_car('BMW X7')

?

class B:
??? def handle(self):
??????? print '喵喵'


class A(B):
??? def handle(self):
??????? B.handle(self)


new = A()
new.handle()

25.


class Student(object):
??? count = 0

??? def __init__(self, name, age):
??????? self.name = name
??????? self.age = age
??????? Student.count += 1

??? @staticmethod
??? def count_student():
??????? print '共實例%d個對象' % Student.count


bob = Student('bob', 19)
Jenny = Student('Jenny', 18)
Danny = Student('Danny', 19)
liming = Student('liming', 20)

Student.count_student()

26.


class Student(object):
??? count = 0

??? def __init__(self, name, age):
??????? self.name = name
??????? self.age = age
??????? Student.count += 1

??? @staticmethod
??? def count_student():
??????? print '共實例%d個對象' % Student.count


bob = Student('bob', 19)
Jenny = Student('Jenny', 18)
Danny = Student('Danny', 19)
liming = Student('liming', 20)

Student.count_student()

?

?

總結

以上是生活随笔為你收集整理的python考试编程题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:python考试编程题