Python基础练习 9.8

1.简单输入输出交互
>>> print('hello world')
hello world
>>> name=input(':')
:xiao
>>> print(name)
xiao

>>> name=input('what is your name?\n')
what is your name?
xiaoyan
>>> print('hi,%s'%name)
hi,xy

2.用户输入两个数字,计算并输出两个数字之和:(尝试只用一行代码实现这个功能)

>>> print('两个数字的和为:%s'%(int(input('num1为:'))+int(input('num2为:'))))
num1为:12
num2为:24
两个数字的和为:36

3.输入半径,计算圆的面积。

>>> r=input('请输入圆的半径:')
请输入圆的半径:2
>>> area=float(r)**2*3.14
>>> print('圆的面积为'+str(area))
圆的面积为12.56

 

posted on 2017-09-08 17:56  081肖妍  阅读(113)  评论(0)    收藏  举报

导航