python编写程序、输入本金、年利率和年份、计算复利 您所在的位置:网站首页 python编写窗口程序年份 python编写程序、输入本金、年利率和年份、计算复利

python编写程序、输入本金、年利率和年份、计算复利

2023-07-28 12:54| 来源: 网络整理| 查看: 265

1.Python中使程序与用户进行交互的函数是input和print。如:

import datetime

myName=input("please input your name:")

birthyear=int("please input your birthyear:")#在Python里是用#做注释的,而不像是C或者Java等用/*------*/或//

age=datetime.date.today().year-birthyear

print("hi,{0},your age is{1}.".format(myName,age))#说来也蛮有创意,Python里会考虑到用{0}{1}这样的格式来与后面的内容匹配,真是比C,java这类语言具有更大的灵活性和自由性。

2.在Python中需要提示用户名和密码等,可以使用getpass模块。

import getpass

def checkuser(user,passwd):

if user=='xiaoxu'and passwd=='passwd':

return  true

else:

return false

if _name_=='_main_':#这一行不同版本中可能会报不同错误,虽均是基于3.x的,但不同版本还是有不同变化。

user=input('用户名')

passwd=getpass.getpass('密码')

if checkuser(user,passwd):

print('登陆成功



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有