python学习20200506 注释与交互程序输入输出if语句,缩进介绍
注释:
#在python里是注释,在开头为单行注释,末尾为为这行代码注释
开头''' 结尾''' 为多行注释 单引号可以变为"但要前后一致
#在python里是注释,在开头为单行注释,末尾为为这行代码注释
开头''' 结尾''' 为多行注释 单引号可以变为"但要前后一致
交互式程序
input(”you name“)
print
print(input(”you age“))
name=input(”you name“)
input(”you age“)
print("name,age")
input(”you name“)
print(input(”you age“))
name=input(”you name“)
input(”you age“)
print("name,age")
print("Hello, world!")
name = input("What is your name? ")
print("Hello, " + name + "!")
input("Press <enter>")
name = input("What is your name? ")
print("Hello, " + name + "!")
input("Press <enter>")
数据类型转换
death_age=80
name = input("your name:")
age = input("your age:") #input 接受的所有数据都是字符串,即使输入数字也被当成字符串
name = input("your name:")
age = input("your age:") #input 接受的所有数据都是字符串,即使输入数字也被当成字符串
# int integer=整数 把整数变为字符串用str,用str(被转的数据) 类型的强制转换
# str string=字符串 把字符串变为整数用str,用int(被转的数据)
# str string=字符串 把字符串变为整数用str,用int(被转的数据)
print("your name:",name)
print("you can still live for ",death_age - int(age) ,"years......")
print("you can still live for "+ str(death_age - int(age)) + " years......")
print("you can still live for ",death_age - int(age) ,"years......")
print("you can still live for "+ str(death_age - int(age)) + " years......")
判断猜年龄
age_of_princal = 56
guess_age = int(input(">>>:please guess the age of princal "))
if guess_age == age_of_princal : # python 里面==是判断相等,=是赋值,!=是判断不等于
# 必须缩进,而且级别必须保持一致,必须是四个空格或Tab键,python里面Tab就是四个空格
guess_age = int(input(">>>:please guess the age of princal "))
if guess_age == age_of_princal : # python 里面==是判断相等,=是赋值,!=是判断不等于
# 必须缩进,而且级别必须保持一致,必须是四个空格或Tab键,python里面Tab就是四个空格
print("yes,you got it")
elif guess_age > age_of_princal:
print("try samller...")
else:
print("no,it's wrong,try bigger... ")
elif guess_age > age_of_princal:
print("try samller...")
else:
print("no,it's wrong,try bigger... ")
多分支if语句
score = int(input("score:"))
if score > 90:
print("A")
elif score > 80:
print("B")
elif score >70:
print("C")
elif score >50:
print("D")
else:
print("滚")
if score > 90:
print("A")
elif score > 80:
print("B")
elif score >70:
print("C")
elif score >50:
print("D")
else:
print("滚")
各种关系表示
a = 3
>>> b = 4
>>> a>b
False
>>> a<b
True
>>> a==b
False
>>> a!=b
True
>>> a>=b
False
>>> a<=b
True
>>> b = 4
>>> a>b
False
>>> a<b
True
>>> a==b
False
>>> a!=b
True
>>> a>=b
False
>>> a<=b
True
a<b<c

浙公网安备 33010602011771号