python例题(04)

1.编写程序

s = float(input('Enter the exchange rate from dollars to RMB:'))
a = int(input('Enter 0 to convert dollars to RMB and 1 vice versa:'))
t = 0
if a==0:
    d = float(input('Enter the dollar amount:'))
    t = d*s
    print('$',d,'is',t,'yuan')
elif a==1:
    c = float(input('Enter the RMB amount:'))
    t = c/s
    print(c,'yuan is $','%.2f'%t)
else:
    print('Incorrect input')
# Enter the exchange rate from dollars to RMB:7.2
# Enter 0 to convert dollars to RMB and 1 vice versa:1
# Enter the RMB amount:10000
# 10000.0 yuan is $ 1388.89

# Enter the exchange rate from dollars to RMB:7.2
# Enter 0 to convert dollars to RMB and 1 vice versa:0
# Enter the dollar amount:100
# $ 100.0 is 720.0 yuan

# Enter the exchange rate from dollars to RMB:7.2
# Enter 0 to convert dollars to RMB and 1 vice versa:2
# Incorrect input

2.编写程序

(x,y) = eval(input('Enter a point with two coordinates:'))
if x>=0 and y>=0 and 2*y+x<=200:
    print('The point is in the triangle')
else:
    print('The point is not in the triangle')
# Enter a point with two coordinates:100.5,25.5
# The point is in the triangle
# Enter a point with two coordinates:100.5,50.5
# The point is not in the triangle

3.编写程序

t = 0
for i in range(100,201):
    if i%30!=0 and (i%5==0 or i%6==0) :
        print(i,end=' ')
        t+=1
        if t%10==0:
            print()
# 100 102 105 108 110 114 115 125 126 130 
# 132 135 138 140 144 145 155 156 160 162 
# 165 168 170 174 175 185 186 190 192 195 
# 198 200 

4.编写程序

import math as m
for i in range(1,9):
    for k in range(1,9-i):
        print('\t',end='')
    for j in range(-(i-1),i):
        print('%4.0f'%2**(m.fabs(m.fabs(j)-i+1)),end='')
    print()
	# 						   1
	# 					   1   2   1
	# 				   1   2   4   2   1
	# 			   1   2   4   8   4   2   1
	# 		   1   2   4   8  16   8   4   2   1
	# 	   1   2   4   8  16  32  16   8   4   2   1
	#    1   2   4   8  16  32  64  32  16   8   4   2   1
   # 1   2   4   8  16  32  64 128  64  32  16   8   4   2   1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雨天_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值