python编写程序、输入本金、年利率和年份、计算复利_basic knowledge of python--section one...

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('登陆成功

你可能感兴趣的:(python编写程序,输入本金,年利率和年份,计算复利)