Python基础——input交互功能

1.input基本概念

variable=input() 表示运行后,可以在屏幕中输入一个数字,该数字会赋值给自变量。看代码:

get_input = input('please input a number:',)
print('this is a:',get_input)

#输出
please input a number:100
this is a: 100

input()应用在if语句中.

在下面代码中,需要将input() 定义成整型,因为在if语句中自变量 get_input 对应的是1 and 2 整数型。输入的内容和判断句中对应的内容格式应该一致。

也可以将if语句中的1and2 定义成字符串,其中区别请读者自定写入代码查看。

get_input = int(input('please input a number:'))  #input返回的是字符串形式,要把它转化为整数形式
if get_input == 1:
    print('This is one')
elif get_input == 2:
    print('This is two')
else:
    print('not one or two')

#输出
please input a number:3		#输入3
not one or two

2.input拓展

用input()来判断成绩

score = int(input('please input your score:'))
if score >= 90:
    print('you got A')
elif score >= 80:
    print('you got B')
elif score >= 70:
    print('you got C')
elif score >= 60:
    print('you got D')
else:
    print('not pass exam')

#输出
please input your score:59		#输入59
not pass exam
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值