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