英寸和厘米的交互python_Python新手尝试编写厘米到英寸的代码,反之亦然

我是python的新手,我被赋予了一个从厘米到英寸的代码,反之亦然。其原理是用户输入一个数字,程序询问他们是否要将其从英寸转换为厘米或厘米到英寸,然后显示结果。在

我在mac上使用Python3.3.5是有帮助的。在

这是我的代码:(注释掉的部分显示了任务和我的第一次尝试)##

##Write a program that converts between centimetres, and inches and vice versa, by:

##asking the user to input a number

##asking the user to choose between converting from centimetres to inches or from inches to centimetres

##calculating and outputting the result using functions

##### Old attempt

##print(" Program to convert beteween centimetres and inches " )

##

##centimetre = 1

##inch = centimetre * 2.45

##

##number = input (" Please enter a number: ")

##choice = input (" Do you want to convert into centimetres or inches: ")

##if choice == "centimetres" or "Centimetres":

## print("Your number is", centimetre*number, "cm")

##else:

## print("Your number is",number*inch, "inches")

number = int(input(" Please enter a number: "))

choice = input(str(" If you want to convert from centimetres to inches type 'A' \n If you want to convert from inches to centimetres type 'B': "))

if choice in "A" or "a":

print(" Your number is" , number*2.54,"inches")

else:

print(" Your number is", number/2.54, "centimetres")

答案已经找到,谢谢你的快速回复!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值