1)代码如下:
1 # This program says hello and asks for my name.
2 myName = input("What is your name?")
3 print('it is good to meet you,'+myName) #ask for your name
4 print('it is good to meet you [%s]'%myName)
5
6 print('the length of your name is %s:'%(len(myName)))
7 myAge = input("What is your age?") #ask for your age
8
9 print('You will be ' + str(int(myAge)+1) + ' in a year.')
输出结果:
What is your name?Sara
it is good to meet you,Sara
it is good to meet you [Sara]
the length of your name is 4:
What is your age?30
You will be 31 in a year.
2)解析程序(Dissecting Your Program)
3)The str(),int()和float()函数
>>>str(0)
'0'
>>>str(-3.14)
'-3.14'
>>>int('42')
42
>>>int('-99')
-99
>>>int(1.99)
1
>>>float('3.14')
3.14
>>>float(10)
10.0
>>>42 == 42.0
True
>>>42.0 == 0042.00
True
手机扫一扫
移动阅读更方便
你可能感兴趣的文章