if True:
print('ahah, u r right!')
else:
print('what r u fucking doing?')
#一个去年数据统计中我用来判断成绩等第的例子:
import pandas as pd
def get_letter_grade(score):
if score>=90:
return "A"
elif score>=80:
return "B"
elif score>=70:
return "C"
elif score>=60:
return "D"
else:
return "F"
df=pd.read_csv('big file.csv')
df['letter grade']=df['final grade'].apply(lambda x: get_letter_grade(x))
df.to_csv('big file.csv',index=False)
df.head(10)
# 关于缩进语句的嵌套(python和java不同没有{}的嵌套限制,所有有严格的缩进要求)
gender = 1#1为男生,0为女生
issingle = 1#是单身,0不是单身
if gender == 1:
print('这是个男孩子')
#在该条件下if
if(issingle == 1):
print('为你感到惋惜')
else:
print('滚')
else:
print('这是个女孩子')
if(issingle == 1):
print('为你感到惋惜')
else:
print('祝你幸福')
# 引入包进行random运算,randint函数取得是范围内的整数()包括边界
import random
#或者写from...import。from random import randint
x = random.randint(0,2)
print(x)
# 随堂作业:剪刀石头布程序import random
user = 0
pc = 0
x = int(input("请输入:剪刀(0)、石头(1)、布(2):"))
if x == 0:
user = "剪刀"
elif x == 1:
user = "石头"
elif x == 2:
user = "布"
t = random.randint(0, 2)
if t == 0:
pc = "剪刀"
elif t == 1:
pc = "石头"
elif t == 2:
pc = "布"
if x in (0, 1, 2):
if (x - t) in (1, -2):
print("您出的是:", user, ",电脑出的是:", pc, ",因此您赢了!", sep="")
elif x == t:
print("您出的是:", user, ",电脑出的是:", pc, ",因此平局!", sep="")
else:
print("您出的是%s,电脑出的是%s,因此您输了!" % (user, pc))
else:
print('输入无效,请检查')