python3 100例 一码人学习笔记(81

发布时间:2024-11-22 00:42

将笔记与实际案例相结合 #生活技巧# #学习技巧# #笔记方法#

题目81:809*??=800*??+9*?? 其中??代表的两位数, 809*??为四位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*?? 

a = 809

for i in range(10,100):

b = i * a

if b >= 1000 and b <= 10000 and 8 * i < 100 and 9 * i >= 100:

print(b,' = 800 * ', i, ' + 9 * ', i)

9708 = 800 * 12 + 9 * 12

Press any key to continue . . .

 题目82:八进制转换为十进制

if __name__ == '__main__':

n = 0

p = input('input a octal number:\n')

for i in range(len(p)):

n = n * 8 + ord(p[i]) - ord('0')

print(n)

input a octal number:

18

16

Press any key to continue . . .

题目83:求0—7所能组成的奇数个数。

程序分析:

组成1位数是4个。

组成2位数是7*4个。

组成3位数是7*8*4个。

组成4位数是7*8*8*4个。

def f(n):

if n == 0:

return 1

elif n == 1:

return 7

else:

return f(n-1)*8

l = []

for i in range(1,9):

l.append(f(i-1)*4)

print(l)

print(sum(l))

[4, 28, 224, 1792, 14336, 114688, 917504, 7340032]

8388608

Press any key to continue . . .

题目84:连接字符串

delimiter = ','

mylist = ['Brazil', 'Russia', 'India', 'China']

print(delimiter.join(mylist))

Brazil,Russia,India,China

Press any key to continue . . .

题目85:输入一个奇数,然后判断最少几个 9 除于该数的结果为整数。

def monkey():

a=int(input('输入一个数字:\n'))

b=9

i=1

while True:

if b > a and b%a==0:

print('需要{}个9'.format(i))

break

else:

b = b*10+9

i+=1

if __name__ == '__main__':

monkey()

输入一个数字:

19

需要18个9

Press any key to continue . .

题目86:回答结果(结构体变量传递)

if __name__ == '__main__':

class student:

x = 0

c = 0

def f(stu):

stu.x = 20

stu.c = 'c'

a= student()

a.x = 3

a.c = 'a'

f(a)

print(a.x,a.c)

20 c

Press any key to continue . . .

题目87:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。

import random

num=[]

s=['*']

for i in range(0,3):

num.append(random.randint(1,10))

print(" * 个数为:",num[i])

print('*'*num[i])

*

****

*****

Press any key to continue . . .

题目88:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。

def func():

n = str(input("请输入四位整数"))

a = str((int(n[:1])+5)%10)

b = str((int(n[1:2])+5)%10)

c = str((int(n[2:3])+5)%10)

d = str((int(n[3:4])+5)%10)

number = d+c+b+a

print(number)

func()

请输入四位整数1234

9876

Press any key to continue . . .

题目89:列表使用实例。

testList=[10086,'中国移动',[1,2,4,5]]

print(len(testList))

print(testList[1:] )

testList.append('i\'m new here!')

print(len(testList))

print(testList[-1] )

print(testList.pop(1) )

print(len(testList) )

print(testList )

matrix = [[1, 2, 3],

[4, 5, 6],

[7, 8, 9]]

print(matrix)

print(matrix[1])

col2 = [row[1] for row in matrix]

print(col2 )

col2even = [row[1] for row in matrix if row[1] % 2 == 0]

print(col2even)

3

['中国移动', [1, 2, 4, 5]]

4

i'm new here!

中国移动

3

[10086, [1, 2, 4, 5], "i'm new here!"]

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

[4, 5, 6]

[2, 5, 8]

[2, 8]

Press any key to continue . . .

网址:python3 100例 一码人学习笔记(81 https://www.yuejiaxmz.com/news/view/182793

相关内容

机器学习day01——笔记
【读书笔记】代码大全26章:代码优化技术
100种学习的方法,行动起来!
python 学习笔记24 图片视频修复
提高学习效率——5R笔记法
做笔记=抄书?你还是不会学习!这样做笔记才能高效
一款Python实用神器,5 行 Python 代码 实现一键批量扣图
笔记本、数码相机、MP3等数码产品的养护常识
100个提高学习效率的方法!学习迷茫时看看
肠型分析学习笔记

随便看看