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

程序分析:999999 / 13 = 76923。

#!/usr/bin/python
#coding=utf-8 if __name__ == '__main__':
zi = int(input('输入一个数字:\n'))
n1 = 1
c9 = 1
m9 = 9
sum = 9
while n1 != 0:
if sum % zi == 0:
n1 = 0
else:
m9 *= 10
sum += m9
c9 += 1
print('%d个9可以被%d整除:%d' % (c9, zi, sum))
r = sum / zi
print('%d / %d = %d' % (sum, zi, r))

86、两个字符串连接程序。

#!/usr/bin/python
#coding=utf-8 if __name__ == '__main__':
a = 'Py'
b = 'thon'
c = a + b
print(c)

87、回答结果(结构体变量传递)。

#!/usr/bin/python
#coding=utf-8 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)

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

#!/usr/bin/python
#coding=utf-8 if __name__ == '__main__':
n = 1
while n <= 7:
a = int(input('Input a number:\n'))
while a < 1 or a > 50:
a = int(input('Input a number:\n'))
print(a * '*')
n += 1

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

#!/usr/bin/python
#coding=utf-8 from sys import stdout
if __name__ == '__main__':
a = int(input('输入四个数字:\n'))
aa = []
aa.append(int(a % 10))
aa.append(int(a % 100 / 10))
aa.append(int(a % 1000 / 100))
aa.append(int(a / 1000)) for i in range(4):
aa[i] += 5
aa[i] %= 10
for i in range(2):
aa[i], aa[3 - i] = aa[3 - i], aa[i]
for i in range(3, -1, -1):
stdout.write(str(aa[i]))

90、列表使用实例。

#!/usr/bin/python
#coding=utf-8 testList = [10086, '中国移动', [1, 2, 4, 5]]
#列表长度
print(len(testList))
#到列表结尾
print(testList[1:])
#向列表添加元素
testList.append('I\'m new here!')
#弹出列表最后一个元素
print(testList.pop(1)) matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
col2 = [row[1] for row in matrix]
print(col2)
col2even = [row[1] for row in matrix if row[1] % 2 == 0]
print(col2even)

参考资料:

Python 100例

Python练手例子(15)的更多相关文章

  1. Python练手例子(4)

    16.一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数. 程序分析:请参照程序Python 100例中的第14个例子 #py ...

  2. Python练手例子(3)

    13.打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...

  3. Python练手例子(16)

    91.时间函数举例1. #!/usr/bin/python #coding=utf-8 import time if __name__ == '__main__': #time.time()返回当前的 ...

  4. Python练手例子(11)

    61.打印出杨辉三角形. #python3.7 from sys import stdout if __name__ == '__main__': a = [] for i in range(10): ...

  5. Python练手例子(10)

    55.学习使用按位取反~. 程序分析:~0=1; ~1=0; (1)先使a右移4位. (2)设置一个低4位全为1,其余全为0的数.可用~(~0<<4) (3)将上面二者进行&运算. ...

  6. Python练手例子(2)

    7.将一个列表的数据复制到另一个列表中. 程序分析:使用列表[:]. #python3.7 #适用于简单列表(即列表中都是基本的元素) a1 = [1,2] b1 = a1[:] print(b1) ...

  7. Python练手例子(14)

    79.字符串排序. #python3.7 if __name__ == '__main__': str1 = input('Input string:\n') str2 = input('Input ...

  8. Python练手例子(13)

    73.反向输出一个链表. #python3.7 if __name__ == '__main__': ptr = [] for i in range(5): num = int(input('Plea ...

  9. Python练手例子(12)

    67.输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组. #python3.7 def inp(numbers): for i in range(6): numbers.appen ...

随机推荐

  1. 【转】ContextLoaderListener和DispatcherServlet加载内容的区别

    一.ContextLoaderListener加载内容 二.DispatcherServlet加载内容 ContextLoaderListener和DispatcherServlet都会在Web容器启 ...

  2. Gitlab_ansible_jenkins三剑客⑤jenkins Pipeline-job的使用

    Pipeline-job的使用 创建Pipeline任务 找到root用户的id 编写pipeline脚本 #!groovy pipeline{ agent {node {label 'master' ...

  3. [JavaScript]ECMA-6 箭头函数

    概述 箭头函数的作用是为Js提供一种函数的简写方法,箭头函数作用域内不包含this, arguments, super, or new.target,并且不能用于对象的构造函数: 基本语法 [(][p ...

  4. C# 最全的文件工具类FileHelper

    using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...

  5. ASP Action函数 如何接收client传递的数据(编辑中。。。)

    参看链接:https://www.cnblogs.com/umlzhang/p/3654486.html 我这里总结一下,Action的参数的来源比较多 1.url 2.路由设定 3.post中的内容 ...

  6. VMware对虚拟机快照进行克隆

    1.在关机状态下做一个快照 2.把快照管理器打开 3.右键快照,选择“克隆此快照” 4.选择要克隆的快照 5.选择克隆的方式 6.设置名称及保存的位置 注:虚拟机的快照是开机状态,不能对快照进行克隆

  7. TLS1.3&TLS1.2形式化分析

    本博客是对下面博客连接上的原文进行梳理+自己在其他方面资料做个整理 https://blog.csdn.net/andylau00j/article/details/79269499 https:// ...

  8. lombok @Accessors用法

    @Accessors 翻译是存取器.通过该注解可以控制getter和setter方法的形式. fluent 若为true,则getter和setter方法的方法名都是属性名,且setter方法返回当前 ...

  9. Eureka restTemplate访问超时

    错误代码 I/O error on GET request for "http://sushibase/v1/Publich/authorize": Connection time ...

  10. Spring 开发常见问题

    linux 下http 接收中文参数乱码 解决: 在application.yml配置文件中添加 spring: http: encoding: charset: GB2312