昨天,老师留的作业,做出10086的客服电话大的程序。班级的同学们在晚上都拿着手机一遍遍的打。但我当时发现一个问题,按*号键返回上一级菜单怎么打,(⊙﹏⊙)但最后也是简化了一下就用if elif语句吧。
请写出拨打10086的客服电话的功能的程序?
lang = int(input('欢迎指导10086,普通话请按1,English is 2'))
if lang == 1:
value = int(input('人工服务请按0,流量话费业务请按1,宽带业务请按2,停候机业务请按3,))
if value == 0:
print('正在为你转接,请稍后。响音乐')
if value = 1:
print('您当月话费余额为。。。。')
if value = 2:
print('您所在地区尚未开通此业务。')
else 业务逻辑同上,只要分支逻辑不错就可以
循环顺序 当某些运算和运行需要重复去做的时候就需要使用循环。
eg: 由1输入100,输出1~10等等。
循环语句,while 条件
语句体
eg:语句体1
语句体2
while 条件为真时,成立
print('输出条件') 并一直进行下去直到条件不成立
如,请输出10到1的数。 请输出1到10的数。请输出1~100的偶数
输出:10 9 8.....1
c = 10
while c>=1:
print(c)
c = c - 1
输出:1 2 3....10
count = 1
while count<=10:
print(count)
count = count+1
输出:100以内所有偶数
方法一:
count = 2
while count<=100:
print(count,end=' ')
count = count+2
方法二:
count = 1
while count<=100:
if count%2 == 0:
print(count,end=' ')
count = count+1
断点调试; 在行号位置单击,添加断点可以在dubug模式下可以单步查询运行状态。
累加求和,
本质就是循环,假设循环N次而结果为s。所以思路是n = int(input('请输入一个数:'))
计算1~n累加和
print('累加和:',s)
练习;我求1~10的累加和 1+2+3+4+5+6+7+8+9+10
思路;(1)先有这10个数
(2)累加和
1~10的累加和 s10 =1 2+3+4+5+6+7+8+9+10
1~9的累加和 s9 = 1+2+3+4+5+6+7+8+9
。
直到s1 = s0+1
s = 0
n = 1
while n <=10
s = s+n
n = n+1
print(t)
函数;一个功能模块,就好比一个工具,在生产了这个工具后,以后什么时候用都可以。
格式: dcf 函数名():
语句体
调用函数,避免程序被浪费,而直接拿来使用
def intro():
print('我叫G了呢,请多指教!')
#调用
n = 1
while n<=10:
intro()
n = n+1
使用函数求1~n的累积和
def qiuhe(n):
s = 0
n = 1
while n <=m:
s = s + n
n = n + 1
print('1~%d的累积和:'%d%(m,s))
qiuhe(3)
qiuhe(10)
qiuhe(100)
作业;个税的算法的