码迷,mamicode.com
首页 > 编程语言 > 详细

python入门-用户输入

时间:2018-07-07 20:22:36      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:运算   col   运算符   使用   str   pre   message   back   enter   

1 input()函数来实现用户输入,程序在等待输入的时候会终止,获取用户的输入后继续

message = input("tell me something,and I will repreat it back to you:")
print(message)

 

2 使用int来获取数值输入

age = input("How old are you?")

age = int(age)

print(age)

 

3 求模运算符

number = input("Enter a number,and i‘ll tell you if it‘s even or odd:")
number = int(number)

if number % 2 == 0:
    print("\n the number" + str(number) + "is even.")
else:
    print("\n the number" + str(number) + "is odd.")

 

python入门-用户输入

标签:运算   col   运算符   使用   str   pre   message   back   enter   

原文地址:https://www.cnblogs.com/baker95935/p/9277538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!