共 9 篇文章
显示摘要每页显示  条
通过Python为指字文件添加内容#! /usr/bin/python3# _*_ coding:UTF-8 _*_#同一目录下保存文件,open是打开这个指定文件传递给fofo= open("foo.txt","w")#输出foo的文件名字,fo.name是open后面的文件名。#内容赋值给str1str1 ="菜鸟教程,努力学就能学得会哦!"#fo.write(字符变量)输出write后面内容fo.write(s...
计算五年复利率的实例#本金是30000principal=30000#十个月年利率是0.10元rate=0.10#五年的复利numyears=5#一年时间year=1#循环计算的复利率while year<=numyears: #本金乘以1+利率 principal=principal*(1+rate) #输出利率结果 print("%5d %0.2f" % (year,principal)) #时间累加1 year +=1解析:%5d:将一个整数格式化...
连加法编程def getsum(*a) : s=0 for item in a : s+=item return s;print(getsum(1,2))print(getsum(1,2,3))print(getsum(1,2,3,4))
利用定义的函数编多个参数相加的程序#定义多参数相加:*args#定义函数名:calc_sum#ax = 0,相加结果的存入局部变量#for n in args: 从多个参数中提取元素值依次与ax累加#return ax,最终结果导出#调用函数,让1,5,8,相加。
写一个小的判断酒驾程序proof = int(input("输入驾驶员每 100ml 血液酒精的含量:"))if proof <20: print("驾驶员不构成酒驾")else: if proof <80: print("驾驶员已构成酒驾") else: print("驾驶员已构成醉驾")
密码判断执行代码通过本小节学习,可以学到如果我们的。
表格代码name=input("请输入姓名:")che_grade=input("请输入语文成绩:")math_grade=input("请输入数学成绩:")print("{0:10}{1:>6}{2:>5}".format("姓名","语文","数学"))print("{0:10}{1:>6}{2:>5}".format(name,che_grade,math_grade))花括...
正确的格式:name=input()if name == "Alice": print("Hello,Alice")elif age <12: print("You are not Alice")elif age >2000: print("You are not alse Alice")elif age >1000: print("Don''''''''t pretend to be Alice")
帮助 | 留言交流 | 联系我们 | 服务条款 | 下载网文摘手 | 下载手机客户端
北京六智信息技术股份有限公司 Copyright© 2005-2024 360doc.com , All Rights Reserved
京ICP证090625号 京ICP备05038915号 京网文[2016]6433-853号 京公网安备11010502030377号
返回
顶部