标签:name print ide 内容 input span comment tin oat
1)代码如下:
1 1 # This program says hello and asks for my name. 2 2 myName = input("What is your name?") 3 3 print(‘it is good to meet you,‘+myName) #ask for your name 4 4 print(‘it is good to meet you [%s]‘%myName) 5 5 6 6 print(‘the length of your name is %s:‘%(len(myName))) 7 7 myAge = input("What is your age?") #ask for your age 8 8 9 9 print(‘You will be ‘ + str(int(myAge)+1) + ‘ in a year.‘)
输出结果:
1 What is your name?Sara 2 it is good to meet you,Sara 3 it is good to meet you [Sara] 4 the length of your name is 4: 5 What is your age?30 6 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
编写第一个python程序(Your Firsr Program)
标签:name print ide 内容 input span comment tin oat
原文地址:https://www.cnblogs.com/qiupiao/p/12059389.html