码迷,mamicode.com
首页 > 编程语言 > 详细

编写第一个python程序(Your Firsr Program)

时间:2019-12-18 14:33:25      阅读:59      评论:0      收藏:0      [点我收藏+]

标签: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.)
View Code

  输出结果:

技术图片
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.
View Code

2)解析程序(Dissecting Your Program)

  • COMMENTS:使用#代表注释,帮助自己知道代码是将要做什么;
  • THE PRINT() FUNCTIONS:打印出括号里面的内容;
  • THE INPUT() FUNCTIONS:等待用户输入,并且按ENTER键;
  • THE LEN() FUNCTION:输出字符串的长度

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!