1.C++笔记
int main(){
int year;
printf("请输入一个年份:");
scanf("%d, &year");
// 判断闰年的条件
// 条件1 : 能被4整除且不能被100整除
// 条件2 :能被 400 整除
// 两个条件满足其一就是闰年
(year % 4 == 0 && year % 100 != 0) || (year % 400 ==0)?
printf("%d 年是闰年 \n",year) : printf("%d 年不是闰年 \n", year);
return 0;
}
2.Python笔记
# while 循环基础
count = 1 # 初始值
while count <= 5:
print("我在学习while循环")
count += 1 # count = count + 1
# 累加计算
count = 1 # 初始值
total = 0 # 总和的初始值
while count <= 5:
print(count)
total += count # total = total +
count += 1 # count = count + 1
print("总和为:",total)
#喝水
cup = 1 #初始值
target = 8
while cup < target:
a = input()
print(f"喝了第{cup}杯水")
cup += 1
printf("喝水任务完成")
#计算1-100的偶数
count = 2 #初始值
total = 0 #总和的初始值
while count <= 100:
total += count #total = total + count
print(count)
count += 2 #count = count + 2
print("总和为:" , total)
# 计算50以内所有能被7整除的数的和
count = 7 # 初始值
total = 0 # 总和的初始值
while count <= 50:
total += count # total = total + count
print(count)
count += 7 # count = count + 2
print("总和为:", total)
# 计算100以内所有能被3和5整除的数的和
count = 7 # 初始值
total = 0 # 总和的初始值
while count <= 50:
total += count # total = total + count
print(count)
count += 7 # count = count + 2
print("总和为:", total)
逻辑运算符
x = 0 y = 1 a = 0 b = 2
and
c =x and y c =y and x c =x and a c =y and b print(c) #or c = x or y c = y or x c = x or a c = y or b print(c) #not c = not a c = not b print(c)