-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
环境基于 py3.6
print("******************************-1-*************************************")
# todo 1.#输入a,b,c,d4个整数,计算a+b-c*d的结果
print('Please input four number , and use "enter" key to finish every number ! ')
a = eval(input('a = '))
b = eval(input('b = '))
c = eval(input('c = '))
d = eval(input('d = '))
print("a + b - c * d = %d"%(a + b - c * d))
# 输出结果:
# Please input four number , and use "enter" key to finish every number !
# a = 5
# b = 6
# c = 5
# d = 2
# a + b - c * d = 1
print("******************************-2-*************************************")
# todo 2.计算一个12.5m16.7m的矩形房间的面积和周长
length = eval(input("Please input length of the room:"))
width = eval(input("Please input width of the room:"))
area = length * width
perimeter = 2 * (length + width)
print("The room's area is %.2f and perimeter is %.2f"%(area,perimeter))
# 输出结果:
# Please input length of the room:12.5
# Please input width of the room:16.7
# The room's area is 208.75 and perimeter is 58.40
print("******************************-3-*************************************")
# todo 3.怎么得到9/2的小数结果
print(9/2)
# 输出结果:
# 4.5
print("******************************-4-*************************************")
# todo 4.python计算中7*7*7*7可以有多少种写法
# 第一种:
print(7*7*7*7)
# 第二种:
print(7**4)
# 第三种:
print(pow(7,4)) #pow() 方法返回 x^y(x的y次方) 的值
# 第四种:
print(eval("pow(7,4)")) #eval() 函数用来执行一个字符串表达式,并返回表达式的值。
# 第五种:
a = 1
for i in range(4): a = a *7
print(a)
# 第六种:
print(eval(("*7"*4)[1:])) # (*7*7*7*7)[1:] == (7*7*7*7)
# 第七种:
print(eval("*".join(['7']*4)))
# 输出结果:
# 2401
# 2401
# 2401
# 2401
# 2401
# 2401
# 2401
print("******************************-5-*************************************")
# todo 5.写程序将温度从华氏温度转换为摄氏温度。转换公式为C=5/9*(F-32)
F = eval(input("Please input Fahrenheit temperature:"))
C = 5/9*(F-32)
print("Corresponding centigrade temperature is %.2f"%C)
# 输出结果:
# Please input Fahrenheit temperature:33
# Corresponding centigrade temperature is 0.56
print("******************************-6-*************************************")
# todo 6.一家商场在降价促销。如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣,如果购买金额大于100元会给20%折扣。
# todo 编写一程序,询问购买价格,再显示出折扣(%10或20%)和最终价格
customer_price = eval(input("Please input the price:"))
if customer_price <= 50 and customer_price >= 0:
print("No discount,and your final price is $%.2f. "%(customer_price))
elif customer_price <= 100 and customer_price > 50:
print("Discount 10%% and your final price is $ %.2f. "%(customer_price*0.9))
elif customer_price > 100:
print("Discount 20%% and your final price is $ %.2f. "%(customer_price*0.8))
# 输出结果:
# Please input the price:56
# Discount 10% and your final price is $ 50.40.
print("******************************-7-*************************************")
# todo 7.判断一个数n能同时被3和5整除
n = eval(input('Please input a number:'))
if n % 3 == 0 and n % 5 ==0:
print('The number can be divided by 3 and 5!')
else:
print('The number cannot be divided by 3 and 5!')
# 输出结果:
# Please input a number:6
# The number cannot be divided by 3 and 5!
# Please input a number:15
# The number can be divided by 3 and 5!
Metadata
Metadata
Assignees
Labels
No labels