文章目录
字符转换/输入/计算
1. 从控制台输入圆的半径,计算周长和面积
circleR = input('圆的半径是:')
perimeter = 3.14*int(circleR)*2
area = 3.14*(int(circleR) ^ 2)
print('圆的周长是{},圆的面积是{}'.format(perimeter, area))
2. 一辆汽车以40km/h的速度行驶,行驶了45678.9km,求所用的时间
velocity = 40
distance = 45678.9
time = distance/velocity
print('时间是', time)
3. 华氏温度转摄氏温度【提示:将华氏温度转换为摄氏温度 F = 1.8C + 32】
F_Temp = input('华氏温度是:')
C_Temp = (int(F_Temp)-32)/1.8
print('摄氏温度是:', C_Temp)
**4. 从控制台输入两个数,输出两个数相加,减法,求余数的结果**
number_1 = input('请输入数字1:')
number_2 = input('请输入数字2:')
add = float(number_1)+float(number_2)
subtract = float(number_1) - float(number_2)
print('相加等于{},相减等于{}'.format(add, subtract))
remainder = float(number_1) % float(number_2)
print('余数是', remainder)
5.
**游戏输出:
'''
英雄联盟
键盘输入:
人物角色
初始装备
再购买3件装备(提示:要求键盘输入三次装备名称和价格)
最后计算买装备的总金额
最后输出:
xxx所购买的装备有哪些,共花费xxx钱**
'''
print('英雄联盟')
role = input('人物角色:')
equip = input('初始装备:')
newEquip1 = input('购买装备1:')
price1 = input('装备1金额:')
newEquip2 = input('购买装备2:')
price2 = input('装备2金额:')
newEquip3 = input('购买装备3:')
price3 = input('装备3金额:')
total = float(price1)+float(price2)+float(price3)
print('{}所购买的装备是{},{}和{}, 共花{}元'.format(role, newEquip1, newEquip2, newEquip3, total))
6. 计算如下值:
# a=10
# b=8
# 计算 a+=b ,a-=b a*=b a/=b 的值
a//b 和 a**b 的值**
a = 10
b = 8
a += b
print(a)
a -= b
print(a)
a *= b
print(a)
a /= b
print(a)
print(a//b)
print(a**b)
7. 尝试如下动作:
Print(‘*’ * 100) 的结果是什么
Print(‘hello’ * 5) 的结果是什么
hellohellohellohellohello