python中int input_两分钟了解python中的input函数

5ef82026a9aed966.jpg

两分钟了解python中的input函数

input函数在python中是一个内建函数,其从标准输入中读入一个字符串,并自动忽略换行符。下面我们就来看看input函数的具体用法吧。

#函数inputmessage = input("Tell me something, and I will repeat it back to you: ")

print(message)

message1 = input()

print(message1)

1593316784659312.png

#创建多行字符串的方式prompt1="type someting"

prompt2=prompt1+": "+input()

print(prompt2)

43a2920e6325cd6a0bbbb70393f72642-1.pngprompt = "If you tell us who you are, we can personalize the messages you see."

prompt += "\nWhat is your first name? "

name = input(prompt)

print("\nHello, " + name + "!")

1593316808628663.png

#input默认输入是字符,所以需要字符比较时应当进行类型转换age=input("How old are you?")

age=int(age)

if(age>=18):

print("You have the right to vote!")

else:

print("Sorry,you have no right to vote!")

223a9214c6e5c2431db3043b78688dd4-3.png

#求模运算符c1=input("Please input a number,and i will do modulo operation for it.")

c1=int(c1)

c2=input("Please input another number,and i will do modulo operation for it.")

c2=int(c2)

c3=c1%c2

print(c3)

1593316825851652.png

#汽车租赁 :编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“Let me see if I can find you a Subaru”。input("What kind of car would you like to hire?")

print("Let me see if I can find you a Subaru")

1593316847577350.png

#餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。p1=input("How many people in the dinner?")

p1=int(p1)

if(p1>8):

print("Sorry,There is no empty table.")

else:

print("ok,There is an empty table")

941060a01c0103fa1d10bed87857ace1-6.png

#10的整数倍 :让用户输入一个数字,并指出这个数字是否是10的整数倍。n1=input("Please input a number")n1=int(n1)if(n1%10==0):print(n1+" is an integer multiple of 10.")else:

print(n1+" is not an integer multiple of 10.")

e58d65522d930e93a6f292dbe080d493-7.png

input函数在python中是一个内建函数,其从标准输入中读入一个字符串,并自动忽略换行符。

也就是说所有形式的输入按字符串处理,如果想要得到其他类型的数据进行强制类型转化。默认情况下没有

提示字符串(prompt string),在给定提示字符串下,会在读入标准输入前标准输出提示字符串。如果遇

文件结束符(end of file)会触发一个EOFError。

感谢大家的阅读,希望大家收益多多。

本文转自:https://blog.csdn.net/qq_24135817/article/details/79818479

推荐教程:《python教程》

以上就是两分钟了解python中的input函数的详细内容,更多请关注gxlcms其它相关文章!

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值