jling 2019-12-18
1)代码如下:
# This program says hello and asks for my name. myName = input("What is your name?") print(‘it is good to meet you,‘+myName) #ask for your name print(‘it is good to meet you [%s]‘%myName) print(‘the length of your name is %s:‘%(len(myName))) myAge = input("What is your age?") #ask for your age 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