# 第九次,一 定义g到kg的转换函数,效果如图:1234g = 1.234kg
def g2kg(gWeight):
kgWeight=gWeight/1000
print(kgWeight,'kg')
number=input("Please enter a number:")
g2kg(int(number))
# 运行结果
# Please enter a number:56
# 0.056 kg
#--------------------------------------------------------------------------------------------------------
#二 输入姓名,隐藏名字,效果如图:
# 提示:字符串的索引切片、字符串的replace方法
def hideName(name):
for i in range(len(name)):
if(i>0):
name=name.replace(name[i],'*')
print(name)
input_name=input("Please enter your name:")
hideName(input_name)
# 运行结果
# Please enter your name:罗盼盼
# 罗**
#--------------------------------------------------------------------------------------------------------
# 第九次 被2或者被3整除的正整数依次是:2,3,4,6,8,9,10,12,14,15,16,18...
# 定义一个函数,求第n个被2或者被3整除的正整数是多少?
def calc(n):
j=0
for i in range(1,1000):
if(i%2==0) or (i%3==0):
j=j+1
if(j==n):
print('第',n,'个被2或者被3整除的正整数是:',i)
break
input=input("Please enter a number:")
calc(int(input))
# 运行结果
# Please enter a number:500
# 第 500 个被2或者被3整除的正整数是: 750