Python程序设计基础 Chapter02

Python程序设计基础 Chapter02,第1张

Python程序设计基础 Chapter02
2-1
num = int(input('plz input an num:'))
a = int(num / 100)
b = int(num / 10) - a * 10
c = num % 10
print('ones, tens, hundreds')
print(a, b, c)
-----------------------------------------------------------------------------------------------------------------------
RIVISED1
x = input('plz input an num:')
a, b, c = map(int, x)
print('ones, tens, hundreds')
print(a, b, c)

RIVISED2:
x = int(input('plz input an num:'))
a, b = divmod(x, 100)
b, c = divmod(b, 10)
print('ones, tens, hundreds')
print(a, b, c)
-----------------------------------------------------------------------------------------------------------------------

2-2
import math
x = float(input('plz input 1st side:'))
y = float(input('plz input 2nd side:'))
a = float(input('plz input angle(°):'))
z = math.sqrt(x**2 + y**2 - 2*x*y*math.cos(a*math.pi/180))
print(z)
-----------------------------------------------------------------------------------------------------------------------
RIVISED:
import math
num = input('plz input side1, side2, angle(°):n(split by key space)')
x, y, a = map(float, num.split())
z = math.sqrt(x**2 + y**2 - 2*x*y*math.cos(a*math.pi/180))
print(z)
-----------------------------------------------------------------------------------------------------------------------

2-3
a = []
for i in range(3):
    letter = input('plz input 1 of 3 letters:')
    a.append(letter)
a.sort()
for i in a:
    print(i)
-----------------------------------------------------------------------------------------------------------------------
RIVISED:
letters = input('x, y, z = ')
x, y, z = sorted(letters.split(','))
print(x, y, z)
-----------------------------------------------------------------------------------------------------------------------

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/5443085.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存